本日、アプリケーションを.NETFramework4.0にアップグレードしました。ネットワーク共有上にあるアセンブリを呼び出すため、以前のバージョンでは次のコマンドが必要でした。
caspol.exe -m -chggroup 1.3 -zone "Intranet" FullTrust
.NET 4の場合、「NetFx40_LegacySecurityPolicy」について読み、App.configファイルに含めました。
<runtime>
<NetFx40_LegacySecurityPolicy enabled="true"/>
<loadFromRemoteSources enabled="true"/>
</runtime>
残念ながら、これは機能しません。アプリケーションが起動するとすぐに、環境変数にアクセスできないことを示す例外が発生します(System.Security.Permissions.EnvironmentPermissionがありません)。
CasPol.exeを試してみましたが、アプリケーションが環境変数にアクセスできるようにするために何をしなければならないかを理解できませんでした。Environment.GetEnvironmentVariable呼び出しを削除しても、問題は解決しません。他の多くの操作も機能しないようです。
NetFx40_LegacySecurityPolicyスイッチを削除する(またはfalseに設定する)と、環境を再度読み取ることができますが、(もちろん)ネットワーク共有でのアセンブリの実行が妨げられます。
完全なApp.configファイルは次のとおりです。
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="Launcher.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
</sectionGroup>
</configSections>
<applicationSettings>
<Launcher.Properties.Settings>
<setting name="Executable" serializeAs="String">
<value>\\office\client\client-8919\Client.exe</value>
</setting>
</Launcher.Properties.Settings>
</applicationSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
<runtime>
<NetFx40_LegacySecurityPolicy enabled="true"/>
<loadFromRemoteSources enabled="true"/>
</runtime>
</configuration>
編集:
これは、ネットワーク共有にあるアセンブリを起動するために使用するコードです。
public void ExecuteFile(string version, string[] args)
{
try
{
String appPath = GetExecutablePath();
if (!Directory.Exists(appPath))
throw new Exception("cache does not contain expected executable directory: " + appPath);
String executable = appPath + "\\Client.exe";
if (!File.Exists(executable))
throw new Exception("cache does not contain expected executable: " + executable);
if (Program.DEBUG_MODE)
MessageBox.Show("App Path: " + appPath + "\r\nExecutable: " + executable);
AppDomainSetup domainInfo = new AppDomainSetup();
domainInfo.ApplicationBase = appPath;
AppDomain subDomain = AppDomain.CreateDomain("Name", AppDomain.CurrentDomain.Evidence, domainInfo);
subDomain.ExecuteAssembly(executable, subDomain.Evidence, args);
}
catch (Exception e)
{
MessageBox.Show("Fehler beim Ausführen der Version im lokalen Cache!\r\n" + e.Message);
}
}