none
assemblyBinding configuration ignored in machine.config RRS feed

  • Question

  • I have a situation where I need to be able to load assemblies in the GAC based on their partial names.  In order to do this I have added the following to my app.config file:

    <runtime> 
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"
        <qualifyAssembly partialName="MyAssembly" 
                         fullName"MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=0123456789abcdef"/> 
      </assemblyBinding> 
    </runtime> 


    This works exactly the way I want it to.  However, if I place the same element in my machine.config file, it seems to be ignored, and I get FileNotFoundExceptions when trying to load MyAssembly.

    The following is the assembly binding log when the element is in my app.config, and the bind succeeds:
    LOG: This bind starts in default load context. 
    LOG: Using application configuration file: C:\Documents and Settings\jon_scheiding\My Documents\Source\Testing\Test Projects 1\Cmd\bin\Debug\Testers.Cmd.vshost.exe.config 
    LOG: Using machine configuration file from C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\config\machine.config. 
    LOG: Partial reference qualified from config file. New reference: MyAssembly, Version=1.0.0.0, Culture=neutralPublicKeyToken=0123456789abcdef
    LOG: Post-policy reference: MyAssembly, Version=1.0.0.0, Culture=neutralPublicKeyToken=0123456789abcdef 
    LOG: Found assembly by looking in the GAC. 
    LOG: Binding succeeds. Returns assembly from C:\WINDOWS\assembly\GAC_MSIL\MyAssembly\1.0.0.0__b20f4683c1030dbd\MyAssembly.dll. 
    LOG: Assembly is loaded in default load context. 

    Contrast that with the log when my configuration is in machine.config, and the bind fails:
    LOG: This bind starts in default load context. 
    LOG: Using application configuration file: C:\Documents and Settings\jon_scheiding\My Documents\Source\Testing\Test Projects 1\Cmd\bin\Debug\Testers.Cmd.vshost.exe.config 
    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:/Documents and Settings/jon_scheiding/My Documents/Source/Testing/Test Projects 1/Cmd/bin/Debug/MyAssembly.DLL. 
    LOG: Attempting download of new URL file:///C:/Documents and Settings/jon_scheiding/My Documents/Source/Testing/Test Projects 1/Cmd/bin/Debug/MyAssembly/MyAssembly.DLL. 
    LOG: Attempting download of new URL file:///C:/Documents and Settings/jon_scheiding/My Documents/Source/Testing/Test Projects 1/Cmd/bin/Debug/MyAssembly.EXE. 
    LOG: Attempting download of new URL file:///C:/Documents and Settings/jon_scheiding/My Documents/Source/Testing/Test Projects 1/Cmd/bin/Debug/MyAssembly/MyAssembly.EXE. 
    LOG: All probing URLs attempted and failed. 


    The problem seems to be the fourth line, "Policy not being applied to reference at this time."  However, I can find very little documentation on what this message means, or how to address it.

    How can I get the framework to recognize my <runtime> element?

    Thanks in advance!
    Monday, October 13, 2008 7:49 PM

Answers

  • The MSDN documentation on partial assembly references and LoadWithPartialName() always talk about the app.config file to qualify the partial name and never mention machine.config.  I think "Policy not being applied" is just a side-effect of the assembly loader having an incomplete reference.
    Hans Passant.
    • Marked as answer by Zhi-Xin Ye Monday, October 20, 2008 11:09 AM
    • Unmarked as answer by jonwithoutanh Monday, October 20, 2008 12:12 PM
    • Unmarked as answer by jonwithoutanh Monday, October 20, 2008 12:12 PM
    • Marked as answer by nobugzModerator Saturday, October 25, 2008 9:58 PM
    Monday, October 13, 2008 8:55 PM
    Moderator