I have an ASP.NET Core 3.1 web app.
This application needs to load and execute some code from a 3rd party .NET Framework dll.
Unfortunately, the 3rd party code seems to have a dependency (or something else?) on System.ServiceModel, and when I call the code from that DLL, it throws the following error:
Could not load file or assembly 'System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. Reference assemblies should not be loaded for execution. They can only be loaded in the Reflection-only loader context. (0x80131058)
To try it out in a simpler environment, I have created 2 identical console apps which call this 3rd party component
That leads me to believing that something is problematic when I try to call this 3rd party .NET Framework code from .NET Core.
I had a look into a couple of questions, but they are a bit different:
Could not load file or assembly 'System.ServiceModel, Version=4.0.0.0
Could not load file or assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies
Reference assemblies should not be loaded for execution
Any idea what can I do to make it run?
We ran into this issue as well, what worked for us was to make sure that the RID (Runtime Identifier) was set to win-x64
(or win-x32
). However our stack was entirely .NET Core/Standard
In your case it is not generally possible to load a .NET Framework dll into the .NET Core runtime as the underlying changes are not backwards compatible. So even if you are able to get it to load you will likely run into runtime exceptions or process crashes/failures.
Actually, it turned out to be quite simple!
I had to add a reference to System.ServiceModel.Primitives
nuget in the .NET core application and it started to work all ok!
User contributions licensed under CC BY-SA 3.0