4

I am testing testing DXA .NET 1.2, when rendering a Component with a MediaItem, I get the exception:

Cannot create an abstract class the modelType. the value is:

modelType {Name = "MediaItem" FullName = "Sdl.Web.Common.Models.MediaItem"} System.Type {System.RuntimeType}

My site.log shows the following error:

Sdl.Web.Common.DxaException: Unable to map field 'media' to property of type 'Sdl.Web.Common.Models.MediaItem'.

code from dxa-web-application-dotnet/Sdl.Web.Tridion/Mapping/DefaultModelBuilder.cs

model = (ViewModel)Activator.CreateInstance(modelType);

FULL log:

015-12-04 18:39:39,553 [17] ERROR - Unable to map field 'media' to property of type 'Sdl.Web.Common.Models.MediaItem'. Sdl.Web.Common.DxaException: Unable to map field 'media' to property of type 'Sdl.Web.Common.Models.MediaItem'. ---> System.MissingMethodException: Cannot create an abstract class. 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.Activator.CreateInstance(Type type, Boolean nonPublic) at System.Activator.CreateInstance(Type type) at Sdl.Web.Tridion.Mapping.DefaultModelBuilder.CreateViewModel(MappingData mappingData) in c:\Jenkins\workspace\DXA Dev CI Web App .NET\Sdl.Web.Tridion\Mapping\DefaultModelBuilder.cs:line 389 at Sdl.Web.Tridion.Mapping.DefaultModelBuilder.BuildEntityModel(EntityModel& entityModel, IComponent component, Type baseModelType, Localization localization) in c:\Jenkins\workspace\DXA Dev CI Web App .NET\Sdl.Web.Tridion\Mapping\DefaultModelBuilder.cs:line 202 at Sdl.Web.Tridion.Mapping.ModelBuilderPipeline.CreateEntityModel(IComponent component, Type baseModelType, Localization localization) in c:\Jenkins\workspace\DXA Dev CI Web App .NET\Sdl.Web.Tridion\Mapping\ModelBuilderPipeline.cs:line 119 at Sdl.Web.Tridion.Mapping.DefaultModelBuilder.MapComponent(IComponent component, Type modelType, Localization localization) in c:\Jenkins\workspace\DXA Dev CI Web App .NET\Sdl.Web.Tridion\Mapping\DefaultModelBuilder.cs:line 737 at Sdl.Web.Tridion.Mapping.DefaultModelBuilder.MapFieldValues(IField field, Type modelType, Boolean multival, MappingData mapData) in c:\Jenkins\workspace\DXA Dev CI Web App .NET\Sdl.Web.Tridion\Mapping\DefaultModelBuilder.cs:line 609 --- End of inner exception stack trace --- at Sdl.Web.Mvc.Controllers.BaseController.EnrichModel(ViewModel model) in c:\Jenkins\workspace\DXA Dev CI Web App .NET\Sdl.Web.Mvc\Controllers\BaseController.cs:line 84 at Sdl.Web.Mvc.Controllers.EntityController.Entity(EntityModel entity, Int32 containerSize) in c:\Jenkins\workspace\DXA Dev CI Web App .NET\Sdl.Web.Mvc\Controllers\EntityController.cs:line 18 at lambda_method(Closure , ControllerBase , Object[] ) at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary2 parameters) at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary2 parameters) at System.Web.Mvc.Async.AsyncControllerActionInvoker.b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.b__3f() at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass48.b__41() at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<>c__DisplayClass2b.b__1c() at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.b__1e(IAsyncResult asyncResult)

  • Did you check this out? tridion.stackexchange.com/questions/13003/… – Rick Pannekoek Dec 4 '15 at 7:30
  • hi Bart, i checked the thread, i am not creating a custom media item, i use core Teaser and the site complains for Unable to map field 'media' to property of type 'Sdl.Web.Common.Models.MediaItem'. i am trying to inject DXA into an existing blueprint. – Lucas Liu Dec 4 '15 at 19:05
  • Hi Eric ;-). Even though your scenario is different, I recommend the same analysis technique: ensure that warnings are logged and check the DXA site log. It should tell you more what the issue is: either it can't resolve any concrete type, or it resolves multiple (so it's ambiguous). In both cases it falls back to the model type (which is not a good idea in this case, because the model type is abstract) – Rick Pannekoek Dec 4 '15 at 20:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.