开发者

System.IO.FileNotFoundException: Could not load file or assembly

I have a WPF application that has 3 projects in the so开发者_StackOverflow中文版lution. 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. I'm getting the System.IO error when I'm trying to use a 3rd party reporting tool from in the application files DLL. I have the 3rd party DLLs referenced and are set to copy local in my application DLL. Everything works fine if i reference the 3rd party reporting tool in the EXE project but I don't want to do that. I want my DLL to be stand alone so someone else can reference my DLL without having to add anything but my 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. Find the missing dll, use the exception to give you a good starting position.

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. You can't simply build the other DLL's into your 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.

Try changing the output path (Right click properties on project -> Build) of your application files to the bin path of your exe project


I've used ResourceDictionary from different dll in this way:

<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. 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.

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.

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.

thank you user1151392 !

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