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:
- Download the source code for Stripe’s SDK for the old version I was using.
- With the old version downloaded, I opened the solution and changed the AssemblyTitle and the actual name of the .NET project.
- I changed both of these values to Stripe.old.
- I compiled the source code (in Release mode).
- I removed the old version of the NuGet package.
- In my existing project I manually included a reference to my newly compiled DLL with the name of Stripe.old.
- I left the latest version of the Stripe.net NuGet package in my new project.
- 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.