简体   繁体   English

System.IO.FileNotFoundException:无法加载文件或程序集

[英]System.IO.FileNotFoundException: Could not load file or assembly

I have a WPF application that has 3 projects in the solution. 我有一个WPF应用程序,在解决方案中有3个项目。 I have the main menu, which is the actual EXE, a reporting DLL and the application files DLL which both are a WPF Class Library. 我有主菜单,它是实际的EXE,报告DLL和应用程序文件DLL,它们都是WPF类库。 I'm getting the System.IO error when I'm trying to use a 3rd party reporting tool from in the application files DLL. 尝试从应用程序文件DLL中使用第三方报告工具时,出现System.IO错误。 I have the 3rd party DLLs referenced and are set to copy local in my application DLL. 我引用了第三方DLL,并设置为在我的应用程序DLL中本地复制。 Everything works fine if i reference the 3rd party reporting tool in the EXE project but I don't want to do that. 如果我在EXE项目中引用了第三方报告工具,则一切正常,但我不想这样做。 I want my DLL to be stand alone so someone else can reference my DLL without having to add anything but my DLL. 我希望我的DLL独立存在,以便其他人可以引用我的DLL,而不必添加我的DLL。 Anyone have any idea of what i might need to do to fix this? 任何人对我可能需要做些什么来解决此问题有任何想法? Thanks 谢谢

Go to your output directory and walk though all your DLL's using http://www.dependencywalker.com . 转到输出目录,并使用http://www.dependencywalker.com浏览所有DLL。 Find the missing dll, use the exception to give you a good starting position. 找到丢失的dll,使用异常为您提供良好的开始位置。

I don't believe what you want to do is possible though. 我不相信您想要做什么。 If your DLL has dependencies on other DLL's, then your DLL needs access the other DLL's. 如果您的DLL依赖于其他DLL,则您的DLL需要访问其他DLL。 You can't simply build the other DLL's into your DLL. 您不能简单地将其他DLL构建到您的DLL中。

Copy local means that it will be copied to the bin folder of the current project which in the application files case would then copy it to the bin folder of the application files which is not what you want. 复制本地意味着将其复制到当前项目的bin文件夹中,在应用程序文件的情况下,它将随后复制到应用程序文件的bin文件夹中,这不是您想要的。

Try changing the output path (Right click properties on project -> Build) of your application files to the bin path of your exe project 尝试将应用程序文件的输出路径(项目上的右键单击属性->构建)更改为exe项目的bin路径

I've used ResourceDictionary from different dll in this way: 我以这种方式使用了来自不同dll的ResourceDictionary

<UserControl x:Class="DllName1.Class1" .......>
    <UserControl.Resources>
        <ResourceDictionary Source="pack://application:,,,/DllName2;component/Resources/ResourceStyleDictionaryFileName.xaml" />
    </UserControl.Resources>

    <DockPanel>
        <TextBlock Text="test" Style="{StaticResource ResourceKey=SomeResourceFromOtherDLL}" />
    </DockPanel>
</UserControl>

and I got the very same error , but only in the first time that the Class1 was loaded. 而且我也遇到了同样的错误 ,但是只有在第一次加载Class1时才出现。 from the second time and on, it worked flawless. 从第二次开始,它就完美无缺了。

so, I've turned assembly bind failure logging (Fusion) , on ( see here how ) and opened Debug->windows->Modules list, and I've found that DllName2 is not yet loaded, but on the second time, it is loaded. 所以,我已经变成集绑定失败日志记录(融合), 见这里如何 ),并打开调试- > Windows的>模块列表,我发现DllName2尚未加载,但在第二次,它已加载。

During my trial & error, I've consulted a friend ( user1151392 ) find out that if I use some dummy class from DllName2, the Dll will be loaded in the first time. 在反复试验中,我咨询了一位朋友( user1151392 ),发现如果我使用DllName2中的一些伪类,则Dll将在第一次加载。

Here's what I've ended up with: 这就是我最终得到的结果:

    <DockPanel>
        <!-- weird enough, but that fixed my issue -->
        <dll2alias:SomePublicClass />

        <TextBlock Text="test" Style="{StaticResource ResourceKey=SomeResourceFromOtherDLL}" />
    </DockPanel>
</UserControl>

So, I guess that the mechanism that loads dll for Resources is different than the one loads Instances. 因此,我猜想为资源加载dll的机制不同于加载实例的机制。

thank you user1151392 ! 谢谢user1151392

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法加载文件或程序集System.IO.FileNotFoundException - Could not load file or assembly System.IO.FileNotFoundException System.IO.FileNotFoundException: '无法加载文件或程序集 - System.IO.FileNotFoundException: 'Could not load file or assembly 奇怪的错误:System.IO.FileNotFoundException:无法加载文件或程序集 - Weird Error: System.IO.FileNotFoundException: Could not load file or assembly System.IO.FileNotFoundException: 无法加载文件或程序集 C# - System.IO.FileNotFoundException: Could not load file or assembly C# 无法加载程序集&gt;&gt; System.IO.FileNotFoundException:无法加载文件或程序集&#39;System.Core, - Unable to Load assembly>>System.IO.FileNotFoundException: Could not load file or assembly 'System.Core, System.IO.FileNotFoundException:无法加载文件或程序集“程序集名称”或其依赖项之一 - System.IO.FileNotFoundException: Could not load file or assembly 'name of assembly' or one of its dependencies 发布版本抛出“ System.IO.FileNotFoundException:无法加载文件或程序集”以查找XmlSerializers程序集 - Release build throws “System.IO.FileNotFoundException: Could not load file or assembly” looking for XmlSerializers assembly System.IO.FileNotFoundException:无法加载文件或程序集。 系统找不到文件SharpSvn.dll - System.IO.FileNotFoundException: Could not load file or assembly. The system cannot find the file SharpSvn.dll System.IO.FileNotFoundException:无法加载文件或程序集System.Xml.Linq - System.IO.FileNotFoundException: Could not load file or assembly System.Xml.Linq System.IO.FileNotFoundException:无法加载文件或程序集&#39;System.Web.DataVisualization MEF MVC - System.IO.FileNotFoundException: Could not load file or assembly 'System.Web.DataVisualization MEF MVC
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM