System.TypeLoadException: Could not load type 'System.Data.Entity.Infrastructure.Design.Executor+GetContextType' from assembly 'EntityFramework - entity-framework-6

I created a new Framework Winforms XAF 21.1.4 Winforms project using EF 6.2
When I tried to enable migrations via Package Manager Console I got
System.TypeLoadException: Could not load type 'System.Data.Entity.Infrastructure.Design.Executor+GetContextType' from assembly 'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
at System.Reflection.RuntimeAssembly.GetType(RuntimeAssembly assembly, String name, Boolean throwOnError, Boolean ignoreCase, ObjectHandleOnStack type)
at System.Reflection.RuntimeAssembly.GetType(String name, Boolean throwOnError, Boolean ignoreCase)
at System.Activator.CreateInstance(String assemblyString, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(String assemblyName, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.AppDomain.CreateInstance(String assemblyName, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.AppDomain.CreateInstance(String assemblyName, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Data.Entity.Tools.AppDomainExecutor.Execute(String operation, Object resultHandler, IDictionary args)
at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid4[T0,T1,T2,T3](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3)
at System.Data.Entity.Tools.ExecutorBase.InvokeImpl(String operation, IDictionary args)
at System.Data.Entity.Tools.ExecutorBase.GetContextType(String contextTypeName, String contextAssemblyName)
at System.Data.Entity.Tools.Commands.MigrationsEnableCommand.Execute()
at Microsoft.DotNet.Cli.CommandLine.CommandLineApplication.Execute(String[] args)
at System.Data.Entity.Tools.Program.Main(String[] args)
Could not load type 'System.Data.Entity.Infrastructure.Design.Executor+GetContextType' from assembly 'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

I upgraded to EF 6.4 via Nuget and was then able to enable-migrations

Related

AutoMapper - ProjectTo error when working with Odata in .net6

Referencing this answer
https://stackoverflow.com/a/28725063/19624357
After porting my project from NetFramework4.8 to .net6 with new Odata version 8.0.10, I have the following exception.
System.ArgumentException HResult=0x80070057 Message=Object of type
'System.Data.Entity.Infrastructure.DbQuery1[PersonSearchDto]' cannot be converted to type 'System.Linq.IQueryable1[PersonDto]'.
Source=System.Private.CoreLib StackTrace: at
System.RuntimeType.TryChangeType(Object value, Binder binder,
CultureInfo culture, Boolean needsSpecialCast) at
System.Reflection.MethodBase.CheckArguments(StackAllocedArguments&
stackArgs, ReadOnlySpan1 parameters, Binder binder, BindingFlags invokeAttr, CultureInfo culture, Signature sig) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) at Microsoft.AspNet.OData.ExpressionHelpers.Where(IQueryable query, Expression where, Type type) at Microsoft.AspNet.OData.Query.FilterQueryOption.ApplyTo(IQueryable query, ODataQuerySettings querySettings) at Microsoft.AspNet.OData.Query.ODataQueryOptions.ApplyTo(IQueryable query, ODataQuerySettings querySettings) at Microsoft.AspNet.OData.EnableQueryAttribute.ApplyQuery(IQueryable queryable, ODataQueryOptions queryOptions) at Microsoft.AspNet.OData.EnableQueryAttribute.ExecuteQuery(Object responseValue, IQueryable singleResultCollection, IWebApiActionDescriptor actionDescriptor, Func2 modelFunction,
IWebApiRequestMessage request, Func2 createQueryOptionFunction) at Microsoft.AspNet.OData.EnableQueryAttribute.OnActionExecuted(Object responseValue, IQueryable singleResultCollection, IWebApiActionDescriptor actionDescriptor, IWebApiRequestMessage request, Func2 modelFunction, Func2 createQueryOptionFunction, Action1 createResponseAction, Action`3 createErrorAction) at
Microsoft.AspNet.OData.EnableQueryAttribute.OnActionExecuted(ActionExecutedContext
actionExecutedContext) at
.ODataQueryableAttribute.OnActionExecuted(ActionExecutedContext
actionExecutedContext) in
ODataQueryableAttribute.cs:line
32 at
Microsoft.AspNetCore.Mvc.Filters.ActionFilterAttribute.d__6.MoveNext()
This is the general code from the Controller (in this case it is PersonController)
[EnableQuery]
public virtual IQueryable<TDtoSearch> Get([FromQuery]string excludeIDs = null)
{
return Service.GetQueryable()
.ProjectTo<TDtoSearch>(Mapper.MapperConfiguration);
}
And set up for OdataEDM, here I don't setup for the Person entity.
ODataConventionModelBuilder builder
builder.EntitySet<PersonDto>("Person").EntityType.HasKey(r => new { r.ID });
builder.EntitySet<PersonSearchDto>("PersonSearch").EntityType.HasKey(r => new { r.ID });
Can somebody help me with this exception?

No parameterless constructor defined for this object for MVC Controller

I have this controller as you can see :
namespace Web.Front.Controllers
{
public class CarController : Controller
{
ICarService _CarService;
public CarController(ICarService carService)
{
_CarService = carService;
}
// GET: Car
public ActionResult Index()
{
return View();
}
}
}
When i call index action i get this error :
No parameterless constructor defined for this object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.MissingMethodException: No parameterless constructor defined for this object.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[MissingMethodException: No parameterless constructor defined for this object.]
System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +119
System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +232
System.Activator.CreateInstance(Type type, Boolean nonPublic) +83
System.Activator.CreateInstance(Type type) +11
System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +55
[InvalidOperationException: An error occurred when trying to create a controller of type 'Web.Front.Controllers.CarController'. Make sure that the controller has a parameterless public constructor.]
System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +178
System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) +80
System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +102
System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +184
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +50
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +48
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +16
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +103
System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +48
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +159
As a note i am using ninject to inject services to controllers .when i remove the service from constructor it works .
The ninject code:
private static void RegisterServices(IKernel kernel)
{
kernel.Bind<DidbaanContext>().To<DidbaanContext>();
kernel.Bind<ICarService>().To<CarService>();
kernel.Bind<ICarRepository>().To<CarRepository>();
}
mvc needs parameterless contructions.
If you have no constructor, .Net-runtime create parameterless contruction automaticly, otherwise if you have a contruction with parameter, than the runtime don't do that and raise an error.
Ether you create a new carService on each controler, or you use a serviceProvider.
The unittest are simple with a serviceprovider.
With asp.net core its easy enter link description here, if you use mvc 4 or 5. you can see here a see here a sample enter link description here

No parameterless constructor defined for the object

Just upgraded to from SC 8.0 to 8.1 Update3 and started see No parameterless constructor defined for the object error.
Any ideas what could be different between 8.0 and 8.1 rendering?
Solution includes Glass Mapper as well. I did not add any Areas since the 8.0 build was single site setup.
Full error:
[MissingMethodException: No parameterless constructor defined for this object.]
System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +138
System.Activator.CreateInstance(Type type, Boolean nonPublic) +105
System.Activator.CreateInstance(Type type) +12
System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +73
[InvalidOperationException: An error occurred when trying to create a controller of type 'XOM.HR.Web.Controllers.Page.PageChromeController'. Make sure that the controller has a parameterless public constructor.]
System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +240
System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +103
Sitecore.Mvc.Controllers.SitecoreControllerFactory.CreateController(RequestContext requestContext, String controllerName) +96
[ControllerCreationException: Could not create controller: 'PageChrome'.
The context item is: '/sitecore/content/Home'.
The current route url is: '{*pathInfo}'. This is the default Sitecore route which is set up in the 'InitializeRoutes' processor of the 'initialize' pipeline. ]
Sitecore.Mvc.Controllers.SitecoreControllerFactory.CreateController(RequestContext requestContext, String controllerName) +202
System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +267
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +95
System.Web.Mvc.ServerExecuteHttpHandlerWrapper.Wrap(Func`1 func) +27
System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride) +3614
System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage) +131
System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm) +36
System.Web.Mvc.Html.ChildActionExtensions.ActionHelper(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues, TextWriter textWriter) +595
System.Web.Mvc.Html.ChildActionExtensions.RenderAction(HtmlHelper htmlHelper, String actionName, String controllerName) +52
ASP._Page_Views_Shared_Layouts_Index_cshtml.Execute() in c:\inetpub\wwwroot\Website\Views\Shared\Layouts\Index.cshtml:5
System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +253
System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +148
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +122
System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName, Object model, ViewDataDictionary viewData) +137
Sitecore.Mvc.Presentation.ViewRenderer.Render(TextWriter writer) +343
[InvalidOperationException: Error while rendering view: '~/Views/Shared/Layouts/Index.cshtml' (model: 'Sitecore.Mvc.Presentation.RenderingModel, Sitecore.Mvc').
]
Sitecore.Mvc.Presentation.ViewRenderer.Render(TextWriter writer) +826
Sitecore.Mvc.Pipelines.Response.RenderRendering.ExecuteRenderer.Render(Renderer renderer, TextWriter writer, RenderRenderingArgs args) +30
Sitecore.Mvc.Pipelines.Response.RenderRendering.ExecuteRenderer.Process(RenderRenderingArgs args) +75
(Object , Object[] ) +74

