bright
bright

Reputation: 4811

Visual c# project fails to run due to different versions of the same assembly

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.

Upvotes: 1

Views: 1253

Answers (2)

bright
bright

Reputation: 4811

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;
};   

Upvotes: 0

Ignacio Soler Garcia
Ignacio Soler Garcia

Reputation: 21855

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.

Upvotes: 1

Related Questions