Runtime: .NET Core 2 type load exception for "AssociatedMetadataTypeTypeDescriptionProvider" when using full .net framework dll in web api owin

Created on 20 Jul 2017  路  20Comments  路  Source: dotnet/runtime

We've developed an app on top of "Full .NET/Owin". We managed to run that app on top of "Full .NET/ASP.NET Core" very easily.
Then we started to test that on .net core 2 as it accepts referencing full .net assemblies. Interestingly lots of things are working (signalr, web api, static files middleware etc).
Now we're working on "ASP.NET Web API / OData" as it has no suitable equivalent in .net core world).
In web api parts, we've used swagger, and by running its UI, I received an interesting exception:

"System.TypeLoadException","Message":"Could not load type
'System.ComponentModel.DataAnnotations.AssociatedMetadataTypeTypeDescriptionProvider' from assembly 'System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToke
n=31bf3856ad364e35'

This is a link of repository which contains the sample app you need to reproduce the problem:
https://github.com/ysmoradi/WebApiOwinSwaggerProblemOnDotNetCore2Preview

Run http://localhost:5000/api/swagger and you'll see that exception in console. Note that swagger itself works(!). You can fix this problem by commenting BadController class easily. You'll see GoodController methods in swagger ui and you can invoke them.

I think there is a problem in .NET full shim in .NET Core 2.

area-System.ComponentModel.DataAnnotations

All 20 comments

https://github.com/dotnet/corefx/issues/16101 I saw this now. Sorry. Could you please add this type to .net core 2?

@AlexGhiondea what criteria did you use for selecting the S.CM types to port? We have some parts of eg System.ComponentModel.DataAnnotations.dll from 4.6.1 and not others.

Below are the concrete types In S.CM (except Composition) that are in 4.6.1 but not Core.

