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

发布于 2024-10-20 09:16:05 字数 2444 浏览 2 评论 0原文

我最近尝试在 Visual Studio 2010 下将由 SubSonic 2.2 生成的 DAL 生成的 .net 2.0 项目升级到 .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、连接字符串名称、生成的命名空间 extractClassNameFromSPName == false

EDIT1: 引发错误的代码位于 Global.asax 的 Application_Start() 方法中

System.Data.SqlClient.SqlDependency.Start(SystemSetting.Schema.Provider.DefaultConnectionString);

EDIT2: 错误会冒出并引发目标调用错误参考我的 web.config

<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,但我相信这将是一项更大的任务。

谢谢。

I recently tried to upgrade a .net 2.0 project which had its DAL generated by SubSonic 2.2 to .NET 4.0 under Visual Studio 2010.

The projects converted without error but now I am getting a rather vile error message when I try to launch it.

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)

The code where it is throwing the exception:

    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]);
        }
    }

It performs similar calls to here, the only difference being it is strictly a string and not a boolean it is manipulating.

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

config is defined as a System.Collections.Specialized.NameValueCollection with 3 keys
generateNullableProperties, connectionStringName, generatedNamespace
extractClassNameFromSPName == false

EDIT1: The code that kicks off the error is in the Application_Start() method of the Global.asax

System.Data.SqlClient.SqlDependency.Start(SystemSetting.Schema.Provider.DefaultConnectionString);

EDIT2: The error bubbles out to thowing a targetinvocation error referening my web.config

<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>

has anybody else ever run across such an issue? I could upgrade to SubSonic3.x but it would be a much greater undertaking I believe.

thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

美人骨 2024-10-27 09:16:05

我之前在直接从手工制作的 IL 生成程序集时见过此异常。 .NET 运行时验证程序集中的原始指令的正确性,尤其是在将程序集加载到受限上下文中时。例如,在执行方法之前进行检查以确保将所需数量的参数加载到调用堆栈中。

即使验证失败,程序集仍然可以加载;但它只能在完全信任的情况下运行。在部分信任的情况下,您会收到此“操作可能会破坏运行时的稳定性”错误。原因是,如果程序集“行为不正确”,则运行时无法保证部分信任的程序集的安全操作。

您可以使用 PEVERIFY 工具(可通过 Visual Studio 命令提示符获取)手动检查程序集。尝试验证所有引用的程序集以查看报告的内容。我怀疑 .NET 2.0 和 .NET 4.0 之间的验证规则发生了变化,导致 SubSonic 2.2 程序集之一的验证失败。

您在 Fun Mun Pieng 的回复中提到的作弊行为也表明验证是问题所在。

I have seen this exception before when generating assemblies directly from hand-crafted IL. The .NET runtime verifies the raw instructions in an assembly for correctness, especially when loading the assembly into restricted contexts. For example, there is a check to ensure that the required number of arguments are loaded onto the call-stack before executing a method.

An assembly can still be loaded even if verification fails; but it can only be run in full trust. In partial trust scenarios you get this "operation could destabilize the runtime" error. The reason being that the runtime cannot guarantee safe operation of assemblies in partial trust if they do not "behave correctly".

You can manually check an assembly using the PEVERIFY tool (available via a Visual Studio Command Prompt). Try verifying all of the referenced assemblies to see what is reported. I suspect there was a change in the verification rules between .NET 2.0 and .NET 4.0 that is now causing verification to fail for one of the SubSonic 2.2 assemblies.

Your cheat you mention in response to Fun Mun Pieng also suggests verification is the issue.

篱下浅笙歌 2024-10-27 09:16:05

这能解决问题吗?

private static void ApplyConfig(System.Collections.Specialized.NameValueCollection config, ref bool parameterValue, 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 的值的类型。第二种可能性是该值不是“真”或“假”,而是其他值。同样,这两个可能是也可能不是原因。我不能确定,因为我没有 SubSonic 2.2。

Does this fix the problem?

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

If not, then try

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

There may be 2 reasons why the original code fails. First, earlier version of .NET (probably 1.1) had some type issue. I don't know what exactly, but I suspect it might have failed to identify the type of the value passed straight from the NameValueCollection into ToBoolean. The second possibility is that the value is not "true" or "false", but something else. Again, these 2 may or may not be the reason. I can't know for sure because I don't have SubSonic 2.2.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文