微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c# – System.Security.VerificationException:操作可能会破坏运行时间的稳定. (亚音速2.2)

我最近试图升级一个.net 2.0项目,它的DAL由SubSonic 2.2在Visual Studio 2010下生成到.NET 4.0.

这些项目没有错误地转换,但是当我尝试启动它时,我收到一个相当糟糕的错误消息.

System.Security.VerificationException: Operation Could destabilize the runtime.  

at SubSonic.DataProvider.ApplyConfig(NameValueCollection config,Boolean& parameterValue,String configName) in C:\Documents and Settings\Desktop\4.0 Production\rel_1.0\server\Server.DAL\Server.DAL.SubSonic\DataProviders\DataProvider.cs:line 955
   at SubSonic.DataProvider.Initialize(String name,NameValueCollection config) in C:\Documents and Settings\Desktop\4.0 Production\rel_1.0\server\Server.DAL\Server.DAL.SubSonic\DataProviders\DataProvider.cs:line 916
   at System.Web.Configuration.ProvidersHelper.InstantiateProvider(ProviderSettings providerSettings,Type providerType)

它抛出异常的代码

ApplyConfig(config,ref extractClassNameFromSPName,ConfigurationPropertyName.EXTRACT_CLASS_NAME_FROM_SP_NAME);

    private static void ApplyConfig(System.Collections.Specialized.NameValueCollection config,ref bool parameterValue,string configName)
    {
        if(config[configName] != null)
        {
            parameterValue = Convert.ToBoolean(config[configName]);
        }
    }

它执行类似的调用在这里,唯一的区别是它是一个严格的字符串,而不是一个布尔值,它正在操纵.

private static void ApplyConfig(System.Collections.Specialized.NameValueCollection config,ref string parameterValue,string configName)
{
    if(config[configName] != null)
    {
        parameterValue = config[configName];
    }
}

config被定义为具有3个键的System.Collections.Specialized.NameValueCollection
generateNullableProperties,connectionStringName,generatednamespace
extractClassNameFromSPName == false

EDIT1:启动错误代码在Global.asax的Application_Start()方法

System.Data.sqlClient.sqlDependency.Start(SystemSetting.Schema.Provider.DefaultConnectionString);

EDIT2:这个错误引发了我的web.config中的一个targetinvocation错误

<SubSonicService defaultProvider="appPlan">
    <providers>
        <clear/>
        <add name="appPlan" type="SubSonic.sqlDataProvider,appPlan.Server.DAL.SubSonic" generateNullableProperties="false" connectionStringName="appPlan" generatednamespace="appPlan.Server.DAL"/>
    </providers>
</SubSonicService>

有没有人遇到这样的问题?我可以升级到SubSonic3.x,但这将是一个更大的工作,我相信.

谢谢.

解决方法

这是否解决了这个问题?
private static void ApplyConfig(System.Collections.Specialized.NameValueCollection config,string configName)
{
    if(config[configName] != null)
    {
        string val = config[configName];
        parameterValue = Convert.ToBoolean(val);
    }
}

如果没有,请尝试

string val = config[configName];
if (val.ToLower() == "false")
    parameterValue = false;
else
    parameterValue = true;

原始代码失败可能有2个原因.首先,早期版本的.NET(大概是1.1)有一些类型的问题.我不知道究竟是什么,但我怀疑它可能无法识别直接从NameValueCollection传递到ToBoolean的值的类型.第二种可能性是该值不是“true”或“false”,而是其他的.再次,这2个可能是也可能不是原因.我无法确定,因为我没有SubSonic 2.2.

原文地址:https://www.jb51.cc/csharp/97325.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