我正在使用这样的代码。 当lan为null时,我收到异常 TypeInitializationException。
有没有办法检查URI是否为null?
ResourceDictionary dict = new ResourceDictionary();
dict.Source = new Uri("/Emdep.Geos.UI.Common;component/Resources/Language." + lan + ".xaml", UriKind.RelativeOrAbsolute);
An unhandled exception of type 'System.TypeInitializationException' occurred in Emdep.Geos.UI.Common.dll## Heading ##
答案 0 :(得分:0)
您应该做的是捕捉找不到FileNotFoundException
时发生的ResourceDictionary
:
ResourceDictionary dict = new ResourceDictionary();
try
{
dict.Source = new Uri("/Emdep.Geos.UI.Common;component/Resources/Language." + lan + ".xaml", UriKind.RelativeOrAbsolute);
}
catch (FileNotFoundException)
{
//the resource dictionary could not be located/loaded...
}