私のリソースファイルは別のプロジェクトにあります。 MainwindowProjectのApp.xaml.csでは、以下のようなコードを記述してリソースファイルをロードします。Assembly.LoadFileはデザイン時にファイルを見つけることができません
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));
これまでのところ、設計時と実行時の両方で問題なく動作しています。
まだ一時的に回避するには、リソースソリューションにInterfaceを追加してからapp.xaml.csでこの型を作成し、 "Assembly.GetAssembly(iResType ) "。ありがとう。 – TNA