加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – System.Security.VerificationException:操作可能会破坏

发布时间:2020-12-15 18:02:12 所属栏目:百科 来源:网络整理
导读:我最近试图升级一个.net 2.0项目,它的DAL由SubSonic 2.2在Visual Studio 2010下生成到.NET 4.0. 这些项目没有错误地转换,但是当我尝试启动它时,我收到一个相当糟糕的错误消息. System.Security.VerificationException: Operation could destabilize the runt
我最近试图升级一个.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 SettingsDesktop4.0 Productionrel_1.0serverServer.DALServer.DAL.SubSonicDataProvidersDataProvider.cs:line 955
   at SubSonic.DataProvider.Initialize(String name,NameValueCollection config) in C:Documents and SettingsDesktop4.0 Productionrel_1.0serverServer.DALServer.DAL.SubSonicDataProvidersDataProvider.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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读