1

本日、アプリケーションを.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);
        }
    }
4

1 に答える 1

2

正確には「良い」答えではありません、申し訳ありません。しかしnull、証拠としてCreateDomain呼び出しに渡し、パラメーターExecuteAssemblyを必要としないオーバーロードを使用することに成功しました。evidence渡す証拠の値を考えると、結果は同じになるはずです。

于 2012-08-21T06:57:57.420 に答える