Mun
Mun

Reputation: 14308

Redirect referenced assembly to a different version in C# console application

I'm trying to use the log4net RabbitMQAppender in a C# console application, and it seems like this requires RabbitMQ.Client 2.6.1.0 to be referenced. I'm currently using the latest version, 2.7.1.0, which is causing the appender creation to fail with the following error:

Could not create Appender [AmqpAppender] of type [log4net.RabbitMQ.RabbitMQAppender, log4net.RabbitMQ]. Reported error follows. System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileNotFoundException: Could not load file or assembly 'RabbitMQ.Client, Version=2.6.1.0, Culture=neutral, PublicKeyToken=89e7d7c5feba84ce' or one of its dependencies. The system cannot find the file specified.

Replacing the RabbitMQ.Client with the previous version fixes the issue, though I'd like to get this working with the latest version.

According to another question here on SO, the following config needs to be added to the app settings, which I've added:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity name="RabbitMQ.Client" />
            <bindingRedirect oldVersion="2.6.1.0" newVersion="2.7.1.0" />
        </dependentAssembly>
    </assemblyBinding>
</runtime>

However, this doesn't seem to make any difference, and the error still occurs with the appender throwing an error about being unable to load the RabbitMQ.Client file.

Is there anything else that needs to be done to achieve this, or something that could be stopping this assembly redirection from working?

Upvotes: 0

Views: 3967

Answers (2)

Phil C
Phil C

Reputation: 1

I had a similar problem. I created a .NET DLL that exposed a COM interface. Internally, my DLL was using the RabbitMQ.Client.dll. My programmer was using this in a VB6 application. He was getting the same file not found error. However, I could create a VB6 app using the .NET DLL and NOT get the error.

I, finally, used ProcMon and filtered the results on the VB6.exe process name. I was able to determine that the .NET DLL was referencing the RabbitMQ.Client.DLL file via a mapped drive instead of a UNC. I had the programmer map the same drive and the problem went away.

Upvotes: 0

Mun
Mun

Reputation: 14308

It looks like I may have had a configuration mismatch somewhere. Setting the RabbitMQ.Client.dll file to copy local and adding the following to my app config resolved the issue:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity name="RabbitMQ.Client" publicKeyToken="89e7d7c5feba84ce" culture="neutral" />
            <bindingRedirect oldVersion="2.6.1.0" newVersion="2.7.1.0"/>
        </dependentAssembly>
    </assemblyBinding>
</runtime>

Upvotes: 1

Related Questions