当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - Is there any way to configure the initial AppDomain?

问题描述:

I want to make it so my primary AppDomain has ShadowCopyAssemblies set to true.

Is there something I can do (for example perhaps a manifest setting I am missing) that will let the first AppDomain loaded in my executable have have that property set to true or is my only option to create a 2nd AppDomain and have my program do the bulk of it's work in that 2nd domain?

The target environment is a self hosted service, but knowing how to do it for Console or windows applications would be good to know too.

网友答案:

After posting the question I discovered it is a setting you can pass in to the App.config file. What you need to do is set the configuration settings <appDomainManagerType> and <appDomainManagerAssembly> and point it at a 2nd assembly that contains a AppDomainManager.

Config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
    <runtime>
      <appDomainManagerType value="DomainManager.ShadowDomainManager" />
      <appDomainManagerAssembly
         value="DomainManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
    </runtime>
</configuration>

Manager:

using System;

namespace DomainManager
{
    public class ShadowDomainManager : AppDomainManager
    {
        public override void InitializeNewDomain(AppDomainSetup appDomainInfo)
        {
            base.InitializeNewDomain(appDomainInfo); //Currently does not do anything.
            appDomainInfo.ShadowCopyFiles = "true";
        }
    }
}

Doing this will cause the initial domain to load with ShadowCopyFiles set to true.

分享给朋友:
您可能感兴趣的文章:
随机阅读: