none
Trying to use runtime private Assembly binding with DotNet 4.0 Assemblies RRS feed

  • Question

  • In DotNet 4.0 I created a program that requires an assembly MYASM.DLL. If the DLL is in the current directory and there is no config file, myprog loads myasm successfully.  However, I would like to put myasm.dll in c:\myasms

    So I created this myprog.exe.config below. I know that myprog.exe is looking at the config file because it does not load the DLL even when it is in the current directory. But it is not finding it in the specified directory either. Any idea how I do this? 

    <?xml version ="1.0"?>
    <configuration>
      <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <probing privatePath="PublicAssemblies;PrivateAssemblies"/>
          <dependentAssembly>
            <assemblyIdentity name="myasm" publickeytoken="null" culture="neutral"/>
            <codeBase version="0.0.0.0" href="c:\myasms\myasm.dll"/>
        </assemblyBinding>
      </runtime>
    </configuration>
    
    
    I have also tried this with no luck: href=file://c:/myasms\myasm.dll  
    
    Saturday, February 26, 2011 12:12 AM

Answers

  • Yep, just read the doc you linked - it says so:
    msdn.microsoft.com/en-us/library/efs781xb(v=VS.100).aspx

    • If the assembly has a strong name, the codebase setting can be anywhere on the local intranet or the Internet. If the assembly is a private assembly, the codebase setting must be a path relative to the application's directory.

    -Karel

    • Marked as answer by Neil Weicher Saturday, March 5, 2011 4:43 PM
    Wednesday, March 2, 2011 12:46 AM
    Moderator

All replies

  • you xan change the dll path by pinvoke setdlldirectory

    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP
    Sunday, February 27, 2011 9:55 PM
  • you xan change the dll path by pinvoke setdlldirectory
    Thanks for the suggestion, but that has no affect on DotNet assembly DLLs.
    Monday, February 28, 2011 2:50 AM
  • Then check http://msdn.microsoft.com/en-us/library/system.appdomain.assemblyresolve.aspx

    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP
    Monday, February 28, 2011 5:27 AM
  • Thanks, but I am trying to get it working with the config file. Have you ever successfully used that?
    Monday, February 28, 2011 12:27 PM
  •  

    Hi Neil,

     

    By putting the assembly at c:\myasms\, you just need the assembly to be shared by different application, right?

     

    If so, why not given a strong-name to the assembly, and put it into GAC?

    If not, you may put the assembly in private folder of you application, which makes the application easier to be deployed.

     

    Please feel free to let us know if you have any concern.


    Eric Yang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, March 1, 2011 9:17 AM
  • Yes, I need the assembly shared by several applications.

    So you are saying that there is no way to get this to work? http://msdn.microsoft.com/en-us/library/efs781xb(v=VS.100).aspx

    Thanks.

    Tuesday, March 1, 2011 9:58 AM
  • Yep, just read the doc you linked - it says so:
    msdn.microsoft.com/en-us/library/efs781xb(v=VS.100).aspx

    • If the assembly has a strong name, the codebase setting can be anywhere on the local intranet or the Internet. If the assembly is a private assembly, the codebase setting must be a path relative to the application's directory.

    -Karel

    • Marked as answer by Neil Weicher Saturday, March 5, 2011 4:43 PM
    Wednesday, March 2, 2011 12:46 AM
    Moderator