Glass.Mapper.MapperException: Failed to create type - No parameterless constructor defined for this object

Following an earlier post, I'm implementing this YouTube Video Picker in Sitecore - this has involved creating a custom Field Type (YouTubeVideoField). the control itself works no problem but when trying to get the video on the page (#Html.Sitecore().Field("YouTube Video")) I get the following error. Any ideas?
5824 15:50:34 ERROR Unhandled exception occurred
Exception: System.Web.HttpUnhandledException
Message: An unhandled exception occurred.
Source: Sitecore.Mvc
at Sitecore.Mvc.Pipelines.MvcEvents.Exception.ShowAspNetErrorMessage.ShowErrorMessage(ExceptionContext exceptionContext, ExceptionArgs args)
at Sitecore.Mvc.Pipelines.MvcEvents.Exception.ShowAspNetErrorMessage.Process(ExceptionArgs args)
at (Object , Object[] )
at Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args)
at Sitecore.Mvc.Pipelines.PipelineService.RunPipeline[TArgs](String pipelineName, TArgs args)
at Sitecore.Mvc.Filters.PipelineBasedRequestFilter.OnException(ExceptionContext exceptionContext)
at System.Web.Mvc.ControllerActionInvoker.InvokeExceptionFilters(ControllerContext controllerContext, IList`1 filters, Exception exception)
at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)
at Sitecore.Mvc.Controllers.SitecoreActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)
at System.Web.Mvc.Controller.<>c__DisplayClass22.<BeginExecuteCore>b__1e()
at System.Web.Mvc.Async.AsyncResultWrapper.<.cctor>b__0(IAsyncResult asyncResult, Action action)
at System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
at System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
at Sitecore.Mvc.Routing.RouteHttpHandler.EndProcessRequest(IAsyncResult result)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
Nested Exception
Exception: System.InvalidOperationException
Message: Error while rendering view: '/Views/Layouts/_Default.cshtml' (model: 'Sitecore.Mvc.Presentation.RenderingModel, Sitecore.Mvc').
Source: Sitecore.Mvc
at Sitecore.Mvc.Presentation.ViewRenderer.Render(TextWriter writer)
at Sitecore.Mvc.Pipelines.Response.RenderRendering.ExecuteRenderer.Render(Renderer renderer, TextWriter writer, RenderRenderingArgs args)
at Sitecore.Mvc.Pipelines.Response.RenderRendering.ExecuteRenderer.Process(RenderRenderingArgs args)
at (Object , Object[] )
at Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args)
at Sitecore.Mvc.Pipelines.PipelineService.RunPipeline[TArgs](String pipelineName, TArgs args)
at Sitecore.Mvc.Presentation.RenderingView.Render(ViewContext viewContext, TextWriter writer)
at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult)
at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)
Nested Exception
Exception: System.InvalidOperationException
Message: Error while rendering view: '/Views/Component/YouTubeVideo.cshtml'.
Source: Sitecore.Mvc
at Sitecore.Mvc.Presentation.ViewRenderer.Render(TextWriter writer)
at Sitecore.Mvc.Pipelines.Response.RenderRendering.ExecuteRenderer.Render(Renderer renderer, TextWriter writer, RenderRenderingArgs args)
at Sitecore.Mvc.Pipelines.Response.RenderRendering.ExecuteRenderer.Process(RenderRenderingArgs args)
at (Object , Object[] )
at Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args)
at Sitecore.Mvc.Pipelines.PipelineService.RunPipeline[TArgs](String pipelineName, TArgs args)
at Sitecore.Mvc.Pipelines.Response.RenderPlaceholder.PerformRendering.Render(String placeholderName, TextWriter writer, RenderPlaceholderArgs args)
at (Object , Object[] )
at Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args)
at Sitecore.Mvc.Pipelines.PipelineService.RunPipeline[TArgs](String pipelineName, TArgs args)
at Sitecore.Mvc.Helpers.SitecoreHelper.Placeholder(String placeholderName)
at ASP._Page_Views_Layouts__Default_cshtml.Execute() in c:\inetpub\wwwroot\Website\Views\Layouts\_Default.cshtml:line 27
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
at System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName, Object model, ViewDataDictionary viewData)
at Sitecore.Mvc.Presentation.ViewRenderer.Render(TextWriter writer)
Nested Exception
Exception: Glass.Mapper.MapperException
Message: Failed to create type BrainJocks.YouTube.Custom.FieldTypes.YouTubeVideoField
Source: Glass.Mapper
at Glass.Mapper.Pipelines.ObjectConstruction.Tasks.CreateConcrete.CreateConcreteTask.CreateObject(ObjectConstructionArgs args) in c:\TeamCity\buildAgent\work\8567e2ba106d3992\Source\Glass.Mapper\Pipelines\ObjectConstruction\Tasks\CreateConcrete\CreateConcreteTask.cs:line 117
at Glass.Mapper.Pipelines.ObjectConstruction.Tasks.CreateConcrete.CreateConcreteTask.Execute(ObjectConstructionArgs args) in c:\TeamCity\buildAgent\work\8567e2ba106d3992\Source\Glass.Mapper\Pipelines\ObjectConstruction\Tasks\CreateConcrete\CreateConcreteTask.cs:line 68
at Glass.Mapper.Pipelines.AbstractPipelineRunner`2.<>c__DisplayClass3.<CreateTaskExpression>b__2(T args) in c:\TeamCity\buildAgent\work\8567e2ba106d3992\Source\Glass.Mapper\Pipelines\AbstractPipelineRunner.cs:line 77
at Glass.Mapper.Pipelines.AbstractPipelineRunner`2.<>c__DisplayClass3.<CreateTaskExpression>b__2(T args) in c:\TeamCity\buildAgent\work\8567e2ba106d3992\Source\Glass.Mapper\Pipelines\AbstractPipelineRunner.cs:line 82
at Glass.Mapper.Pipelines.AbstractPipelineRunner`2.<>c__DisplayClass3.<CreateTaskExpression>b__2(T args) in c:\TeamCity\buildAgent\work\8567e2ba106d3992\Source\Glass.Mapper\Pipelines\AbstractPipelineRunner.cs:line 82
at Glass.Mapper.Pipelines.AbstractPipelineRunner`2.<>c__DisplayClass3.<CreateTaskExpression>b__2(T args) in c:\TeamCity\buildAgent\work\8567e2ba106d3992\Source\Glass.Mapper\Pipelines\AbstractPipelineRunner.cs:line 82
at Glass.Mapper.Pipelines.AbstractPipelineRunner`2.<>c__DisplayClass3.<CreateTaskExpression>b__2(T args) in c:\TeamCity\buildAgent\work\8567e2ba106d3992\Source\Glass.Mapper\Pipelines\AbstractPipelineRunner.cs:line 82
at Glass.Mapper.Pipelines.AbstractPipelineRunner`2.<>c__DisplayClass3.<CreateTaskExpression>b__2(T args) in c:\TeamCity\buildAgent\work\8567e2ba106d3992\Source\Glass.Mapper\Pipelines\AbstractPipelineRunner.cs:line 82
at Glass.Mapper.AbstractService.InstantiateObject(AbstractTypeCreationContext abstractTypeCreationContext) in c:\TeamCity\buildAgent\work\8567e2ba106d3992\Source\Glass.Mapper\AbstractService.cs:line 138
at Glass.Mapper.Sc.SitecoreService.CreateType(Type type, Item item, Boolean isLazy, Boolean inferType, Dictionary`2 parameters, Object[] constructorParameters) in c:\TeamCity\buildAgent\work\8567e2ba106d3992\Source\Glass.Mapper.Sc\SitecoreService.cs:line 495
at Glass.Mapper.Sc.Pipelines.Response.GetModel.GetObject(String model, Database db, Rendering renderingItem) in c:\TeamCity\buildAgent\work\8567e2ba106d3992\Source\Glass.Mapper.Sc.Mvc\Pipelines\Response\GetModel.cs:line 240
at Glass.Mapper.Sc.Pipelines.Response.GetModel.GetObject(String model, Database db, Rendering renderingItem) in c:\TeamCity\buildAgent\work\8567e2ba106d3992\Source\Glass.Mapper.Sc.Mvc\Pipelines\Response\GetModel.cs:line 188
at Glass.Mapper.Sc.Pipelines.Response.GetModel.Process(GetModelArgs args) in c:\TeamCity\buildAgent\work\8567e2ba106d3992\Source\Glass.Mapper.Sc.Mvc\Pipelines\Response\GetModel.cs:line 92
at (Object , Object[] )
at Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args)
at Sitecore.Mvc.Pipelines.PipelineService.RunPipeline[TArgs](String pipelineName, TArgs args)
at Sitecore.Mvc.Pipelines.PipelineService.RunPipeline[TArgs,TResult](String pipelineName, TArgs args, Func`2 resultGetter)
at Sitecore.Mvc.Presentation.Rendering.GetModel()
at Sitecore.Mvc.Presentation.Rendering.get_Model()
at Sitecore.Mvc.Presentation.ViewRenderer.get_Model()
at Sitecore.Mvc.Presentation.ViewRenderer.Render(TextWriter writer)
Nested Exception
Exception: System.MissingMethodException
Message: No parameterless constructor defined for this object.
Source: mscorlib
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
at Glass.Mapper.Pipelines.ObjectConstruction.Tasks.CreateConcrete.CreateConcreteTask.CreateObject(ObjectConstructionArgs args) in c:\TeamCity\buildAgent\work\8567e2ba106d3992\Source\Glass.Mapper\Pipelines\ObjectConstruction\Tasks\CreateConcrete\CreateConcreteTask.cs:line 100
Any ideas?
Thanks!
Dan
EDIT: So I'm reading through the Glass Mapper tutorials - do i need to create a custom data handler?
You probably need to implement a custom data handler. If you want to use the supplied custom field see these examples:
https://github.com/mikeedwards83/Glass.Mapper/blob/master/Source/Glass.Mapper.Sc/DataMappers/SitecoreFieldScWrapperMappers.cs

Autofac injecting to Controllers loaded with RegisterControllers()

Is there a way to enable injection in controllers loaded via builder.RegisterControllers() in an external assembly? When I copy the exact same assembly in my plugin folder, I get a parameterless constructor not found error.
// This doesnt work, parameterless constructor not found!
var assemblies = new DirectoryInfo(
HttpContext.Current.Server.MapPath("~/App_Plugins/"))
.GetFiles("*.dll")
.Select(r => Assembly.LoadFrom(r.FullName)).ToArray();
// This works, injection happens correctly on constructor
var assemblies = new[] {typeof (MvcApplication).Assembly};
The second one will work, while the first one will produce the error. I have tried manualy also registering the "external" controllers but still the same problem:
builder.RegisterAssemblyTypes(assemblies)
.Where(r => r.BaseType == typeof(Controller))
.InstancePerHttpRequest();
I am using the DefaultControllerFactory of mvc 4
Stack trace is this:
No parameterless constructor defined for this object.
[MissingMethodException: No parameterless constructor defined for this object.]
System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +113
System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +232
System.Activator.CreateInstance(Type type, Boolean nonPublic) +83
System.Activator.CreateInstance(Type type) +6
System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +55
[InvalidOperationException: An error occurred when trying to create a controller of type 'TestProject.Controllers.HomeController'. Make sure that the controller has a parameterless public constructor.]
System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +178
System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) +77
System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +66
System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +191
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +50
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +48
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +16
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +301
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
I'm not seeing Autofac involved in the stack trace. If Autofac were unhappy the exception would look something like:
[DependencyResolutionException: None of the constructors found with 'Public binding flags' on type 'SomeApp.WebApplication.Areas.Shared.Controllers.AccountController' can be invoked with the available services and parameters:
Cannot resolve parameter 'SomeApp.WebApplication.Areas.Shared.Controllers.Slappy slappy' of constructor 'Void .ctor(SomeApp.Web.LoginService, SomeApp.Web.AccountMembership.IMembershipService, SomeApp.Infrastructure.Logging.ILog, SomeApp.WebApplication.Areas.Shared.Controllers.Slappy)'.]
Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters) +377
Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters) +48
Autofac.Core.Resolving.InstanceLookup.Execute() +48
Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters) +167
Autofac.Core.Resolving.ResolveOperation.Execute(IComponentRegistration registration, IEnumerable`1 parameters) +64
Autofac.Core.Lifetime.LifetimeScope.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters) +163
Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable`1 parameters, Object& instance) +70
Autofac.ResolutionExtensions.ResolveOptionalService(IComponentContext context, Service service, IEnumerable`1 parameters) +53
Autofac.Integration.Mvc.AutofacDependencyResolver.GetService(Type serviceType) +59
System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +41
[InvalidOperationException: An error occurred when trying to create a controller of type 'SomeApp.WebApplication.Areas.Shared.Controllers.AccountController'. Make sure that the controller has a parameterless public constructor.]
System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +179
System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) +80
System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +74
System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +196
System.Web.Mvc.<>c__DisplayClass6.<BeginProcessRequest>b__2() +49
System.Web.Mvc.<>c__DisplayClassb`1.<ProcessInApplicationTrust>b__a() +13
System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22
System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Func`1 func) +88
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +98
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +50
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +16
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +301
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
Verify you are setting the DependencyResolver.
DependencyResolver.SetResolver(new AutofacDependencyResolver(ApplicationContainer));

Resources