다음을 통해 공유


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 “https://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="https://www.yourwebsite.com/filename.dll"/>

                    </dependentAssembly>
    </assemblyBinding>

    </runtime>
    </configuration>

Comments

  • Anonymous
    May 14, 2004
    Take Outs for 14 May 2004

  • Anonymous
    May 31, 2004
    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.

  • Anonymous
    June 01, 2004
    Yes, see the 'App.Config Files' link in this blog entry.

  • Anonymous
    June 03, 2004
    very helpful hints Suzanne. thank you very much

  • Anonymous
    June 21, 2005
    That is invaluable insight. It really helped. Thanks a lot!!!!!!!!

  • Anonymous
    March 28, 2006
    PingBack from https://mdavey.wordpress.com/2006/03/28/dependentassembly/

  • Anonymous
    May 16, 2006
    Thanks for a simple and direct sample of redirection.

  • Anonymous
    June 14, 2006
    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?

  • Anonymous
    June 26, 2006
    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

  • Anonymous
    February 08, 2007
    Do you have any idea why a codebase href of: file:///../../myassembly.dll would not work? Thanks.

  • Anonymous
    February 19, 2007
    Can you please let us know about machine.config tag details???

  • Anonymous
    April 12, 2007
    I typically recommend that you build and test your assemblies against the same version of .NET that you

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

  • Anonymous
    April 12, 2007
    By default, the application configuration file of the default appdomain (and other appdomains for v1.1

  • Anonymous
    December 22, 2007
    PingBack from http://evgenya.wordpress.com/2007/12/22/configuring-applications-using-systemconfiguration-namespace/

  • Anonymous
    January 21, 2009
    PingBack from http://www.keyongtech.com/427431-uninstalling-older-versions

  • Anonymous
    March 06, 2009
    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?    

  • Anonymous
    March 13, 2009
    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.

  • Anonymous
    May 26, 2009
    PingBack from http://castironbakeware.info/story.php?title=suzanne-cook-s-net-clr-notes-app-config-examples

  • Anonymous
    September 18, 2009
    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