jeudi 14 mars 2019

Reflection from .net project and reading dll from .net core project in a different solution

I've got 2 solutions in visual studio 2017.

  • The first solution has a project that reads an assembly/dll from a project in an external solution. This project is coded in .net 4.5.2
  • The second solution has a project that with the targeted classes/dll to reflect to the first project. This project is written in .net core 2

Code in the first project:

string pathDllProject_DAL = "E:\\Coding\\Repos\\_order_manager_webapp\\order_manager_webapp_backend\\DAL\\bin\\Debug\\netcoreapp2.2\\DAL.dll";
Assembly ass_DAL2 = Assembly.LoadFile(pathDllProject_DAL);


Type[] respTypes = ass_DAL2.GetTypes(); //<----Exception Thrown HERE

This is the exception i get:

'ass_DAL2.GetTypes()' threw an exception of type 'System.Reflection.ReflectionTypeLoadException'
    Data: {System.Collections.ListDictionaryInternal}
    HResult: -2146232830
    HelpLink: null
    InnerException: null
    LoaderExceptions: {System.Exception[152]}
    Message: "Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information."
    Source: "mscorlib"
    StackTrace: "   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)\r\n   at System.Reflection.RuntimeModule.GetTypes()\r\n   at System.Reflection.Assembly.GetTypes()"
    TargetSite: {System.RuntimeType[] GetTypes(System.Reflection.RuntimeModule)}
    Types: {System.RuntimeType[279]}

I was wondering of there is an incompatibility in reading a DLL created in .net-core from a .net 4.5.2 framework? or is there some other issue?





Aucun commentaire:

Enregistrer un commentaire