WPF ClickOnce完全信任问题(与单独的AppDomain相关?)

时间:2012-09-26 21:03:18

标签: wpf clickonce appdomain full-trust

我正在为我的应用程序创建clickonce安装。

如果项目属性,我在“安全”选项卡中启用了完全信任的ClickOnce安全设置。我发布到网络驱动器并运行安装。安装成功但是当我运行应用程序时出现此错误:

enter image description here

我在单独的AppDomain中运行Pos for .Net代码(由于它与.net 4的默认安全策略有关)。它在我的本地系统上运行正常,没有clickonce。我的应用程序使用Prism,因此我必须修改清单以包含动态加载的模块。它以某种方式与我的AppDomain相关,我没有完全信任。

这就是我创建AppDomain的方式

AppDomainSetup currentAppDomainSetup = AppDomain.CurrentDomain.SetupInformation;
AppDomainSetup newAppDomainSetup = new AppDomainSetup()
{
    ApplicationBase = currentAppDomainSetup.ApplicationBase,
    LoaderOptimization = currentAppDomainSetup.LoaderOptimization,
    ConfigurationFile = currentAppDomainSetup.ConfigurationFile,
    PrivateBinPath = @"Modules"  // need to set this so that the new AppDomain can see the prism modules
};
newAppDomainSetup.SetCompatibilitySwitches(new[] { "NetFx40_LegacySecurityPolicy" }); // required for POS for .Net to function properly
_posAppDomain = AppDomain.CreateDomain("POS Hardware AppDomain", null, newAppDomainSetup);
// Error happens on the following line. Note that type T is always in same assembly that AppDomain was created in.
    T hardware = (T)PosAppDomain.CreateInstanceFromAndUnwrap(Assembly.GetAssembly(typeof(T)).Location, typeof(T).FullName);

我是否缺少安全设置?

我想我越来越近了。我运行的AppDomain在没有clickonce的情况下运行时完全信任,但是当我使用clickonce运行它时,它不能完全信任地运行....所以现在我想弄清楚如何完全信任它。

1 个答案:

答案 0 :(得分:1)

想出来

我必须添加EvidencePermissionSet ...

Evidence evidence = new Evidence();
evidence.AddHostEvidence(new Zone(SecurityZone.MyComputer));
PermissionSet ps = SecurityManager.GetStandardSandbox(evidence);
AppDomainSetup currentAppDomainSetup = AppDomain.CurrentDomain.SetupInformation;
AppDomainSetup newAppDomainSetup = new AppDomainSetup()
{
    ApplicationBase = currentAppDomainSetup.ApplicationBase,
    LoaderOptimization = currentAppDomainSetup.LoaderOptimization,
    ConfigurationFile = currentAppDomainSetup.ConfigurationFile,
    PrivateBinPath = @"Modules"  // need to set this so that the new AppDomain can see the prism modules
};
newAppDomainSetup.SetCompatibilitySwitches(new[] { "NetFx40_LegacySecurityPolicy" }); // required for POS for .Net to function properly