C# Assembly.LoadFile在设计时找不到该文件

C# Assembly.LoadFile在设计时找不到该文件,c#,wpf,binding,C#,Wpf,Binding,我的资源文件位于另一个项目中。在MainwindowProject中的App.xaml.cs中,我编写如下代码来加载资源文件 static ResourceBundle CreateResourceBundle() { string dllPath = System.IO.Directory.GetCurrentDirectory() + "\\Trade.Resources.dll"; ResourceBundle re

我的资源文件位于另一个项目中。在MainwindowProject中的App.xaml.cs中,我编写如下代码来加载资源文件

static ResourceBundle CreateResourceBundle()
        {

             string dllPath = System.IO.Directory.GetCurrentDirectory() + "\\Trade.Resources.dll";
               ResourceBundle resBundle = new ResourceBundle(Assembly.LoadFile(dllPath));
                resBundle.LocaleRoot = "Trade.Resources.locale"; //where my locale files are
                resBundle.AddResourceFile("Resources");

                string culture = "en-US";
                resBundle.Locale = culture;
                System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo(culture);
               return resBundle;
}
某些用户控件正在使用此resBundle。它在运行时运行良好。但是,如果在设计时打开父xaml窗口,就会出现此异常,并且无法加载usercontrol

The system cannot find the file specified. (Exception from HRESULT: 0x80070002)
   at System.Reflection.RuntimeAssembly.nLoadFile(String path, Evidence evidence)
   at System.Reflection.Assembly.LoadFile(String path)
我怎样才能解决这个问题?谢谢

编辑:临时解决方案

我刚刚在Trade.Resources项目中添加了接口。在App.xaml.cs中,如下所示

Type iResType = Type.GetType("Trade.Resources.IRes,Trade.Resources", true);
            ResourceBundle resBundle = new ResourceBundle(Assembly.GetAssembly(iResType));

到目前为止,它在设计时和运行时都运行良好。

尝试将资源文件的“复制到输出目录”属性设置为始终复制。通过执行此操作,您的资源文件将复制到执行程序集的Bin目录。即使这不起作用,也要将您的资源设置为嵌入式资源,并尝试从清单中读取它。一旦将副本设置为输出目录,我不确定如何获取文件“要始终复制资源文件的属性,然后只加载文件,它应该可以工作

但仍然不工作。”。对于临时解决方案,我只需在资源解决方案中添加接口。然后,我在app.xaml.cs中创建这个类型,并使用“Assembly.GetAssembly(iResType)”。谢谢。我已经试过你的建议了。我还没有被开除。谢谢