the type initializer for '' threw an exception
the type initializer for '' threw an exception
调查:查看类的构造函数是否会有异常抛出。
解决:去掉类的构造函数中可能出现的异常。
问题:.net应用程序通过Oracle.DataAccess.dll访问64位的Oracle服务器,在连接时出现以下异常:“System.TypeInitializationException:
The type initializer for 'Oracle.DataAccess.Client.OracleConnection'
threw an exception. ---> Oracle.DataAccess.Client.OracleException:
提供程序与此版本的 Oracle 客户机不兼容”
通过windows的事件查看器,发现类似如下应用程序错误:
事件类型:错误
事件来源:
事件种类:无
事件 ID:0
日期:2011-10-20
事件:15:25:18
用户:N/A
计算机:
描述:
Service cannot be started. System.TypeInitializationException: The type
initializer for 'Oracle.DataAccess.Client.OracleConnection' threw an
exception. ---> Oracle.DataAccess.Client.OracleException:提供程序与此版本的 Oracle 客户机不兼容
事件类型:错误
事件来源:.NET Runtime 4.0 Error Reporting
事件种类:无
事件 ID:5000
日期:2011-10-20
事件:15:25:19
用户:N/A
计算机:
描述:
EventType clr20r3, P1 dbsupport.exe, P2 1.0.0.0, P3 4e9d2829, P4
oracle.dataaccess, P5 4.112.2.0, P6 4cea1964, P7 6cc, P8 1f5, P9
oracle.dataaccess.client.oracle, P10 NIL.
如下系统错误:
事件类型:错误
事件来源:SideBySide
事件种类:无
事件 ID:59
日期:2011-10-20
事件:15:25:18
用户:N/A
计算机:
描述:
Generate Activation Context 为 C:\odp.net\bin\OraOps11w.dll 失败。 参考错误消息: 参照的汇编没有安装在系统上。
事件类型:错误
事件来源:SideBySide
事件种类:无
事件 ID:32
日期:2011-10-20
事件:15:39:28
用户:N/A
计算机:
描述:
找不到附属汇编 Microsoft.VC80.CRT,上一个错误是 参照的汇编没有安装在系统上。
事件类型:错误
事件来源:SideBySide
事件种类:无
事件 ID:59
日期:2011-10-20
事件:15:39:28
用户:N/A
计算机:
描述:
Resolve Partial Assembly 为 Microsoft.VC80.CRT 失败。 参考错误消息: 参照的汇编没有安装在系统上。
原因:
服务器安装的.net framework 中缺少以下两个包:
Microsoft Visual C++ 2005 Redistributable Package,
Microsoft Visual C++ 2005 SP1 Redistributable Package
解决方法:
下载上述包,并安装到服务器上。
下载地址:
http://www.microsoft.com/download/en/details.aspx?id=21254
http://www.microsoft.com/download/en/details.aspx?id=18471
今天写程序想实现一个Singleton模式,结果程序老是抛异常说"The type initializer for 'TestStatic.StaticClass' threw an exception.",InnerException是"Object reference not set to an instance of an object",后来发现犯了一个非常低级的错误,代码如下:
// In main.cs
static void Main()
{
string t = StaticClass.StrMember;
System.Diagnostics.Debug.WriteLine(t);
...
}
// StaticClass.cs
private StaticClass(int defValue)
{
Trace.WriteLine("StaticClass ctor");
IntMember = defValue;
}
private static StaticClass _instance = new StaticClass(12);
private int intMember;
public static int IntMember
{
set
{
Trace.WriteLine("set IntMember");
_instance.intMember = value;
}
}
看出问题了吗?问题就出在
IntMember = defValue;
这句话,为这个静态属性赋值的时候其实是为静态成员_instance的intMember成员赋值,而此时_instance还是null,必须等待构造函数结束以后_instance才会被赋值为新建StaticClass对象的引用。所以应该把
IntMember = defValue;
改写为
this.intMember = defValue;
就一切正常了。调了很久,实在是很郁闷...
总结如下:首先当然是编程水平问题
:P,对Singleton模式一知半解。另外在构造函数里初始化静态属性也不是可取的做法。第三,之所以调试了很久,是因为Visual
Studio没有明确的定位异常发生的代码段:总是在main函数的"string t =
StaticClass.StrMember;"语句处报异常,非常的misleading,有时间需要研究一下为什么...
为了解决问题我尝试了用更新的版本。但是他还是会抛出同样的问题。
最后我想起了.NET中自带有微软的ORACLE访问借口,于是我就用了SYSTEM.DATA.ORACLECLIENT这个组件,问题得到了解决。
部分代码:(注释的就是调用的ORACLE.DATAACCESS.DLL组件的方法)

protected DataSet GetData()
{ //Oracle.DataAccess.Client.OracleConnection conn = new Oracle.DataAccess.Client.OracleConnection(connstr);
System.Data.OracleClient.OracleConnection conn = new OracleConnection(connstr);
try
{
conn.Open();
//Oracle.DataAccess.Client.OracleCommand com = conn.CreateCommand();
OracleCommand com = conn.CreateCommand();
com.CommandText = "select * from DL_GOVT_NOTICE_INFO";//"select * from DL_GOVT_NOTICE_EXP_HIST";
//Oracle.DataAccess.Client.OracleDataAdapter apter = new Oracle.DataAccess.Client.OracleDataAdapter(com);
OracleDataAdapter apter = new OracleDataAdapter(com);
DataSet ds = new DataSet();
apter.Fill(ds);
apter.Dispose();
conn.Dispose();
return ds;
}
catch (Exception ex)
{
this.LabShowInfo.Text = "Error: " + ex.Message;
conn.Close();
return null;
} }

详细情况我现在也还很糊涂,希望对有出现类似情况的同志有所帮助。
//////////////////
Both Oracle Data Provider for .NET (from Oracle) and .NET Framework Data Provider for Oracle (from Microsoft) require Oracle Client installed on machine.
/////////
the type initializer for '' threw an exception的更多相关文章
- C#中异常:“The type initializer to throw an exception(类型初始值设定项引发异常)”的简单分析与解决方法
对于C#中异常:“The type initializer to throw an exception(类型初始值设定项引发异常)”的简单分析,目前本人分析两种情况,如下: 情况一: 借鉴麒麟.NET ...
- .net core获取数据库连接 抛出The type initializer to throw an exception
原文:https://www.cnblogs.com/pudefu/p/7580722.html 在.NET Framework框架时代我们的应用配置内容一般都是写在Web.config或者App.c ...
- 使用Spire组件抛出异常The type initializer for 'spr857' threw an exception
使用Spire组件抛出异常The type initializer for 'spr857' threw an exception 我使用免费的Spire.Xls组件尝试去转换Excel文档到PDF文 ...
- System.Security.SecurityException The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception
[15/08/19 00:03:10] [DataManager-7292-ERROR] System.Reflection.TargetInvocationException: Exception ...
- System.TypeInitializationException: The type initializer for 'Mono.Unix.Native.Stdlib' threw an exception.
08-31 17:02:03: ### DEBUG ##########################System.TypeInitializationException: The type ini ...
- debian The type initializer for 'System.Drawing.KnownColors' threw an exception
Change the "System.Drawing" reference of "CoreCompat.System.Drawing"if you thro ...
- ASP.Net Core "The type initializer for 'Gdip' threw an exception"
ASP.NET Core项目部署在Linux下可能会出现GDI错误 The type initializer for 'Gdip' threw an exception 解决方案:创建 libdl 的 ...
- The type initializer for System.Data.SqlClient.SqlConnection threw an exception
The type initializer for System.Data.SqlClient.SqlConnection threw an exception net framwork啥原因 xp电脑
- System.TypeInitializationException: The type initializer for 'Oracle.DataAccess.Client.OracleConnection' threw an exception. ---> Oracle.DataAccess.Client.OracleException: 提供程序与此版本的 Oracle 客户机不兼容”
.net应用程序通过Oracle.DataAccess.dll访问64位的Oracle服务器,在连接时出现以下异常:“System.TypeInitializationException: The t ...
随机推荐
- String声明为NULL和""的区别
代码虐我千百遍,我待代码如初恋. String 声明为 NULL 则声明了一个变量不指向任何一块地址,则 length()会出现错误. 声明为"",则是一个长度为0的字符串.
- PHP发送微信模版消息
public function payResult($params) { global $_GPC, $_W; $weid = $this->_weid; $order = pdo_fetch( ...
- nginx配置location [=|~|~*|^~] /uri/ { … }用法
版权声明:https://github.com/wusuopubupt ====== nginx location语法 基本语法:location [=|~|~*|^~] /uri/ { … } = ...
- java中线程池的使用方法
1 引入线程池的原因 由于线程的生命周期中包括创建.就绪.运行.阻塞.销毁阶段,当我们待处理的任务数目较小时,我们可以自己创建几个线程来处理相应的任务,但当有大量的任务时,由于创建.销毁线程需要很大的 ...
- 1988-B. 有序集合
描述 在C++里,有一个神奇的东西,叫做STL,这里提供了很多简单好用的容器,用来实现常用又很难书写的数据结构,如栈(stack)等.其中,有一个容器叫set,译作“有序集合”.首先,这是一个集合,所 ...
- Android ListView相关 fastScrollEnabled
1.android:fastScrollEnabled="true" 当数据量比较多的时候,右侧会出现一个可以拉动的滚动条,这样可以很快的拉动,如图:
- 【BZOJ 2618】 2618: [Cqoi2006]凸多边形 (半平面交)
2618: [Cqoi2006]凸多边形 Description 逆时针给出n个凸多边形的顶点坐标,求它们交的面积.例如n=2时,两个凸多边形如下图: 则相交部分的面积为5.233. Input 第一 ...
- JavaScript 三种创建对象的方法
JavaScript中对象的创建有以下几种方式: (1)使用内置对象 (2)使用JSON符号 (3)自定义对象构造 一.使用内置对象 JavaScript可用的内置对象可分为两种: 1,JavaScr ...
- Java Web开发 之小张老师总结中文乱码解决方案
中文乱码:在以后学习过程中全部采用UTF-8 1.文件的乱码 1.1.项目文本文件默认编码: [右击项目]->[Properties]->[Resource]->[Te ...
- 基于ASP.NET的comet简单实现
http://www.cnblogs.com/hanxianlong/archive/2010/04/27/1722018.html 我潜水很多年,今天忽然出现.很久没写过博客了,不是因为不想写,而是 ...