[英]Could not load file or assembly C# Console Application with Class Library
I've created a Class Library
in C# .Net Framework 4.8
, and in the solution I've also included a Console Application
, same target.我在 C#
.Net Framework 4.8
中创建了一个Class Library
,并且在解决方案中我还包含了一个Console Application
,相同的目标。 I'm running both in a x64
configuration.我都在
x64
配置中运行。 No errors on build.构建时没有错误。
I referenced the App
in the Library
, and when I run a Button
in a Form
in the Class Library
I'm getting an error:我在
Library
中引用了App
,当我在Class Library
中的Form
中运行Button
时,出现错误:
System.IO.FileNotFoundException: Could not load file or assembly 'ExampleApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
System.IO.FileNotFoundException:无法加载文件或程序集“ExampleApp,Version=1.0.0.0,Culture=neutral,PublicKeyToken=null”或其依赖项之一。 The system cannot find the file specified.
该系统找不到指定的文件。 File name: 'ExampleApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
文件名:'ExampleApp,Version=1.0.0.0,Culture=neutral,PublicKeyToken=null'
I've combed the inte.net and SO for a solution.我梳理了 inte.net 和 SO 的解决方案。 I tried repairing Visual Studio, I tried deleting the
.vs
folder in the projects, I tried things like:我尝试修复 Visual Studio,我尝试删除项目中的
.vs
文件夹,我尝试过如下操作:
solution 1 and solution 2 方案一和方案二
I seriously tried everything I could think of.我认真地尝试了我能想到的一切。 It has to be something to do with the.dll dependencies imho, because the only one that my
ExampleApp
is using is the Microsoft.CognitiveServices.Speech
reference which I installed via NugetPackage in my solution.它必须与 .dll 依赖关系恕我直言,因为我的
ExampleApp
使用的唯一一个是Microsoft.CognitiveServices.Speech
参考,我通过 NugetPackage 安装在我的解决方案中。
No idea how to debug this further or get a proper trace stack from this error...不知道如何进一步调试或从此错误中获得正确的跟踪堆栈...
Any ideas on how to proceed?关于如何进行的任何想法?
Thanks谢谢
Solved by changing the.dll's Copy Local property to True
通过将.dll的Copy Local属性更改为
True
来解决
Exactly @Yafim Simanovsky, I solved also my problem by changed <Private>
flag to True.正是@Yafim Simanovsky,我通过将
<Private>
标志更改为 True 也解决了我的问题。
My problem (“Could not load file or assembly…”) was with new Designer 'WpfSurface.exe' from VS 2022, which after changing the reference tags 'Private' to True, was able to copied all dependent.dll files to Cache.我的问题(“无法加载文件或程序集……”)与 VS 2022 中的新设计器“WpfSurface.exe”有关,在将引用标记“Private”更改为 True 后,它能够将所有 dependent.dll 文件复制到缓存中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.