0

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

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

在此处输入图像描述

我有Pos for .Net代码在单独的 AppDomain 中运行(由于 .net 4 的默认安全策略存在问题)。它在我的本地系统上运行良好,无需单击。我的应用程序使用 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 运行它时,它不会完全信任运行......所以现在我试图弄清楚如何让它完全信任。

4

1 回答 1

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
于 2012-09-27T15:23:35.143 回答