Glass.Mapper.MapperException: 未能创建类型 - 没有为此对象定义无参数构造函数

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

继之前的 post 之后,我正在 Sitecore 中实施 this YouTube Video Picker - 这涉及创建自定义字段类型 (YouTubeVideoField)。控件本身没有问题但是当试图在页面上获取视频时 (@Html.Sitecore().Field("YouTube Video")) 我收到以下错误.有什么想法吗?

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\work67e2ba106d3992\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\work67e2ba106d3992\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\work67e2ba106d3992\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\work67e2ba106d3992\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\work67e2ba106d3992\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\work67e2ba106d3992\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\work67e2ba106d3992\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\work67e2ba106d3992\Source\Glass.Mapper\Pipelines\AbstractPipelineRunner.cs:line 82
   at Glass.Mapper.AbstractService.InstantiateObject(AbstractTypeCreationContext abstractTypeCreationContext) in c:\TeamCity\buildAgent\work67e2ba106d3992\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\work67e2ba106d3992\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\work67e2ba106d3992\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\work67e2ba106d3992\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\work67e2ba106d3992\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\work67e2ba106d3992\Source\Glass.Mapper\Pipelines\ObjectConstruction\Tasks\CreateConcrete\CreateConcreteTask.cs:line 100

有什么想法吗?

谢谢! 旦

编辑:所以我正在通读 Glass Mapper tutorials - 我需要创建自定义数据处理程序吗?

您可能需要实施自定义数据处理程序。如果您想使用提供的自定义字段,请参阅这些示例:

https://github.com/mikeedwards83/Glass.Mapper/blob/master/Source/Glass.Mapper.Sc/DataMappers/SitecoreFieldScWrapperMappers.cs