T:System.ComponentModel.CurrentChangedEventManager
T:System.ComponentModel.CurrentChangingEventArgs
T:System.ComponentModel.CurrentChangingEventHandler
T:System.ComponentModel.CurrentChangingEventManager
T:System.ComponentModel.DependencyPropertyDescriptor
T:System.ComponentModel.DesignerProperties
T:System.ComponentModel.ErrorsChangedEventManager
T:System.ComponentModel.GroupDescription
E:System.ComponentModel.GroupDescription.PropertyChanged
E:System.ComponentModel.GroupDescription.System#ComponentModel#INotifyPropertyChanged#PropertyChanged
T:System.ComponentModel.ICollectionView
E:System.ComponentModel.ICollectionView.CurrentChanged
E:System.ComponentModel.ICollectionView.CurrentChanging
T:System.ComponentModel.ICollectionViewFactory
T:System.ComponentModel.ICollectionViewLiveShaping
T:System.ComponentModel.IEditableCollectionView
T:System.ComponentModel.IEditableCollectionViewAddNewItem
T:System.ComponentModel.IItemProperties
T:System.ComponentModel.ItemPropertyInfo
T:System.ComponentModel.PropertyChangedEventManager
T:System.ComponentModel.PropertyFilterAttribute
T:System.ComponentModel.SortDescription
T:System.ComponentModel.SortDescriptionCollection
E:System.ComponentModel.SortDescriptionCollection.CollectionChanged
E:System.ComponentModel.SortDescriptionCollection.System#Collections#Specialized#INotifyCollectionChanged#CollectionChanged
T:System.ComponentModel.DataAnnotations.AssociatedMetadataTypeTypeDescriptionProvider
T:System.ComponentModel.DataAnnotations.BindableTypeAttribute
T:System.ComponentModel.DataAnnotations.MetadataTypeAttribute
T:System.ComponentModel.DataAnnotations.ScaffoldTableAttribute
T:System.ComponentModel.Design.ActiveDesignSurfaceChangedEventArgs
T:System.ComponentModel.Design.ActiveDesignSurfaceChangedEventHandler
T:System.ComponentModel.Design.ArrayEditor
T:System.ComponentModel.Design.BinaryEditor
T:System.ComponentModel.Design.ByteViewer
T:System.ComponentModel.Design.CollectionEditor
T:System.ComponentModel.Design.CollectionEditor.CollectionForm
T:System.ComponentModel.Design.ComponentDesigner
T:System.ComponentModel.Design.ComponentDesigner.ShadowPropertyCollection
T:System.ComponentModel.Design.DateTimeEditor
T:System.ComponentModel.Design.DesignerActionHeaderItem
T:System.ComponentModel.Design.DesignerActionItem
T:System.ComponentModel.Design.DesignerActionItemCollection
T:System.ComponentModel.Design.DesignerActionList
T:System.ComponentModel.Design.DesignerActionListCollection
T:System.ComponentModel.Design.DesignerActionListsChangedEventArgs
T:System.ComponentModel.Design.DesignerActionListsChangedEventHandler
T:System.ComponentModel.Design.DesignerActionMethodItem
T:System.ComponentModel.Design.DesignerActionPropertyItem
T:System.ComponentModel.Design.DesignerActionService
E:System.ComponentModel.Design.DesignerActionService.DesignerActionListsChanged
T:System.ComponentModel.Design.DesignerActionTextItem
T:System.ComponentModel.Design.DesignerActionUIService
E:System.ComponentModel.Design.DesignerActionUIService.DesignerActionUIStateChange
T:System.ComponentModel.Design.DesignerActionUIStateChangeEventArgs
T:System.ComponentModel.Design.DesignerActionUIStateChangeEventHandler
T:System.ComponentModel.Design.DesignerCommandSet
T:System.ComponentModel.Design.DesignSurface
E:System.ComponentModel.Design.DesignSurface.Disposed
E:System.ComponentModel.Design.DesignSurface.Flushed
E:System.ComponentModel.Design.DesignSurface.Loaded
E:System.ComponentModel.Design.DesignSurface.Loading
E:System.ComponentModel.Design.DesignSurface.Unloaded
E:System.ComponentModel.Design.DesignSurface.Unloading
E:System.ComponentModel.Design.DesignSurface.ViewActivated
T:System.ComponentModel.Design.DesignSurfaceCollection
T:System.ComponentModel.Design.DesignSurfaceEventArgs
T:System.ComponentModel.Design.DesignSurfaceEventHandler
T:System.ComponentModel.Design.DesignSurfaceManager
E:System.ComponentModel.Design.DesignSurfaceManager.ActiveDesignSurfaceChanged
E:System.ComponentModel.Design.DesignSurfaceManager.DesignSurfaceCreated
E:System.ComponentModel.Design.DesignSurfaceManager.DesignSurfaceDisposed
E:System.ComponentModel.Design.DesignSurfaceManager.SelectionChanged
T:System.ComponentModel.Design.EventBindingService
T:System.ComponentModel.Design.ExceptionCollection
T:System.ComponentModel.Design.IComponentDesignerDebugService
T:System.ComponentModel.Design.IComponentDesignerStateService
T:System.ComponentModel.Design.IDesignTimeAssemblyLoader
T:System.ComponentModel.Design.IMultitargetHelperService
T:System.ComponentModel.Design.InheritanceService
T:System.ComponentModel.Design.LoadedEventArgs
T:System.ComponentModel.Design.LoadedEventHandler
T:System.ComponentModel.Design.LocalizationExtenderProvider
T:System.ComponentModel.Design.MenuCommandsChangedEventArgs
T:System.ComponentModel.Design.MenuCommandsChangedEventHandler
T:System.ComponentModel.Design.MenuCommandService
E:System.ComponentModel.Design.MenuCommandService.MenuCommandsChanged
T:System.ComponentModel.Design.MultilineStringEditor
T:System.ComponentModel.Design.ObjectSelectorEditor
T:System.ComponentModel.Design.ObjectSelectorEditor.Selector
T:System.ComponentModel.Design.ObjectSelectorEditor.SelectorNode
T:System.ComponentModel.Design.ProjectTargetFrameworkAttribute
T:System.ComponentModel.Design.UndoEngine
T:System.ComponentModel.Design.UndoEngine.UndoUnit
E:System.ComponentModel.Design.UndoEngine.Undoing
E:System.ComponentModel.Design.UndoEngine.Undone
T:System.ComponentModel.Design.Data.DataSourceDescriptor
T:System.ComponentModel.Design.Data.DataSourceDescriptorCollection
T:System.ComponentModel.Design.Data.DataSourceGroup
T:System.ComponentModel.Design.Data.DataSourceGroupCollection
T:System.ComponentModel.Design.Data.DataSourceProviderService
T:System.ComponentModel.Design.Data.DesignerDataColumn
T:System.ComponentModel.Design.Data.DesignerDataConnection
T:System.ComponentModel.Design.Data.DesignerDataParameter
T:System.ComponentModel.Design.Data.DesignerDataRelationship
T:System.ComponentModel.Design.Data.DesignerDataSchemaClass
T:System.ComponentModel.Design.Data.DesignerDataStoredProcedure
T:System.ComponentModel.Design.Data.DesignerDataTable
T:System.ComponentModel.Design.Data.DesignerDataTableBase
T:System.ComponentModel.Design.Data.DesignerDataView
T:System.ComponentModel.Design.Data.IDataEnvironment
T:System.ComponentModel.Design.Data.IDesignerDataSchema
T:System.ComponentModel.Design.Serialization.BasicDesignerLoader
T:System.ComponentModel.Design.Serialization.CodeDomComponentSerializationService
T:System.ComponentModel.Design.Serialization.CodeDomDesignerLoader
T:System.ComponentModel.Design.Serialization.CodeDomLocalizationProvider
T:System.ComponentModel.Design.Serialization.CodeDomSerializer
T:System.ComponentModel.Design.Serialization.CodeDomSerializerBase
T:System.ComponentModel.Design.Serialization.CodeDomSerializerException
T:System.ComponentModel.Design.Serialization.CollectionCodeDomSerializer
T:System.ComponentModel.Design.Serialization.DesignerSerializationManager
E:System.ComponentModel.Design.Serialization.DesignerSerializationManager.SessionCreated
E:System.ComponentModel.Design.Serialization.DesignerSerializationManager.SessionDisposed
E:System.ComponentModel.Design.Serialization.DesignerSerializationManager.System#ComponentModel#Design#Serialization#IDesignerSerializationManager#ResolveName
E:System.ComponentModel.Design.Serialization.DesignerSerializationManager.System#ComponentModel#Design#Serialization#IDesignerSerializationManager#SerializationComplete
T:System.ComponentModel.Design.Serialization.ExpressionContext
T:System.ComponentModel.Design.Serialization.ICodeDomDesignerReload
T:System.ComponentModel.Design.Serialization.MemberCodeDomSerializer
T:System.ComponentModel.Design.Serialization.ObjectStatementCollection
T:System.ComponentModel.Design.Serialization.RootContext
T:System.ComponentModel.Design.Serialization.SerializeAbsoluteContext
T:System.ComponentModel.Design.Serialization.StatementContext
T:System.ComponentModel.Design.Serialization.TypeCodeDomSerializer

