英文:
Could not load file or assembly 'System.Configuration.ConfigurationManager, The system cannot find the file specified
问题
我有一个包含两个项目的解决方案,一个是Framework,另一个是Core。它们相互交互。但是,即使我已安装了这个Nuget库,在Framework项目中仍然出现了这个错误。我注意到,当我删除旧版本(System.Configuration)时,这段代码将无法编译...
ConfigurationManager.ConnectionStrings["NAME"].ConnectionString;
这告诉我它无论如何都在忽略“System.Configuration.ConfigurationManager”。但如果我两者都安装了,它会在运行时出现上述错误。为什么Framework项目需要这个库呢?它不是一个Core库吗?
我应该指出,Framework项目是一个类库。
英文:
I have a solution with two projects, one in Framework and the other in Core. They interact with one another. But I am getting this error in the Framework project even though I have this Nuget Library installed. I notice that when I delete the older version (System.Configuration) this code will not compile...
ConfigurationManager.ConnectionStrings["NAME"].ConnectionString;
Which tells me that it is ignoring the "System.Configuration.ConfigurationManager" anyway. But if I have both installed it errors out at runtime with the above mentioned error. Why would the Framework project even need this library? It's a Core library no?
I should point out that the Framework project is a class library.
答案1
得分: 5
无法从.NET Core程序集引用.NET Framework程序集(反之亦然)。
这可能看起来可以工作,对于一小部分程序集确实可以工作,但文档指出不能这样做,你将会收到错误消息来证明文档的正确性。你刚刚遇到了其中之一。
那么,如果你想要共享代码,解决方案是什么呢?你可以创建一个.NET Standard程序集。这些程序集可以被.NET Core和.NET Framework同时引用。但如果你需要一个程序集是.NET Core,另一个程序集是.NET Framework,那么你就没办法了。你将不得不使用间接的通信手段(例如HTTP、命名管道或内存映射文件),就像它们是两种完全不同的编程语言一样。
英文:
You cannot reference a .NET Framework assembly from a .NET Core assembly (or vice versa).
It might look like it works and it might indeed work for a very small subset of assemblies, but the documentation says you cannot and you will get errors to prove the documentation correct. You just got one of them.
So what is the solution if you want to shared code? Well you could create a .NET Standard assembly. Those can be referenced by both .NET Core and .NET Framework. But if you need one assembly to be .NET Core and the other to be .NET Framework, you are out of luck. You will have to use indirect means of communication (for example HTTP or named pipes or memory mapped files) as if it were two completely different programming languages.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论