Welcome to MSDN Blogs Sign in | Join | Help

App.Config Files

By default, the application configuration file of the default appdomain (and other appdomains for v1.1 and later) is in the process exe’s directory and named the same as the process exe + ".config". This is true even if that exe is unmanaged. Also, note that a web.config file is an app.config - ASP.NET sets that as the config file for your appdomain.

To change the config file, set an AppDomainSetup.ConfigurationFile to the new location and pass that AppDomainSetup to your call to AppDomain.CreateDomain(). Then, run all of the code requiring that application config from within that new appdomain.

Note, though, that you won’t be able to choose the CLR version by setting the ConfigurationFile – at that point, a CLR will already be running, and there can only be one per process.

Application configuration files are per-appdomain. So, you can set a ‘dll config’ by using the method above, but that means that it will be used for the entire appdomain, and it only gets one.

Check here for info about the contents of configuration files or here for common examples.

Published Monday, June 02, 2003 6:50 PM by Suzanne Cook
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# RE: App.Config Files

Suzanne, Apparently, the contents of a configuration file are cached, so that any changes made to the file are not available until you unload the domain. Is there any mechanism to force the domain to reload the configuration?
Monday, June 02, 2003 8:50 PM by Fernando Tubio

# RE: App.Config Files

Not for AppDomain configuration purposes, at least. You'd have to create a new AppDomain for it to be reloaded. That's best for the loader's purposes, anyway.
Tuesday, June 03, 2003 6:08 PM by Suzanne

# RE: App.Config Files

If config files are per-appdomain; does this then mean that placing a web.config file in a web site sub-directory to do something such as alternative permissions for said folder; cause the runtime to provision a new app domain for each of the folders. If so is this done for all sub folders period or for just those with a separate web.config?
Saturday, June 21, 2003 12:56 PM by M. Keith Warren

# RE: App.Config Files

The CLR wouldn't automatically create a new AppDomain; it would be up to the host to create it (ASP.NET). I believe that ASP.NET creates a new AppDomain per 'app' and uses a web.config if it's there in the app root - I don't think it creates AppDomains based on the location of web.configs.
Monday, June 23, 2003 2:19 PM by Suzanne

# RE: App.Config Files

suzanne i want to ask you a question about the GAC but how can i do that, there is nowhere a link to a email adres. the question : I made my own dll and put it in the GAC the DLL contains a class called : Task this is the source i use : <%@ Import Namespace="Mpp.Wsis.Mod_sys.Task" %> <script language="VB" runat="server"> Sub Page_Load(Sender As Object, E As EventArgs) 'author = "mve,0206032108" dim task1 as Mpp.Wsis.Mod_sys.Task = new Mpp.Wsis.Mod_sys.Task(2) response.write(task1.getRelID) response.write("<br>") response.write(task1.getTaskMemo) end sub </script> the error a get is : BC30002: Type 'Mpp.Wsis.Mod_sys.Task' is not defined. can you help me, or do you know someone how can? there is so less about real asp.dotnet on internet when i put a assembly tag in my page and place the dll in de bin dir it works, but don't use the GAC and a want to use the GAC i hope to hear from you. i think you know a lot, when i read your info
Sunday, July 06, 2003 11:30 AM by Michael van Engelenburg

# RE: App.Config Files

Yes, no email because I work on developing the product, not really technical support. You can use Microsoft's official tech support channels, though, or the MS newsgroups can also help. Assemblies retrieved from the GAC require a full assembly display name for the reference (see my blog entry at http://blogs.msdn.com/suzcook/archive/2003/05/29/57137.aspx ). Check the <add assembly> tags in your machine.config file. If it doesn't have an entry for it, add the appropriate one(<add assembly="*" /> works for bin assemblies, but not GAC ones).
Wednesday, July 09, 2003 3:33 PM by Suzanne

# RE: App.Config Files

