Value cannot be null. Parameter name: serviceKey

Topics: General
Mar 5, 2011 at 1:14 AM

Hello again. I'm getting the error listed in the title and I'm not sure why.

I've got two custom modules that I intend to use as "areas" in my site. One is an Account management area and the other is a Products Showcase.
I've followed the tutorials I can find on this site and elsewhere and have created these "from scratch" in Visual Studio

Some relevant information. The module projects are NOT stored in the Orchard/Modules directory. Instead, I do a post-build event that copies everything from my module project into the proper place in Orchard. I have verified that ALL files are getting copied over, including the bin folder of my module project.

The module is enabled in Orchard and Orchard detects things like when I fake the module needing to be upgraded.

The module contains a single controller with a single Action
publicActionResult Index()
    ViewBag.Message =
"Welcome to Account";
return View();

My view is as simple as possible, it simply contains "Account Module"
Default Global.asax code is commented out but -- it wasn't but doing so didn't fix the issue.
I have tried removing EVERYTHING from the default web.config.
I copied the Routes.cs from the Blogs module and changed the relevant information.

public IEnumerable<RouteDescriptor> GetRoutes() {
return new [] { 
new RouteDescriptor {
        Route =
new Route ( "Account" , new RouteValueDictionary {
"area", "MyCompany.Account" },
"controller", "Account" },
"action", "Index" } },
new RouteValueDictionary(),
new RouteValueDictionary {
"area", "MyCompany.Accout" } },
new mvcRouteHandler ()) }

My module references Orchard.Core, Orchard.Framework and Orchard.Web
I'm not sure what I am missing, something silly most likely.



Mar 5, 2011 at 3:11 AM

Also worth nothing that the project runs by itself if I set it as startup and press play in VS2010.
I've tried removing the Global.asax, web.config pieces that orchard doesn't need, Views\Shared folder and Views\_ViewStart.cshtml to see if it was the stuff that makes the site run as a normal MVC3 app was causing the issue. It wasn't...

