3

This is linked to a question I asked yesterday. Briefly, the problem I'm having is that I have two conflicting versions of an assembly. One is in the appbase and the other is in the PrivateBinPath.

From what I understand the assembly resolver searches the appbase first and then searches in the private path. The problem is that, based on what I got by running fusion log, if the resolver finds the wrong version in the appbase it throws an error saying the version doesn't match and stops probing.

I need to use references located in the appbase, so setting the PrivateBinPathProbe is not an option because it excludes the appbase. Is there any way to change the order to search in the PrivateBinPath first?

As a side note, I do not understand why the resolver just gives up if it finds the wrong version.

Community
  • 1
  • 1
user472875
  • 3,115
  • 4
  • 37
  • 68

2 Answers2

2

The AssemblyResolve event is only called when the previous lookup was not successfull. So you have to combine the approach from Yahia with the answer from your previous question:

  1. Set PrivateBinPathProbe so that Fusion will not look in the AppBase directory.
  2. Implement an AssemblyResolve event that resolves the path to your AppBase directory.
  3. ...
  4. profit!

The first step is important so that the event gets fired.

aKzenT
  • 7,775
  • 2
  • 36
  • 65
1

There is AFAIK no option to do that...

You could however implement a workaround:

  • setup an AssemblyResolve handler
  • implement the handler to search wherever you want in whatever preferred order need be

Another option is to embed the dependencies into the EXE/DLL so there is no need to search any path at all - for options to achieve this see here.

Community
  • 1
  • 1
Yahia
  • 69,653
  • 9
  • 115
  • 144
  • Maybe I did something wrong, but I tried tracing all the AssemblyResolve events caught by the handler, and mine never came up. – user472875 Apr 05 '12 at 15:50
  • @user472875 that is hard to diagnose without more details/source code etc. One possible explanation could be that loading 2 different versions of the an assembly into the same process can lead to strange effects... – Yahia Apr 05 '12 at 15:53
  • slightly different situation but as it is, the resources I unpack into the PrivateBinPath are actually embedded in the core DLL. One option I have is to manually load the assembly using Assembly.LoadFrom on the file path. It is a hack that I would really like to avoid though. – user472875 Apr 05 '12 at 16:02
  • @user472875 why are you unpacking them ? just implement the core DLL so that it loads them via its own AssemblyResolve handler directly from the resources... – Yahia Apr 05 '12 at 16:29
  • What I'm making is a plugin, and the base application (it is the one doing the unpacking) is doing all the other steps. I can't mess too much with that logic because there are several other plugins already out there. Otherwise, I could have implemented something like aKzenT's solution. – user472875 Apr 05 '12 at 16:38
  • @user472875 sorry but I don't think that this approach is ever going to work in a robust fashion - it is basically flawed as a plugin concept IMO... – Yahia Apr 05 '12 at 16:47
  • To clarify a bit on my pervious comment: I actually have 5 DLLs that could potentially have version conflicts. That means that I would have to add Assembly.LoadFrom in different parts of my plugin code to try to beat the resolver to it, which to me seems like a hack. And yes, unfortunately, those are the limitations. :( – user472875 Apr 05 '12 at 16:47
  • @user472875 I understand the problem... I strongly recommend to redesign the approach (esp. regarding resolving assemblies and conflicting versions) and then update plugins step by step to the new design... in my experience such problems tend to grow over time... thus a smart approach to incrementally solve these conceptual shortcomings is the only viable option IMHO. – Yahia Apr 05 '12 at 16:53
  • I'm reluctant to accept the answer, but it looks like you are right. Although the way the assembly resolution is handled in this case still feels like a shortcoming to me. Thanks for your help. – user472875 Apr 05 '12 at 17:07