thank you for your support. Off Course i'll checked the support pages first, but after 3 hour, microsoft is no longer a friend :-) solution helped!!. Other question i can not find in the support shit. I made a dll placed it in the gac and want to run, but because the gac is outside the iis enviroment, i can not use a response.write() command in the dll, is there a solution , or is it possible to add an other namespace to make it possible thanks in advanced
Friday, September 05, 2003 3:37 PM by michael van Engelenburg

# RE: App.Config Files

Did you add the appropriate <add assembly> tag to the machine.config for the CLR loaded in the process? It sounds like it wasn't added. If yes, check the Fusion log ( http://blogs.gotdotnet.com/suzcook/PermaLink.aspx/f9f7be1e-ef53-453c-af11-1ad81536edeb ) to see if there was some other loading problem.
Monday, September 15, 2003 3:39 PM by Suzanne

# LoadFrom's Second Bind

Friday, April 30, 2004 3:10 PM by Suzanne Cook's .NET CLR Loader Notes

# App.config Examples

Friday, May 14, 2004 12:37 PM by Suzanne Cook's .NET CLR Loader Notes

# .NET app.config Files

Friday, May 14, 2004 6:23 PM by Mark Treadwell

# May come in handy

Monday, May 24, 2004 11:16 AM by Thea Burger's Blog

# re: App.Config Files

I have a Web Service with web.config, can I treat that as my App.config
Tuesday, May 25, 2004 8:31 PM by GG

# re: App.Config Files

I create a new project and am unable to find the app.config file in the solution tree? Any pointers?

Thanks,
Matt
Friday, May 28, 2004 8:57 AM by woodm@prpa.org

# re: App.Config Files

GG: Yes, ASP.NET automatically sets the app's web.config as that appdomain's app.config.

woodm: VS doesn't automatically create an app.config for you today.
Wednesday, June 02, 2004 2:37 PM by Suzanne

# re: App.Config Files

I have a .NET DLL I need to access from an asp app. So I have wrapperd my DLL for COM interop how ever I can't get it to take a config file.

Could you paste a quick example of how you would repoint an application/dll at a new config file.

Tuesday, June 08, 2004 2:01 PM by Benjamin C. J. Casha

# re: App.Config Files

Benjamin, please read the original blog entry - it answers this exact question, with the methods to call.
Tuesday, June 08, 2004 2:04 PM by Suzanne

# re: App.Config Files

pls tell about config file
Wednesday, July 07, 2004 3:42 AM by saravanakumar.a@kshema.com

# re: App.Config Files

Hello I would like use a file: app.config for define a new attribut for my dll.
my app.config is used for taking another class for compressed the data beetween the client and the issuer.

When I compile it, the config file isn't use.
how do that??

thanks
seb
Thursday, July 08, 2004 7:18 AM by seb

# re: App.Config Files

<!-- Web.Config Configuration File -->

<configuration>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>
Friday, July 16, 2004 8:31 PM by Michele Nelson

# re: App.Config Files

We are having a problem where a no-touch depolyment windows form isn't loading its app.config file. It works in all cases, except when the client has IE configured to use a proxy server. We get no errors, just the application settings collection is empty (which means our dynamic webservices fail and the application is non-functional). Any clue on this odd problem?
Wednesday, April 06, 2005 7:28 PM by KrisK

# re: App.Config Files

Is there a way to specify a substitution variable that can be used in several places in the app.config file (like you can do in Ant/NAnt build files)? For example, if there is part of a file path that I specify in several of the appSettings key values, can I somehow specify that path once, and just insert a substitution variable of some sort (e.g., "${path}") and have it get substituted at run-time? I could just separate them into different keys and handle it in code, but this path is being set on a key in a custom configuration section for a third-party component (log4net), so this is not possible. Also, I tried to do this using XML Entities to no avail. Please advise.
Wednesday, June 29, 2005 6:13 PM by EJ

# re: App.Config Files

i can not add applicaion configurtion file in my windows application,it is not visible in add items.
Monday, November 14, 2005 2:09 AM by sandy

# App.Config File Culture Tag

