1

My c# application uses two different pre-packaged parsers, that each use a different strong version of Antlr.Runtime.dll.

The application throws a FileLoadException, apparently because it correctly loaded only one of the versions and could not find the other.

The <app>\bin\x86\Debug directory contains only one copy of the dll.

Note that I cannot use assembly aliases since my code doesn't directly call the versioned assemblies - they are only indirectly called via the parser assemblies.

Is this a matter of instructing Visual Studio to place the differently versioned dlls in separate directories since they have the same name? I'd like to avoid using the GAC as far as possible.

I've read many "side by side" and related articles, but none seem to address this question.

4
  • 1
    The GAC was made to solve this problem. Takes 30 seconds. Implementing AppDomain.AssemblyResolve and writing the post build event to put the copies in separate directories is going to take a bit longer. Commented Feb 1, 2011 at 12:18
  • @hans - that breaks xcopy deployment. Commented Feb 1, 2011 at 14:25
  • Well, sounds to me that trying to use different versions of the same assembly broke that. Xcopy otherwise has no trouble copying subdirectories, /s option. Commented Feb 1, 2011 at 14:28
  • The point is that GAC deployment is not the same as xcopy deployment. With xcopy deployment, you copy a directory and the app works. Your suggestion requires an installer, however simple, to register assemblies into the GAC. Conceivably App.Main() could do this at first start, but that's no simpler than the code below. Or am I missing something? :) Commented Feb 1, 2011 at 19:41

2 Answers 2

1

I'm in no way a SxS expert but at my company when this happens they create a different folder for each assembly and a manifest to load them.

Sign up to request clarification or add additional context in comments.

Comments

0

Solved this problem by hooking AppDomain.AssemblyResolve:

AppDomain.CurrentDomain.AssemblyResolve += (s, e) =>
{
    Assembly result = null;

    if (e.Name ==
        @"Antlr3.Runtime, Version=3.1.3.42154, Culture=neutral, PublicKeyToken=3a9cab8f8d22bfb7")
        result = Assembly.LoadFile(
             @"C:\src\NHibernate-3.0.0.GA\lib\net\3.5\Antlr3.Runtime.dll");

    return result;
};   

1 Comment

This is good, except that you have physical path to dll file in source code. I personally would use what SoMos wrote. It should be possible to configure these things without C# programming.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.