Something else of note, me MainMenu.cs file works and I can get my module to show up in the menu (even conditionally if the user is authenticated so Orchard sees the module and is capable of injecting an IHttpContextAccessor into it.

The error seems to only be concerned with the navigating to or rendering of the view.



Mar 8, 2011 at 3:51 AM

I haven't tried this yet but this post from today is pointing at the same issue I am having:
Is this a common thing? If so, is the solution posted in that discussion acceptable? It seems the poster has blindly made the change without fully understanding the system. I don't want to do this and cause other issues without confirmation from someone more intimate with the core code.
Is this a confirmed issue or are we doing something wrong? I've had custom modules working before. It seems like whatever "tripped" in the system is now affecting all of my custom modules. However, since I am following the same guide for each, it could very easily be ME who is missing something in my setup and nothing wrong with Orchard.
Can someone on the Orchard team speak to this? It's had my Orchard development at a standstill since Friday. :(


Mar 8, 2011 at 4:30 AM

Just to see if it is something I am doing wrong I copied the blog module and deleted everything in it that is blog specific. I left only the BlogController and the Blog/Item view and in it only left "HI BLOG"
Changed every occurrance of "Blog" to "Store" to prevent and route issues and ran it. Get the same error. Whatever is going on I don't think it's in the way I am setting up my module projects...


Mar 9, 2011 at 9:21 PM
Edited Mar 9, 2011 at 9:22 PM

Has anyone been able to take a look at this or the other post? I haven't seen any replies since Friday and powers above me are beginning to rethink letting me experiment with Orchard.
Do I need to package and upload our test module for someone to look at or test to see if they get the "Value cannot be null. Parameter name: serviceKey" error?

Can we get an indication that someone is investigating the issue? This is one of two posts (that I am aware of) with seemingly the same problem and they have both been silent. :(


Mar 9, 2011 at 9:26 PM

I'm a little confused by all the weird stuff you're doing here (like not putting your module in modules) but if you want to package and send me your module (bleroy at microsoft), I'll take a look.

Mar 9, 2011 at 10:39 PM

The reason I'm not putting my module project directly into the modules directory is simply for source code structuring. We don't want our primary sourcecode to live inside of the Orchard/Modules folder. We want to keep them in our source code repository in it's own folder/namespace. Test projects are stored and namespaced similarly. I don't see why Orchard would care if the actual project is stored in the Modules folder versus my project simply copying itself there on Post-Build. Either way, Orchard will get the exact same files.

I have zipped and emailed my test module. It's a simple MVC3 project with a single controller, single action and single view. The project runs stand-alone so if you load it in VS and press play you should see your browser load a blue window with the word "Games" and nothing more. Could it be that being an actual MVC app is screwing with Orchard? The setup was done following this tutorial The only difference is mine is MVC3, not MVC2.

Also worth noting is the fact that I have also tried using these tutorials and have gotten the same effect:


Mar 10, 2011 at 12:24 AM

Mmmh, I was able to make your module work by just fixing the area to be "DD.Games" in the MainMenu.cs file.

Mar 10, 2011 at 3:47 AM
Edited Mar 10, 2011 at 4:02 AM

Hmmm. Ok so here is what I have discovered so far. Having the project stored outside of Orchard and copied post-build to modules folder causes no harm.

Now I'm really confused. I'm trying to figure out just what controls what between the menus, routes.cs and module.txt.
It seems like in my MainMenu.cs file if I specify the area to be anything other than the assembly name ("DD.Games") then I get the error about ClaySharp.Clay does not contain a definition for 'TrimEnd()'
You will note that this error is different from the serviceKey error I was getting before you pointed out to change my area to DD.Games in your last post.
Next, when I hover over my Games menu item(created by MainMenu.cs) I see the path is to From what I can tell, the "Games" part of the url comes from the Module.txt file -- the very first line seems to be what controls this part of the URL.
If I change the first line in Module.txt to be "Name: GameZZZ" and recompile then my main menu points to (which actually works by the way). At this point also works but navigates to a different place which I will describe below.

In my Routes.cs file I have a route with a url of SomeGame using my Home controller and Index action (as opposed to the Test action specified by the MainMenu.
Now, I can navigate to the url except that actually points to the Home controller Test action. <boggle>... I would expect this to navigate to the Home controller Index action as specified in Routes.cs...
If I try to replicate what the main menu does and go to I get a "resource not found error".

Now another test. MainMenu and Routes are configured just like before. Module.txt now has "SomeGameZ" on the first line. Recompile. MainMenu Games entry now points to the url. actually seems to be using the Routes.cs file because it correctly navigates to the www.SomeGameZ/Home/Index view as opposed to the www.SomeGameZ/Home/Test view. However, the "SomeGame" url I specified in the Routes.cs file still navigates to view instead of the Index view as I would expect.

So, here is the way it seems to me.
MainMenu navigates to where it is supposed to which seems to use the name of the Module as the "area name"?.
MainMenu seems to disregard Routes.cs file completely -- I think this makes sense.
Navigating to the url that corresponds directly to the module name (as specified on first line of Module.txt) seems to use the value set up in Routes.cs even though the URL doesn't match the URL I've specified in GetRoutes().
Navigating to the url actually configured in Routes.cs seems to get me to the view configured by the main menu -- totally wasn't expecting this.

Needless to say, I'm very confused at this point. :(

Is there a document somewhere that shows what each of these settings controls because changing some things seems to be having some quite unexpected results. If not, this would be a great document to have.
I think the problems I am having here are the same things affecting FIMi in his post here

I will reply to his to read here for a potential answer to his problem though I still think there are bugs in the way routes are handled.


EDIT * I just did a discussions search for Routes.cs and came across this post
Could this be what I am running into? I have periods in my area names because I've found that naming the area anything besides the assembly name is causing problems.
As a test I searched my project for EVERY occurrance of DD.Games and replaced it with "FOO". Now the site immediately errors with:
'ClaySharp.Clay' does not contain a definition for 'TrimEnd'

Line 7:      @DisplayChildren(Model)
Line 8:  } else {
Line 9:      if (Model.Href.TrimEnd('/').ToUpperInvariant() == Request.Path.TrimEnd('/').ToUpperInvariant()) {
Line 10:         Model.Classes.Add("current");
Line 11:     }

So, looks like areas absolutely MUST be named the same as the assembly.

Mar 10, 2011 at 4:38 AM

It would appear that if I take the . out of my Module name in Module.txt that things get a bit more predictable.
I also think some of the oddness I was seeing was IE cached files. I've been clearing temp files after every build for the past few minutes and now it seems like URLs from the menu and manually keyed are acting in a more predictable manner.
Area name still HAS to match the assembly name it would seem but I don't think this is a limiting factor -- though maybe still a bug?

I've successfully tested various scenarios of Menu pointing to various views and it even appears that the URL assigned to a menu will correspond to the shortest route found, which is nice.

Well, this was good progress for me tonight.
bertrandleroy, thanks a TON. Your one point about the area name is what finally gave me the ability to actually start creating some useful code instead of spinning my wheels with this issue.

I'd still like to hear your opinion about what I was experiencing in my previous post. Could have been my lack of understanding of what Orchard is trying to do but my results from previous tests still have me wondering if there is a bug under the hood with the way menus, routes.cs and module.txt all interract.

Thanks again,

Mar 10, 2011 at 4:40 AM

I'm pretty sure there is a bug there, but it's extremely hard to reproduce. So if you hit it again, please let me know.