![](/img/trans.png)
[英]System.TypeInitializationException: 'The type initializer for 'Bid' threw an exception.'
[英]System.TypeInitializationException: 'The type initializer threw an exception.'
我有一个简单的类MyClass,它具有在DLL中定义的方法,现在我在另一个代码中引用此DLL,并尝试初始化类似Myclass obj = new MyClass()
。 我不确定为什么编译器会抛出NullReferenceException
。 请协助
DLL:
public class MyClass
{
public MyClass(){}
public void method()
{
//some code
}
}
其他代码:
void main()
{
MyClass obj=new MyClass(); //This is where I get NullReferenceException error
}
为了后代,因为我们在评论中找到了答案:
TypeInitializationException
通常是由静态字段初始化或静态构造函数执行中的错误引起的。
实际上,我们发现内部异常堆栈跟踪指向:
SqlConStr = ConfigurationManager.ConnectionStrings["RMDB.Database"].ConnectionString
此错误是由以下事实引起的:在应用程序的app.config
未指定连接字符串RMDB.Database
。 必须使用连接在应用程序的app.config
中指定连接字符串(事件是从dll使用的)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.