Welcome to MSDN Blogs Sign in | Join | Help

App.config Examples

Below are three examples of useful application configuration files.

  1. Forces the v1.0 CLR to be run. If the v1.0 CLR is not installed, the app will fail to run.

    <?xml version ="1.0"?>
     <configuration>
        <startup>
             <requiredRuntime version="v1.0.3705"/>
             <supportedRuntime version="v1.0.3705"/>
         </startup>
     </configuration>

  2. Redirects “assemblyName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=25283151a234958d“ to version 2.0.0.0 of that assembly. This is only useful for strongly-named assemblies, since versions don't matter for those that are simply-named.

    <?xml version ="1.0"?>
    <configuration>
    <runtime>

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

                    <dependentAssembly>
                            <assemblyIdentity name="assemblyName" culture="" publicKeyToken="25283151a234958d"/>
                            <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0"/>

                    </dependentAssembly>
            </assemblyBinding>

    </runtime>
    </configuration>

  3. Redirects “assemblyName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=8968ee41e78ce97a“ to codebase “http://www.yourwebsite.com/filename.dll“. 'Href' can also be set to something like “file:///c:/localfile/filename.dll“. Note that redirecting to a codebase causes a System.Net.WebPermission or System.IO.FileIOPermissionAccess.Read + PathDiscovery demand when loading that assembly.

    <?xml version ="1.0"?>
    <configuration>
    <runtime>

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

                    <dependentAssembly>
                            <assemblyIdentity name="assemblyName" culture="" publicKeyToken="8968ee41e78ce97a"/>
                            <codeBase version="1.0.0.0" href="http://www.yourwebsite.com/filename.dll"/>

                    </dependentAssembly>
            </assemblyBinding>

    </runtime>
    </configuration>

    Published Friday, May 14, 2004 9:25 AM 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

    # LoadFrom's Second Bind

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

    # .NET app.config Files

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

    # Take Outs for 14 May 2004

    Take Outs for 14 May 2004
    Saturday, May 15, 2004 2:29 AM by Enjoy Every Sandwich

    # Useful config files scenarios to keep on hand

    Friday, May 21, 2004 7:24 PM by ISerializable

    # re: App.config Examples

    Suzanne,

    Is there a way to use application configuration files with different binding redirects on a per-appdomain basis? I would like to have a managed app host multiple appdomains, each with a different environment.

    Thanks for any help.
    Monday, May 31, 2004 1:20 PM by David Levine

    # re: App.config Examples

    Yes, see the 'App.Config Files' link in this blog entry.
    Tuesday, June 01, 2004 2:51 PM by Suzanne

    # re: App.config Examples

    very helpful hints Suzanne. thank you very much
    Thursday, June 03, 2004 11:21 AM by yoohoo

    # New Assembly, Old .NET (and Vice-Versa)

    Wednesday, January 26, 2005 5:40 PM by Suzanne Cook's .NET CLR Loader Notes

    # Some interesting posts and articles

    Wednesday, February 16, 2005 9:25 AM by Angelos Petropoulos' WebLog

    # re: App.config Examples

    That is invaluable insight. It really helped. Thanks a lot!!!!!!!!
    Tuesday, June 21, 2005 9:00 AM by Ali

    # Tales from a Trading Desk &raquo; dependentAssembly

    Tuesday, March 28, 2006 8:28 AM by Tales from a Trading Desk » dependentAssembly

    # re: App.config Examples

    Thanks for a simple and direct sample of redirection.
    Tuesday, May 16, 2006 6:47 PM by Patrick

    # re: App.config problem

    I changed app.config while the application is running. But the application does not read the change, unless I restart the application. What should I do?
    Thursday, June 15, 2006 7:47 AM by Pravin Bhongale

    # re: App.config Examples

    Will this solution work for assemblies that are registered in the GAC? would oyu have to register App.config?  and what if the app uses Machine.config instead of App.config
    Monday, June 26, 2006 12:04 PM by James Moore

    # re: App.config Examples

    Do you have any idea why a codebase href of:

    file:///../../myassembly.dll

    would not work?

    Thanks.

    Thursday, February 08, 2007 9:53 AM by Mike Nacey

    # re: App.config Examples

    Can you please let us know about machine.config tag details???

    Tuesday, February 20, 2007 4:37 AM by alevi

    # New Assembly, Old .NET (and Vice-Versa)

    I typically recommend that you build and test your assemblies against the same version of .NET that you

    Thursday, April 12, 2007 6:44 PM by Suzanne Cook's .NET CLR Notes

    # LoadFrom's Second Bind

    Pre-v2, when you load an assembly by path through Fusion (LoadFrom(), ExecuteAssembly(), etc.), it can

    Thursday, April 12, 2007 7:07 PM by Suzanne Cook's .NET CLR Notes

    # App.Config Files

    By default, the application configuration file of the default appdomain (and other appdomains for v1.1

    Thursday, April 12, 2007 8:24 PM by Suzanne Cook's .NET CLR Notes

    # Configuring applications using System.Configuration namespace &laquo; Aizikovich Evgeni

    # Uninstalling Older Versions | keyongtech

    Wednesday, January 21, 2009 10:32 PM by Uninstalling Older Versions | keyongtech

    # re: App.config Examples

    We have an unmanaged app that is loading a .NET assembly through interop wrappers.  This loaded assembly uses another .NET assembly that requires settings from the app.config. Can we configure the required settings in the unmanged app.config file?    

    Friday, March 06, 2009 9:17 AM by E.Palus

    # re: App.config Examples

    Is there any way to do this at run-time? I'll keep searching, but this thread seems very on-topic. Basically, what I'm hoping to do, if it is possible, is have a compile-time reference to a DLL in another project, but not deploy that DLL with the build output. Instead, after firing up, the program needs to determine the location of the DLL by other means and have it be loaded from there. Just using strong names and GACcing the dependency isn't an option at this point, unfortunately.

    Friday, March 13, 2009 4:26 PM by Jonathan Gilbert

    # Suzanne Cook s NET CLR Notes App config Examples | Cast Iron Cookware

    # re: App.config Examples

    Hi Suzanne,

    I have a simple versioning issue that I cannot seem to resolve after searching the net for a day or so.

    Perhaps you could help.

    I have a program (X) that accesses an interface in another program (Y) using .NET remoting.

    Say I built my program with version 1.3.4.0 of the dll containing the interface.

    The version number of the DLL updates with each build of the Y software, but the functionality does not change.  I also don't know what future versions will be.

    How would I go about telling my program to always use the assembly from the remote program/server?  

    I've tried using some app.config settings as you suggest in this post, but no luck.

    Is what I'm trying to do even possible?

    Thanks,

    Caleb

    Friday, September 18, 2009 4:50 PM by Caleb Dougherty

    Leave a Comment

    (required) 
    required 
    (required) 

      
    Enter Code Here: Required
     
    Page view tracker