EnterpriseLibrary导致的“类型初始值设定项引发异常”,高分!

cellblue 2008-10-15 10:27:38
“Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.EnterpriseLibraryFactory”的类型初始值设定项引发异常。

我引入了微软的EnterpriseLibrary,以前还是正常的,可是现在出现了问题,据我测试体验,一个可以使用的解决方案,从VSS中脱离开之后就不能用了。不清楚为什么。

估计原因是里头的引用出了问题,但是不清楚如何排除。



...全文
942 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
jiangnii 2009-09-15
  • 打赏
  • 举报
回复
我也遇到了同样的问题。。郁闷。。
cellblue 2008-10-29
  • 打赏
  • 举报
回复
不好意思,最近都在全国跑,有一个dll从原先的60KB,变成69KB

wangyanboq 2008-10-15
  • 打赏
  • 举报
回复
突然想起我以前也遇到过这种问题,举例说明
public class ClassA
{
private static string connectionString = System.Config..........

public static bool Method()
{
}
}

如果第一次调用ClassA.Method(),可能会出现“类型初始值设定项引发异常”

原因如下:

第一次调用ClassA.Method()的时候,会初始化ClassA.connectionString。如果在初始化的过程中出现异常,就会抛出“类型初始值设定项引发异常”

检查一下你出现异常所指向的类里面的静态变量
cellblue 2008-10-15
  • 打赏
  • 举报
回复
我把VSS源码管理取消了,每个项目都重新做了引用,可是还是不行

zlkingdom 2008-10-15
  • 打赏
  • 举报
回复
那说明你项目有部分的DLL文件的引用一直是由VSS在管理的,你重新引用一下,然后再跑程序
playzxw 2008-10-15
  • 打赏
  • 举报
回复
是不是版本问题。
wangyanboq 2008-10-15
  • 打赏
  • 举报
回复
把引用再重新一个个引用一遍
tinalucky 2008-10-15
  • 打赏
  • 举报
回复
个人认为,你签入到VSS了,再从VSS下载下来,也有可能带来问题的
cnming 2008-10-15
  • 打赏
  • 举报
回复
做签名了没有?如果有的话,重新编译这个DLL试试看

从网络上查,有如下的文章,看起来如果能够加入log的话,或许能帮你找出问题。

另外,我个人认为,你签入到VSS了,再从VSS下载下来,也有可能带来问题的,例如字节的变化,如果外加签名,直接就不允许你调用这个DLL。



EnterpriseLibraryJune2005 的问题
EnterpriseLibraryJune2005.exe 成功安装后,但在其它项目引用后,出现错误,信息如下:
“Microsoft.Practices.EnterpriseLibrary.Data.Instrumentation.DataCommandFailedEvent”的类型初始值设定项引发异常,请各位高手提点意见
.
-----------------------------------------------------------------------------------------------------------------------------

有趣的问题,刚查了查,两解决办法:
一是打安装服务补丁,于如下地址下载补丁:
http://www.softitechture.com/discussions/index.html#InstallServices

二是修改注册表HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\Application 下的RestrictGuestAccess值由1改为0,然后重启。
----------------------------------------------------------------------------

I was able to resolve this by following Craig's advice regarding the registry
setting for guest access to the event log:

In HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\Application
there is a DWORD value called RestrictGuestAccess, change from 1 to 0, then REBOOT.

Also, I ran the InstallServices batch file in the \bin directory of my ASP.NET app. You can download a copy of the batch file that doesn't look for Visual Studio on your server machine here:

http://www.softitechture.com/discussions/index.html#InstallServices

Also, if you read the FAQ you can recompile to disable instrumentation:

"Open up the EnterpriseLibrary.sln and modify the Configuration Properties\Build\Conditional Constants of the EnterpriseLibrary.Common project. Remove the USEWMI;USEEVENTLOG;USEPERFORMANCECOUNTER constants. By removing these constants, all of the internal Enterprise Library instrumentation will be disabled. Recompile."

----------------------------------------------------------------------------
Drew - did you run the Install Services script or installutil over the EntLib assemblies? Also WMI is very particular about where the assemblies are located, so you'll need to run the script over the exact assemblies that your app is loading.


The stuff in InstallServices.bat that points to VS2003 is basically there to find

the location of installutil.exe. However installutil can also be found in other locations, such as C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322.



On a production machine without VS2003, rather than run InstallServices.bat it is probably safer to run Installutil.exe directly over the EntLib assemblies, eg:

installutil Microsoft.Practices.EnterpriseLibrary.Common.dll
installutil Microsoft.Practices.EnterpriseLibrary.Configuration.dll

... and so on over whatever assemblies your application is using.
---------------------------------------------------------------------------------------------------------------------------
上面还提到,如果打补丁后出现
"Open up the EnterpriseLibrary.sln and modify the Configuration Properties\Build\Conditional Constants of the EnterpriseLibrary.Common project. Remove the USEWMI;USEEVENTLOG;USEPERFORMANCECOUNTER constants. By removing these constants, all of the internal Enterprise Library instrumentation will be disabled. Recompile."
错误,重新编译一下即可。



wangyanboq 2008-10-15
  • 打赏
  • 举报
回复
如果是在调用ClassA.Method()的时候出错,那么就去ClassA类里面找ClassA其他的初始化项

而不是在调用ClassA.Method()的类里面找初始化项
cellblue 2008-10-15
  • 打赏
  • 举报
回复
绑定回去也不能用了,因此才急于找问题
TLJewel 2008-10-15
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 adrianEvin 的回复:]
怎么从VSS中脱离,  删除VSS文件  还是把代码拷出来  脱离
[/Quote]
我用的是vs2005,你可以再源代码里设置,将绑定取消就可以了
adrianEvin 2008-10-15
  • 打赏
  • 举报
回复
怎么从VSS中脱离, 删除VSS文件 还是把代码拷出来 脱离
cellblue 2008-10-15
  • 打赏
  • 举报
回复
没有发现会有什么问题,string mTmp = System.Configuration.ConfigurationSettings.AppSettings["OrganizeGUID"].ToString();照常取出来,没有异常

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