Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# System.IO.FileNotFoundException:无法加载文件或程序集_C#_.net_Wpf_Vb.net - Fatal编程技术网

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

C# System.IO.FileNotFoundException:无法加载文件或程序集,c#,.net,wpf,vb.net,C#,.net,Wpf,Vb.net,我有一个WPF应用程序,在解决方案中有3个项目。我有主菜单,它是实际的EXE,一个报告DLL和应用程序文件DLL,它们都是WPF类库。当我试图使用应用程序文件DLL中的第三方报告工具时,我遇到System.IO错误。我引用了第三方DLL,并将其设置为在我的应用程序DLL中复制本地DLL。如果我在EXE项目中引用第三方报告工具,一切都正常,但我不想这样做。我希望我的DLL是独立的,这样其他人就可以引用我的DLL,而无需添加除我的DLL以外的任何内容。有人知道我需要做什么来解决这个问题吗?谢谢转到您

我有一个WPF应用程序,在解决方案中有3个项目。我有主菜单,它是实际的EXE,一个报告DLL和应用程序文件DLL,它们都是WPF类库。当我试图使用应用程序文件DLL中的第三方报告工具时,我遇到System.IO错误。我引用了第三方DLL,并将其设置为在我的应用程序DLL中复制本地DLL。如果我在EXE项目中引用第三方报告工具,一切都正常,但我不想这样做。我希望我的DLL是独立的,这样其他人就可以引用我的DLL,而无需添加除我的DLL以外的任何内容。有人知道我需要做什么来解决这个问题吗?谢谢

转到您的输出目录,浏览所有DLL的使用情况。找到丢失的dll,使用异常为您提供一个良好的起始位置

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

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

但是我不相信你想做的是可能的。如果您的DLL依赖于其他DLL,则您的DLL需要访问其他DLL。您不能简单地将另一个DLL构建到您的DLL中。

复制本地意味着它将被复制到当前项目的bin文件夹中,在应用程序文件的情况下,该文件夹将复制到应用程序文件的bin文件夹中,而这不是您想要的

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

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

尝试将应用程序文件的输出路径(右键单击project->Build上的属性)更改为exe项目的bin路径

我使用了不同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>
    <DockPanel>
        <!-- weird enough, but that fixed my issue -->
        <dll2alias:SomePublicClass />

        <TextBlock Text="test" Style="{StaticResource ResourceKey=SomeResourceFromOtherDLL}" />
    </DockPanel>
</UserControl>
所以,我猜为资源加载dll的机制与加载实例的机制不同

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

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

谢谢大家!

是否有可能第三方DLL有依赖项,而FileNotFound是部署时缺少依赖项的结果?@Smudge202-这是个好主意。我总是被这件事缠住。错误说明它无法加载一个DLL,但实际上它意味着它找不到该DLL的依赖项。这也是我想知道的,如果可能的话。要将dll打包到dll中,使使用父dll的exe不知道dll中的内容…实际上,可以使用ILMerge将多个.NET程序集合并到单个程序集中。
    <DockPanel>
        <!-- weird enough, but that fixed my issue -->
        <dll2alias:SomePublicClass />

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