Hi,
I'm just getting started with Glass Mapper so I created a simple project for a clean Sitecore 7 130918 installation. I'm using Sitecore MVC so I installed the Glass.Mapper.Sc.Razor and Glass.Mapper.Sc.Razor.CastleWindsor nuget packages. Straight out of the box I'm getting some errors in the App_Start\GlassMapperScRazor.cs file:

Some of the types can't be found so I went and had a look at the Glass.Mapper.Sc.Razor.CastleWindsor assembly in Reflector but it seems empty.

So I went and took the Glass.Mapper.Sc.CastleWindsor assembly and referenced it in my solution. Now the GlassMapperScRazor class has no errors. Using this assembly might be the reason why I'm running into my next error. Using TDS I pulled the Sample_Item out of Sitecore and generated the code for it. In my controller I'm now trying to do this to get my current context item:

It all compiles fine but when accessing the page in a browser I'm seeing an YSOD:
Server Error in '/' Application.
The given key was not present in the dictionary.
Description: An unhandled exception occurred.
Exception Details: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
Source Error:
Line 17: public ActionResult Index()
Line 18: {
Line 19: var contextItem = new SitecoreContext().GetCurrentItem<Sample_Item>();
Line 20: return View(contextItem);
Line 21: } |
Source File: c:\inetpub\wwwroot\USQ.Responsive\USQ.Responsive\USQ.Responsive.UI.Web\USQ\Websites\Responsive\Controllers\HomeController.cs Line: 19
Stack Trace:
[KeyNotFoundException: The given key was not present in the dictionary.]
System.Collections.Generic.Dictionary`2.get_Item(TKey key) +14178855
Glass.Mapper.AbstractService..ctor(String contextName) +97
Glass.Mapper.Sc.SitecoreService..ctor(Database database, String contextName) +55
Glass.Mapper.Sc.SitecoreContext..ctor() +80
USQ.Responsive.UI.Web.USQ.Websites.Responsive.Controllers.HomeController.Index() in c:\inetpub\wwwroot\USQ.Responsive\USQ.Responsive\USQ.Responsive.UI.Web\USQ\Websites\Responsive\Controllers\HomeController.cs:19
lambda_method(Closure , ControllerBase , Object[] ) +113
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +261
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +39
System.Web.Mvc.<>c__DisplayClass13.<InvokeActionMethodWithFilters>b__10() +124
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +854290
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +854290
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +309
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +345
|
I've checked the WebActivator assemblies are in the bin folder of my website and that the GlassMapperScRazor.cs file in App_Start is running fine.
Any ideas on what I'm doing wrong and how to fix this error?
Thanks
Ben