Assigning app.config to AppDomain RRS feed

  • Question

  • Hi,

    Suppose that I have created a new AppDomain, and I override all assembly loading on that AppDomain by means of subscribing to AssemblyResolve event and handling retrieval of those assemblies manually. However, loading assemblies is not enough in my example, I also need to be able to override configuration management for that AppDomain.

    I know there is a ConfigurationFile property in AppDomainSetup class that I can pass when creating an AppDomain, but it only accepts a physical file path. Instead I would like to override that and feed it a stream.

    I am building an application that needs to be completely decoupled from file system. My runtime environment will not have access to it's file system at all. All I have is a database and memory access.

    Thank you

    Friday, September 2, 2011 9:32 PM


  • Rodion,

    There is a SetConfigurationBytes method that is part of the AppDomainSetup class that will do exactly what you want.  It will override any configuration information for that AppDomain and isn't dependent on the file system.

    The documentation for it is at:


    Below is an example of how I would see it working: 

    AppDomainSetup ads = new AppDomainSetup();
    ads.SetConfigurationBytes( Encoding.UTF8.GetBytes(
          <remove invariant="System.Data.SqlServerCe.3.5"></remove>
    </configuration>" ) ); 


    Tom Overton

    • Edited by Tom_Overton Sunday, September 4, 2011 9:51 AM
    • Proposed as answer by Paul Zhou Tuesday, September 6, 2011 7:32 AM
    • Marked as answer by Rodion Pronin Tuesday, September 6, 2011 1:30 PM
    Sunday, September 4, 2011 9:50 AM