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 ...
随机推荐
- 阅读Google的C++代码规范有感
李开复曾在微博上说过,Google的C++代码规范是全球最好的一份C++代码规范,没有之一.最近花了点时间看了下这份代码规范,收获确实很大,在编程过程中一些乱七八糟的坏习惯也该改一改了.最新的英文版见 ...
- AMH4.2 虚拟主机面板Tengine版本
本人将原版Nginx更换成淘宝的Tengine 2.1.0 并且更换安装源,以保证面板正常安装 AMH4.2 修改版安装 ———————AMH为独立的一套LNMP/Nginx虚拟主机面板 安装请使用纯 ...
- 让Flash背景透明兼容Firefox、IE 6和IE 7的代码
添加代码: <param name="wmode" value="transparent" > 到 <object>…</obje ...
- [转载]c# winform 获取当前程序运行根目录
// 获取程序的基目录. System.AppDomain.CurrentDomain.BaseDirectory // 获取模块的完整路径. System.Diagnostics.Process.G ...
- jquery mobile validation
<!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content ...
- WPF 视图分组排序
视图分组排序 效果: 实现步骤: 第一步:为分组做一个标题头,就是效果图中的浅蓝色部分: <DataGrid.GroupStyle>标签部分: <DataGrid x:Name=&q ...
- pthread_create()之前的属性设置
一.pthread_create()之前的属性设置1.线程属性设置我们用pthread_create函数创建一个线程,在这个线程中,我们使用默认参数,即将该函数的第二个参数设为NULL.的确,对大多数 ...
- 如何在CHROME里调试前端代码?
以前看前端们调得很神的, 刚看书到这里,作一个记录,演练了一下,确实有点神!!! :) <!DOCTYPE html> <html lang="en"> & ...
- 5.查找最小的k个元素(数组)
题目: 输入n个整数,输出其中最小的k个,例如输入1,2,3,4,5,6,7,8这8个数,则最小的4个是1,2,3,4(输出不要求有序) 解: 利用快速排序的partition,算导上求第k大数的思想 ...
- BZOJ 2806 cheat
首先这个题目显然是要二分转换成判断可行性的 之后我们考虑DP 设f(i)表示 1->i 熟悉的子串的长度的最大值 那么对于i这个点,要么不在熟悉的子串中,要么在熟悉的子串中 所以得到 f(i)= ...