Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
689 views
in Technique[技术] by (71.8m points)

c# - .NET Core vs .NET Framework - Could not load file or assembly 'System.ServiceModel, Reference assemblies should not be loaded for execution

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

  • .NET Framework - works OK, no errors thrown
  • .NET Core - same error is thrown

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?

question from:https://stackoverflow.com/questions/65941547/net-core-vs-net-framework-could-not-load-file-or-assembly-system-servicemod

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...