none
InitializeNewDomain method may not work properly within a custom AppDomainManager RRS feed

  • Question

  • I have written a custom AppDomainManager and put in in the GAC. I am using the Environment variables to point to the Assembly and the type and then it runs fine. The requirement here is to override the Fusion store properties (application base, path, etc) of the DEFAULT DOMAIN of the application.

    This technique is very well documented on different blogs from Microsoft as well as in the book "Customizing the Microsoft .NET Framework Common Language Runtime" Book by 'Steven Pratschner'.

    I am not creating a new Domain but trying to change the ApplicationBase and PrivateBinPath of the "Default Domain". I am very well aware that the CreateDomain method for the Default Domain is not visible to me within a custom AppDomainManager but my understanding is that i have a second chance in the InitializeNewDomain override.

    Basically what I am doing is this, say if my exe is located in the following path with a dependent library

    c:\Somefolder\bin\debug\app.exe
    c:\Somefolder\bin\debug\library.dll
     

    I override the InitializeNewDomain function on my custom AppDomainManager and changed the properties on the AppDomainSetup param is as follows:


    AppBase = c:\Somefolder\bin\
    PrivateBinPath = c:\Somefolder\bin\debug;c:\Somefolder\bin\shared
    PrivateBinPathProbe = "exclude"
     
    That way I should be able to copy the dependent library to the shared folder and it will work. Now there are contradictory arguments on whether these properties can be changed or not after a domain has been created. Some documenation says these cannot be changed where as the blogs and the book explicitly says they can be changed cause the domain creation is not completed yet. In fact the book claims that InitializeNewDomain is the only place we can configure these properties for the DEFAULT DOMAIN as the CreateDomain function is not called for the process's default domain.

     
    Once the main function is called  reading these properties back from the AppDomain.CurrentDomain.SetupInformation tells me that the new values are set but when the code tries to load the dependent library that is now MOVED to the shared path it cannot find it.

     
    The fusion log viewer has the following for the bind failure. It clearly shows that  whatever was changed in the InitializeNewDomain on the appdomainsetup param was not passed on to the fusion loader. This has become a major problem for the solution that I am trying to write. Any help in this regard will be very much appreciated.
     

    LOG: DisplayName = MyLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null (Fully-specified) 

    LOG: Appbase = file:///C:/DEV/PROJECTS/AppDomainSamples/HelloWorld/bin/Debug/ LOG: Initial PrivatePath = NULL LOG: Dynamic Base = NULL

    LOG: Cache Base = NULL LOG: AppName = HelloWorld.exe Calling assembly : HelloWorld, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null. ===

    LOG: This bind starts in default load context. LOG: No application configuration file found.

    LOG: Using machine configuration file from C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\config\machine.config.

    LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind). LOG: Attempting download of new URL file:///C:/DEV/PROJECTS/AppDomainSamples/HelloWorld/bin/Debug/MyLibrary.DLL.

    LOG: Attempting download of new URL file:///C:/DEV/PROJECTS/AppDomainSamples/HelloWorld/bin/Debug/MyLibrary/MyLibrary.DLL.

    LOG: Attempting download of new URL file:///C:/DEV/PROJECTS/AppDomainSamples/HelloWorld/bin/Debug/MyLibrary.EXE.

    LOG: Attempting download of new URL file:///C:/DEV/PROJECTS/AppDomainSamples/HelloWorld/bin/Debug/MyLibrary/MyLibrary.EXE.

    LOG: All probing URLs attempted and failed.
    • Edited by nobugzModerator Saturday, October 4, 2008 7:31 PM OP unreadable due to pre tag
    Friday, October 3, 2008 10:28 PM

Answers

  • If you are doing this so you can shared the library between projects then Library.dll belongs in the GAC.  That's the only way you can avoid DLL Hell.
    Hans Passant.
    • Marked as answer by Zhi-Xin Ye Friday, October 10, 2008 11:49 AM
    Monday, October 6, 2008 1:01 PM
    Moderator

All replies

  • I'm not sure what you're doing.  Why don't you just use an app.config file?  Use the <probing> element.  Whatever is in the .config file is used to initialize the default appdomain.
    Hans Passant.
    Saturday, October 4, 2008 7:39 PM
    Moderator
  • Because my understanding is that <probing> will let you add a new path within your appbase. Here I am changing my appbase.

    So this is what I a trying to do:

    a) My application and its dependent dll are in a sinle folder following the default provate assembly model of .NET, say
                  c:\MyAppFolder\App.exe
                  C:\MyAppFolder\Library.dll

    b) Now I do not want to add a folder beneath 'MyAppFolder'. What i Want to do is move the shared dll to a sibling folder of MyAppFolder. SO here is what I want to achieve

                    C:\MyAppFolder\App.exe
                    c:\SharedFolder\Library.dll

    AppBase has to be changed for that and has to happen befofre the domain gets created. Config file reading is done very late in the sequence and by that time its too late.

    That is why I am using an AppDomain Manager. Btw this works when i create a second domain. The problem is with the default domain of the process.
    Monday, October 6, 2008 12:13 PM
  • If you are doing this so you can shared the library between projects then Library.dll belongs in the GAC.  That's the only way you can avoid DLL Hell.
    Hans Passant.
    • Marked as answer by Zhi-Xin Ye Friday, October 10, 2008 11:49 AM
    Monday, October 6, 2008 1:01 PM
    Moderator