It would be interesting to know the full set you need @ysmoradi ... not sure how to find out though unless you want to add this type locally and see what happens,.

@danmosemsft I'm ready! Just tell me how to add this type locally to my app. Then I try to do the same for other types as needed. I can copy its code from mono code / reference source, but how can I add this type locally? I'm gonna spend time no matter how hard it would be.

@ysmoradi OK, it wil lbe a bit of work if you've not previously got set up to contribute. You'll want to clone this corefx repo, and then follow the docs (start here) to build it. Then follow the docs here to use the result. Hopefully the docs are accurate - if not please let us know and maybe submit a fix. Ping back if you get stuck.

Once you are successfully consuming bits you built yourself, you can add the type. You'd edit src\System.ComponentModel.Annotations\ref\System.ComponentModel.Annotations.cs to add the declaratoin, and put the implementation in src\System.ComponentModel.Annotations\src.

Thanks. I'm gonna try these steps (:

@ysmoradi isn鈥檛 this issue a duplicate of https://github.com/dotnet/corefx/issues/16101? Otherwise, what is different between them?

@divega Yeah, I've mentioned it in my second comment. I realized that late.

Incidentally the focus of System.ComponentModel.* API additions in 2.0 was those that in Desktop are in System.dll. These we ported into System.ComponentModel.dll. This type is in System.ComponentModel.DataAnnotations.dll. Some types from that were already in .NET Core, but not this one. I think we would be glad in general to have more of DataAnnotations ported.

Let's dupe this against https://github.com/dotnet/corefx/issues/16101 and make progress on S.CM.DA there.

It's ok. So, I'll report my progress there (:

@ysmoradi sounds good. Thanks!

Why System.ComponentModel.Composition is not available in .Net core 2.0?
i need this for [PartCreationPolicy(CreationPolicy.Shared)] is there any other way to migrate in to .net core 2.0?

@gummadikalyan this is tracked by https://github.com/dotnet/corefx/issues/11857. We haven't got a lot of interest so far. You might add your request there to help priortize.

Same problem Here!

I have a console application that copies data from EF6 to EFcore, but I can not access the DBContext class of EF6 because of the error.

Is there a momentary solution until the full solution is published?

@LuisPignataro Have you found a solution? I have the same issue when I'm using the EF6 with EFcore asp.net project

TypeLoadException: Could not load type 'System.ComponentModel.DataAnnotations.AssociatedMetadataTypeTypeDescriptionProvider' from assembly 'System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.

No @AndreyBespamyatnov ! My solution was to recreate EF6 model with EFcore.

Was this issue supposed to be resolved in 2.1? I'm still seeing the issue when trying to access EF 6 from a .NET Core web application.

Was this issue supposed to be resolved in 2.1? I'm still seeing the issue when trying to access EF 6 from a .NET Core web application.

As far as I know, this works in netcoreapp3.0+

Was this page helpful?
0 / 5 - 0 ratings