6

Since AppDomain.AppendPrivatePath() is obsolete, I'm trying to figure out how to specify a PrivateBinPath for the current AppDomain in my project without spinning up a whole new AppDomain, and being able to access it later.

I know I can set the PrivateBinPath on an AppDomainSetup object (which would be ok if I wanted to create a new AppDomain), and I also know that I can add it to my app.config like so:

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

However, when adding this entry to my app.config, the AppDomain.CurrentDomain.SetupInformation.PrivateBinPath property is null.

scottm
  • 27,829
  • 22
  • 107
  • 159

2 Answers2

6

use

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

According to http://msdn.microsoft.com/en-us/library/823z9h8w.aspx the privatePath is already interpreted as "subdirectories of the application's base directory"... so I suspect that using .\ is somehow messing things up...

Yahia
  • 69,653
  • 9
  • 115
  • 144
  • 2
    I tried using this, but not worked for me. The AppDomain.CurrentDomain.SetupInformation.PrivateBinPath property is still null. – Andre Soares Jan 24 '13 at 14:30
  • 1
    It seems that the AppDomain.CurrentDomain.SetupInformation.PrivateBinPath remains null when a probing path is set through an app.config file, but I was able to confirm that the probing path is still actually being used in this case. Calling Assembly.Load and specifying the name of an assembly in my probing path succeeded. – Roger Sanders Jun 18 '14 at 02:48
  • 1
    As sugessted in this comment http://stackoverflow.com/questions/33353420/appdomain-currentdomain-setupinformation-privatebinpath-is-null?noredirect=1#comment54508987_33353420 `SetupInformation.PrivateBinPath` is always null for the primary appdomain. – bitbonk Oct 27 '15 at 07:06
4

From the docs:

If the directories specified for PrivateBinPath are not under ApplicationBase, they are ignored.

So, you need to make sure the paths you are add are under ApplicationBase.

This only works with app.config however. If you need to do this at runtime, use the AssemblyResolve event as described in the docs:

http://msdn.microsoft.com/en-us/library/system.appdomain.assemblyresolve.aspx