GenerateResource”任务意外失败的解决方法
错误描述:
System.InvalidOperationException: 配置有 NoSecurityChanges 标志的 AppDomainManager 修改了 AppDomain 的安全状态。
在 System.AppDomain.SetupDomainSecurity(AppDomainHandle appDomain, ObjectHandleOnStack appDomainEvidence, IntPtr creatorsSecurityDescriptor, Boolean publishAppDomain)
在 System.AppDomain.InitializeDomainSecurity(Evidence providedSecurityInfo, Evidence creatorsSecurityInfo, Boolean generateDefaultEvidence, IntPtr parentSecurityDescriptor, Boolean publishAppDomain)
在 System.AppDomain.Setup(Object arg)
在 System.AppDomain.nCreateDomain(String friendlyName, AppDomainSetup setup, Evidence providedSecurityInfo, Evidence creatorsSecurityInfo, IntPtr parentSecurityDescriptor)
在 System.AppDomainManager.CreateDomainHelper(String friendlyName, Evidence securityInfo, AppDomainSetup appDomainInfo)
在 System.AppDomainManager.CreateDomain(String friendlyName, Evidence securityInfo, AppDomainSetup appDomainInfo)
在 System.AppDomain.InternalCreateDomain(String friendlyName, Evidence securityInfo, AppDomainSetup info)
在 System.AppDomain.CreateDomain(String friendlyName, Evidence securityInfo, AppDomainSetup info)
在 Microsoft.Build.Tasks.GenerateResource.Execute()
在 Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
在 Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask, Boolean& taskResult) Genersoft.Platform.Task.UI
问题描述:
原因是.NET Framework 4 版已经弃用代码访问安全(CAS)策略。因此,如果显式或隐式(通过其他类型和成员)调用过时的策略类型和成员,则可能遇到编译警告和运行时异常。
参见MSDN:代码访问安全策略兼容性和迁移 http://msdn.microsoft.com/zh-cn/library/ee191568(VS.100).aspx 解决方法: if you have "The "ResolveComReference" task could not be instantiated from "Microsoft.Build.Tasks.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". this error , most probably you've modified devenv.exe.config and added there <NetFx40_LegacySecurityPolicy enabled="true"/> , am I right?
If this is the case, do this: 1) remove <NetFx40_LegacySecurityPolicy enabled="true"/> from devenv.exe.config 2) re-open VS, compile your project. It will generate you all interops with no problems. 3) close VS, add <NetFx40_LegacySecurityPolicy enabled="true"/> again if you need it. 4) open VS, open your project. Your references will be fine now. |