C# System.TypeInitializationException:';DemoProject.TestResources.StaticClassExample';抛出异常
我在一个名为StaticClassExample的公共类上有一个静态方法C# System.TypeInitializationException:';DemoProject.TestResources.StaticClassExample';抛出异常,c#,.net,exception,C#,.net,Exception,我在一个名为StaticClassExample的公共类上有一个静态方法 public static string GetValue(string res, string key) { string value = string.Empty; value = getValueByLang(res, key, 1); // get resource value for default locale if (string.IsNull
public static string GetValue(string res, string key)
{
string value = string.Empty;
value = getValueByLang(res, key, 1);
// get resource value for default locale
if (string.IsNullOrEmpty(value))
{
value = getValueByLang(res, key, 1);
}
return value;
}
在另一个类中,我将此方法称为
return StaticClassExample.GetValue(_resource, "Success");
但每次它都会给出一个例外,比如:
System.TypeInitializationException:“DemoProject.TestResources.StaticClassExample”的类型初始值设定项引发了异常。”
内部异常必须在中指定用于分析的有效信息
绳子
消息类型初始值设定项
“DemoProject.TestResources.StaticClassExample”引发异常
GetValue
是StaticClassExample
中唯一的代码吗?如果没有,那么你应该发布整个代码。配置文件中缺少了一些数据,正是因为这个原因,我得到了那个异常,所以只要添加那个值,我就解决了这个问题。