Two different versions of the same DLL with C# Two different versions of the same DLL with C#

Recently I was stuck with the error Try removing one of the references or sign them to enable side-by-side. This is not a common error, but I received it because I was in the very unfortunate situation of requiring to have two different versions of the same DLL installed in my solution. Let's explore how I worked around this.


Here is some background of what I was trying to accomplish. I had an existing API integration with Stripe.net. This integration was very old, as in 5 years old. The integration was working flawlessly so we never upgraded the SDK we were using.

Recently Stripe has introduced Stripe Connect where, using OAuth, the client agrees to you, the provider, to perform API and direct charge requests. The old way was to simply use the client's API keys. This is now discouraged.

Of course the version of the SDK we were using doesn't support this newer Stripe Connect functionality.

My first thought was that I could install different versions of the Stripe NuGet package by creating different projects. This allowed me to compile my code. However, when I ran it I received the dreaded run-time error regarding side-by-side references.

It was a given that we had to support both integrations while we migrate our existing clients to the new Stripe Connect approach.

Let's continue on to the solution.

Try removing one of the references or sign them to enable side-by-side

Two different projects I think is still a good solution, so how to solve the duplicate references. My solution was as follows:

  1. Download the source code for Stripe's SDK for the old version I was using.
  2. With the old version downloaded, I opened the solution and changed the AssemblyTitle and the actual name of the .NET project.
  3. I changed both of these values to Stripe.old.
  4. I compiled the source code (in Release mode).
  5. I removed the old version of the NuGet package.
  6. In my existing project I manually included a reference to my newly compiled DLL with the name of Stripe.old.
  7. I left the latest version of the Stripe.net NuGet package in my new project.
  8. Recompiled and no more run-time error.

This allowed me to overcome the Try removing one of the references or sign them to enable side-by-side error.

In my BIN directory I now have two Stripe DLLs: Stripe.old.dll and Stripe.net.dll. This is the secret to have two different versions of the same library in your C# projects. Perhaps not the prettiest solution, but it allowed me to support both implementations without having to refactor the original implementation.

Published on Apr 13, 2019

Tags: dll | ASP.NET MVC and Web API Tutorial | c#

Related Posts

Did you enjoy this article? If you did here are some more articles that I thought you will enjoy as they are very similar to the article that you just finished reading.

Tutorials

Learn how to code in HTML, CSS, JavaScript, Python, Ruby, PHP, Java, C#, SQL, and more.

No matter the programming language you're looking to learn, I've hopefully compiled an incredible set of tutorials for you to learn; whether you are beginner or an expert, there is something for everyone to learn. Each topic I go in-depth and provide many examples throughout. I can't wait for you to dig in and improve your skillset with any of the tutorials below.