none
how to read "runtime" section of app.config file

    Question

  • In my config file, I have specified <runtime> section in which I specify the probing path detail. My <runtime> section looks like following

     

     <runtime>
        <assemblyBinding xmlns="urn: schemas-microsoft-com:asm.v1">
          <probing privatePath="AppWork\DotNetComp"/>
        </assemblyBinding>
      </runtime>

    I'm using framework 3.0 and I want to read the probing path information by reading configuration file using ConfigurationManager class. Is it possible? currently when I try to access"runtime" section using

     

    ConfigurationManageer.OpenExeConfiguration(ConfigurationUserLevel.None).GetSection("runtime")

     

    it returns "IgnoredSection" as return object and using this return value I can't access the "privatepath" element. I also tried using "SectionInformation" but not helping.

     

    I need to create additional appdomain in my application and I need to pass on this additional probing path information to newly created appdomain.

     

    Thanks...

    Tuesday, April 22, 2008 6:34 AM

Answers

  • You can get that information from AppDomain.CurrentDomain.SetupInformation.PrivateBinPath

     

     

    Tuesday, April 22, 2008 7:39 AM
  • If the probing path is part of the .exe.config for the COM component, and you know the location of that file, why don't you just set setup.ConfigurationFile in the code I posted to the config file's location and then create the domain?

     

    Tuesday, April 22, 2008 10:37 AM

All replies

  • You can get that information from AppDomain.CurrentDomain.SetupInformation.PrivateBinPath

     

     

    Tuesday, April 22, 2008 7:39 AM
  • When creating your secondary AppDomain, you can specify the configuration file for that domain to use.  So if you don't mind giving your secondary AppDomain access to the host's configuration file, you can simply do this:

     

    Code Snippet

    AppDomainSetup setup = new AppDomainSetup();

    //Modify whatever you need with the setup, like the base directory etc.

    setup.ConfigurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;

    AppDomain newDomain = AppDomain.CreateDomain("MyDomain", AppDomain.CurrentDomain.Evidence, setup);

     

     

     

     

    Tuesday, April 22, 2008 7:52 AM
  •  

    Thanks for your replies.

     

    The suggestions given are appropriate however not fitting to my environment. Let me describe it.

     

    I have created COM Component which will be hosted by COM client. This COM Client can be developed in any language i.e. VB, C++, or even Office applications also. When COM Client tries to host the component, I create seperate AppDomain and load the COM Component in newly created domain. It meast seperate domain for client application and COM component.

     

    Now all the probing path related information is available in the exe.config file of COM Component. So in above context while creating new AppDomain, when I use "AppDomain.CurrentDomain.SteupInformation.ConfigurationFile" it returns the configuration file of client application in which no probing path information is available. So the solution suggested above I can not use because it will return me the configuration file detail of client application whereas I need the configuration file detail of COM component.

     

    Hope I'm clear with my above explaination. Pls revert in case if you need to know more.

     

    Thanks...

    Tuesday, April 22, 2008 8:23 AM
  • If the probing path is part of the .exe.config for the COM component, and you know the location of that file, why don't you just set setup.ConfigurationFile in the code I posted to the config file's location and then create the domain?

     

    Tuesday, April 22, 2008 10:37 AM
  • Sasha,

    Thanks for your reply.

     

    I did what you mentioned yesterday itself after getting your first reply. But assigning config file to newly created domain causes "ConfigurationErrorsException" with message "Configuration system failed to initialize". However my config file is well formed. I don't see any problem with my config file as such because with the same config file I can run the application in standalone mode

     

    I checked the inner exception detai but fail to resolve the problem. I'm giving the inner exception detail here.

    {"Section or group name <ProjectName>.Properties.Settings' is already defined. Updates to this may only occur at the configuration level where it is defined. (C:\\Documents and Settings\\Admin\\Local Settings\\Application Data\\XXXXX\\OLEInterfaceDomain_Path_x4xzrjbupq1vxw54tn0dg5km2ipj2umw\\1.00\\user.config line 5)"}

     

    Can you tell me from above information what could be the problem?

     

    Thanks....

    Wednesday, April 23, 2008 2:03 AM
  • Hi,

    I know this message was posted ages ago but I am running into the same problem. I am trying to read the values of the runtime 'children' in much the same way we would read AppSetting values but it doesn't seem that it is that easy..
    I was hoping to use the Configuration class but there is no way to read runtime properties in code, that I know of, like we do AppSettings. i.e. 

     

    Dim configure As Configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)

     

    Dim sm = configure.AppSettings.Settings("setting1").Value

     


     with app.config settings as follows

     

    <?xml version="1.0" encoding="utf-8" ?> 
    <configuration> 
    ...
    <runtime> 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
    <dependentAssembly> 
    <assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d"/> 
    <bindingRedirect oldVersion="0.0.0.0-6.1.3.0" newVersion="6.1.3.0"/> 
    <publisherPolicy apply="no"/> 
    </dependentAssembly> 
    </assemblyBinding> 
    </runtime> 
    </configuration>
    
    



    Any suggestions?

    Thanks!


    my favorite place on the net is msdn!
    • Edited by msdner1 Tuesday, January 26, 2010 1:57 PM formatting
    Tuesday, January 19, 2010 6:51 PM
  • I've come to the following conclusion with regard to this problem.

    While it is more elegant to use the classes that come with the System.Configuration namespace to access configuration settings it seems that no property exists to access the runtime section of the config; by default its handler is set to IgnoreSectionHander and as such cant be accessed. 

    The IgnoreSection configuration section handler can be used to instruct the .Net Framework configuration system to bypass i.e. not to load and parse the configuration section that is associated with the IgnoreSection handler. If you instruct the configuration system to ignore a section in the configuration file (as it appears is the default with the runtime section) then you will have to load and parse the section and assign the configuration settings appropriately from your own code in order to make use of the configuration settings.

    And so that is my solution, loading the config file in an XML doc and manually parsing and updating the runtime assembly binding.

    If there was a way to override the handler for the runtime section I think that this could be done, but I'm not sure how I would go about that.

    If any one can provide more information on this it would be great.

    Thanks!
    my favorite place on the net is msdn!
    Wednesday, January 20, 2010 3:09 PM