2011-05-17 44 views
3

我试图使用起来需要设置传统的安全政策支持老.NET代码:使用传统的安全策略和动态操作一起在.NET 4

<NetFx40_LegacySecurityPolicy enabled="true" /> 

,并托管IronPython的(也许在某些地方使用dynamic关键字)。

我找不到同时使用它们的方法。如果我添加上述选项的app.config文件,我得到

动态操作只能 在同质的AppDomain执行的例外。

如果我不加这个选项,我得到

这种方法明确地使用CAS策略,已废弃由.NET Framework。为了兼容性原因启用CAS策略,请使用NetFx40_LegacySecurityPolicy配置开关。有关更多信息,请参阅http://go.microsoft.com/fwlink/?LinkID=155570

有没有办法解决这个问题?

+0

我被困在同一块岩石和坚硬的地方......你找到了解决方案吗? ta – 2011-07-22 12:56:07

+0

不,我没有,目前我正在使用传统安全策略并避免使用任何动态操作。我们计划在将来放弃需要此政策的图书馆... – vigoo 2011-07-27 15:50:06

+0

有没有人有此修复? – caa 2014-08-15 11:31:34

回答

0

值得一提的是,不要设置LegacySerurityPolicy,并尝试为您的APP提供应用程序清单,而不是类似于以下内容。

<?xml version="1.0" encoding="utf-8"?> 
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <assemblyIdentity version="1.0.0.0" name="MyApplication.app" /> 
    <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2"> 
    <security> 
     <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3"> 
     <!-- UAC Manifest Options 
      If you want to change the Windows User Account Control level replace the 
      requestedExecutionLevel node with one of the following. 

     <requestedExecutionLevel level="asInvoker" uiAccess="false" /> 
     <requestedExecutionLevel level="requireAdministrator" uiAccess="false" /> 
     <requestedExecutionLevel level="highestAvailable" uiAccess="false" /> 

      Specifying requestedExecutionLevel node will disable file and registry virtualization. 
      If you want to utilize File and Registry Virtualization for backward 
      compatibility then delete the requestedExecutionLevel node. 
     --> 
     <requestedExecutionLevel level="asInvoker" uiAccess="false" /> 
     </requestedPrivileges> 
     <applicationRequestMinimum> 
     <PermissionSet class="System.Security.PermissionSet" version="1" Unrestricted="true" ID="Custom" SameSite="site" /> 
     <defaultAssemblyRequest permissionSetReference="Custom" /> 
     </applicationRequestMinimum> 
    </security> 
    </trustInfo> 
    <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"> 
    <application> 
     <!-- A list of all Windows versions that this application is designed to work with. Windows will automatically select the most compatible environment.--> 
     <!-- If your application is designed to work with Windows 7, uncomment the following supportedOS node--> 
     <!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>--> 
    </application> 
    </compatibility> 
    <!-- Enable themes for Windows common controls and dialogs (Windows XP and later) --> 
    <!-- <dependency> 
    <dependentAssembly> 
     <assemblyIdentity 
      type="win32" 
      name="Microsoft.Windows.Common-Controls" 
      version="6.0.0.0" 
      processorArchitecture="*" 
      publicKeyToken="6595b64144ccf1df" 
      language="*" 
     /> 
    </dependentAssembly> 
    </dependency>--> 
</asmv1:assembly>