操作可能会破坏运行时稳定性的解决办法

如果你用了ANTS Performance Profiler的话,并且选择了“Line-Level”就有可能出现下面问题了:

System.Security.VerificationException: 操作可能会破坏运行时稳定性。

老外的解决方法:http://stackoverflow.com/questions/378895/operation-could-destabilize-the-runtime
This happens regularily to me when using ANTS Performance Profiler with projects that make use of HtmlAgilityPack. The solution to this was to tell the profiler to exclude HtmlAgilityPack by adding <assemblyName>HtmlAgilityPack</assemblyName> to the file "C:UsersYourUserNameAppDataLocalRed GateANTS Performance Profiler 9LineLevelBlacklist.xml" (Replace "YourUserName" by your actual user name).

我试了,貌似没有用,我还是直接在软件里面修改分析配置的模式,不选Line-Level和With Source的。

错误提示:
操作可能会破坏运行时稳定性。 
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 

异常详细信息: System.Security.VerificationException: 操作可能会破坏运行时稳定性。

源错误: 

执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。  

原因:
framework平台信任级别被主机商修改了(国外主机普通都会修改),导致信任级别过低。

解决方法1:
找到framework配置文件路径:C:WINDOWSMicrosoft.NETFrameworkv2.0.50727CONFIGweb.config (注意不同版本红色部分目录可能不一样,如果购买虚拟主机,请联系主机商修改)
用计事本打开文件找到下面这段
   <location allowOverride="true">
        <system.web>
            <securityPolicy>
                <trustLevel name="Full" policyFile="internal"/>
                <trustLevel name="High" policyFile="web_hightrust.config"/>
                <trustLevel name="Medium" policyFile="web_mediumtrust.config"/>
                <trustLevel name="Low" policyFile="web_lowtrust.config"/>
                <trustLevel name="Minimal" policyFile="web_minimaltrust.config"/>
            </securityPolicy>
      <trust level="Full" originUrl=""/>
            <identity impersonate="true"/>
        </system.web>
    </location>
红色trust部分的level默认是为full,有的主机商吧这里设置为Medium或其他,会提示不受信任的错误,改回Full即可。

解决方法2:
可以把上面蓝色部分的allowOverride改为true(表示允许用户自定义trust级别)

然后在pageadmin自带的web.config文件的</system.web>上面一行加上<trust level="Full" originUrl=""/>

改好的web.congfig如下
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    ....中间部分省略
    <trust level="Full" originUrl=""/>
  </system.web>
</configuration>

通过以上修改后就可以正确的运行Pageadmin系统。

原文地址:https://www.cnblogs.com/zjoch/p/6219113.html