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.
Comments
Anonymous
June 02, 2003
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?Anonymous
June 03, 2003
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.Anonymous
June 21, 2003
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?Anonymous
June 23, 2003
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.Anonymous
July 06, 2003
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 GACthe DLL contains a class called : Taskthis 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 internetwhen i put a assembly tag in my page and place the dll in de bin dir it works, but don't use the GACand a want to use the GACi hope to hear from you.i think you know a lot, when i read your infoAnonymous
July 09, 2003
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).Anonymous
September 05, 2003
The comment has been removedAnonymous
September 15, 2003
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.Anonymous
May 25, 2004
I have a Web Service with web.config, can I treat that as my App.configAnonymous
May 28, 2004
I create a new project and am unable to find the app.config file in the solution tree? Any pointers?
Thanks,
MattAnonymous
June 02, 2004
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.Anonymous
June 08, 2004
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.Anonymous
June 08, 2004
Benjamin, please read the original blog entry - it answers this exact question, with the methods to call.Anonymous
July 06, 2004
pls tell about config fileAnonymous
July 07, 2004
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
sebAnonymous
July 16, 2004
<!-- Web.Config Configuration File -->
<configuration>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>Anonymous
April 06, 2005
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?Anonymous
June 29, 2005
The comment has been removedAnonymous
November 13, 2005
i can not add applicaion configurtion file in my windows application,it is not visible in add items.Anonymous
November 24, 2005
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.Anonymous
November 06, 2006
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, JimboAnonymous
December 17, 2006
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.Anonymous
January 17, 2007
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, BrettAnonymous
May 28, 2007
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?Anonymous
June 26, 2007
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, ShashAnonymous
July 12, 2007
The comment has been removedAnonymous
September 29, 2008
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.Anonymous
March 24, 2009
Asp.Net supports hierarchial config sections. Certain sections can be shared among diff app.config. Is something like this available for Winforms app.configAnonymous
April 25, 2009
Hi, do you know if there is an equivalent of the <add reference> section in the web.config for the app.configAnonymous
November 24, 2009
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.Anonymous
December 07, 2009
Hi, I have written a workflow custom tracking service which takes a DB Connection string in its constructor [Public Sub New(ByVal DBConnStr As String)]. Everything works absolutely fine when I add this service to the workflow runtime programmatically. Final hurdle is to define the service in the app.config file so that the workflowruntime picks it up from there. So far I have got this... <configSections> <section name="HostingWorkflowRuntime" type="System.Workflow.Runtime.Configuration.WorkflowRuntimeSection, System.Workflow.Runtime, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> </configSections> <HostingWorkflowRuntime Name="Hosting"> <CommonParameters/> <Services> <add type="MyTrackingService.MyTrackingService, MyTrackingService, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" DBConnStr="Data Source=Fred; Initial Catalog=Wilma; UID=Barney;PWD=Rubble; Pooling=True;" /> </Services> </HostingWorkflowRuntime> The runtime picks up the service, but insists on calling its parameterless constructor, rather than the one with the string parameter. I have tried removing the parameterless constructor, but this just generates a runtime error. Do I need to decorate the constructor with the parameter with a particular attribute to make the runtime recognise it or what?? This is really annoying! Rgds, //Anonymous
December 08, 2009
No worries, found it myself! Oh don't you love Microsoft documentation? As long as you know EXACTLY how to find it, all the info is there! Essentially, the custom tracking service has to have a constructor with a special signature for it to be definable from the app.config. When the WorkflowRuntime is created with the section name as a parameter it searches for the special signature and, if it isn't found, always tries the parameterless constructor. Obvious really. See http://msdn.microsoft.com/en-us/library/ms591125.aspx for an explanationAnonymous
January 19, 2010
Could you decipher this: 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. What is this? AppDomainSetup.ConfigurationFile Where is it found? Where is my call to AppDomain.CreateDomain? I've never called that before. I've got a windows service and another windows application that both use a shared DLL. The DLL expects a config file from the hosting application. Currently I have two config files, both identical in all but file name. I think your solution here is saying they can use the same one, but I can't make heads or tails out of most of what you have written. You you please break it down for the dumber guys like me?