Hi Suzanne,
I'm a newbie developer in .net and I'm having a little trouble to set the culture info into the app.config file.
I find out here (http://msdn2.microsoft.com/en-us/library/hy4kkhe0.aspx#)
that what I thought would be the solution, but unfortunatelly, don't was.
I think that <system.web> tag works just in web app, and not in desktop app, am I right ???
There is a way to set culture info in the app.config file ? Which tag I shall to use.
Best Regards,
Juliano.
Thursday, November 24, 2005 2:17 PM by Juliano

# SetConfigurationBytes

Hi Suzanne;

As long as we're on the topic of setting up configuration via an AppDomainSetup object, do you have any insight into using the SetConfigurationBytes method?  I'm trying to use this method to supply app domain configuration from a custom host, but am having no success.  The configuration data I supply isn't accessed by the Configuration subsystem (e.g., application settings are not available), even though I can see my configuration from the new app domain when I call AppDomainSetup.GetConfigurationBytes.  

Obliged,

Jimbo

Monday, November 06, 2006 8:54 PM by Beefarino

# re: App.Config Files

Hi

I rewrite the appsettings section of app.config file on application load. How do I reload (re-cache) the app.config file with .NET 1.1. I know that .Net 2.0 provides the API to do it. Is there a work around with .NET 1.1.

Monday, December 18, 2006 2:38 AM by Vineesh Degapudi

# re: App.Config Files

Thank you for this blog!  It is a big help.  What happens to a dll's config file when it gets put in the GAC?  Is the configurations at the time of the GAC install retained?

Thank you, Brett

Wednesday, January 17, 2007 6:51 PM by Brett

# re: App.Config Files

If you are using .NET 2.0 settings class, it sets some default values that are compiled with the dll, so when the dll is in the GAC, it can't find the config file and use the defaults (I guess).

Is there any way to specify the config file to use for a shared assembly in GAC? How?

Tuesday, May 29, 2007 4:38 AM by Ed

# re: App.Config Files

Hi,

I have created an App.config file for my Workflow.When builded it gives me a file name as Workflow.dll.config.

I need to add this App.config in the GAC so that when the Workflow DLL is in GAC it looks at the appropriate App.config in GAC too.

Problem is that App.config is not getting added to the GAC.

any solutions?

Regards,

Shash

Wednesday, June 27, 2007 5:00 AM by Shash

# re: App.Config Files

Hi,

I got an issue. I am using .net dll's (as com interop) in asp pages. app.config file works but when I add enterprise libaray logging feature in it, it stops working.

I know how to get it works in desktop environment (by rename app.config to program.exe.config) but for website i dont know how it should be renamed or how it will work with enterprise libaray.

Any help?

email me at Kamranshehzad@networkplaces.co.uk

thank you.

Friday, July 13, 2007 7:25 AM by Kamran Shehzad

# App.Config Files in debug time

Hi,

I am a newbie in c# development and I have a problem with app.config files in debug time. My app.config file works right in runtime but not in debug time. Can they be used in debug time ?

My app.config file is :

<?xml version ="1.0"?>

<configuration>

           <runtime>

                      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

                                  <probing privatePath="SharedLibs"/>

                       </assemblyBinding>

           </runtime>

           <configSections>

           </configSections>

</configuration>

Thanks in advance.

Monday, September 29, 2008 12:13 PM by Dan

# Does winforms app.config support configSource

Asp.Net supports hierarchial config sections. Certain sections can be shared among diff app.config.  Is something like this available for Winforms app.config

Tuesday, March 24, 2009 8:48 AM by Rajesh

# re: App.Config Files

Hi, do you know if there is an equivalent of the <add reference> section in the web.config for the app.config

Saturday, April 25, 2009 12:28 PM by David

# re: App.Config Files

Creating a new AppDomain with ASP.NET within IIS web site. New AppDomain doesn't seem to obey the Web.Config chaining (local, wwwroot, machine.config). Is there a way to specify more than one config file this way? PS.Thanks for this site. Its a world of help.

Tuesday, November 24, 2009 1:31 PM by John

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker