Why does my NuGet package only work with a particular version of a third-party library?

advertisements

I have created an extension to a package (AutoFixture), which implements one of its interfaces, ICustomization. I published the NuGet package with a compiled binary that references version 3.16 of AutoFixture.

When used in a project that holds a reference to version 3.18 of AutoFixture, the class that implements the ICustomization interface cannot be used. The compilation error given is that MyCustomization is not assignable to ICustomization.

By downloading and compiling the source to my extension, updating the AutoFixture reference, and including it in the new project, the compiler error goes away.

I would have thought with only a minor version increment (maintaining backwards compatibility) this would not have been an issue.

Why does my NuGet package only work with this version of AutoFixture, and is it possible to release a binary under NuGet that will work with all minor version increments (ie those that don't break backwards compatibility)?


This is a consequence of type identity in .NET. A type isn't just identified by its namespace name and type name, it also includes the assembly it came from. Something called the "assembly qualified type name" in the framework. I can demonstrate it with a little sample program:

using System;

class Program {
    static void Main(string[] args) {
        Console.WriteLine(typeof(IDisposable).AssemblyQualifiedName);
        Console.ReadLine();
    }
}

Output:

System.IDisposable, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

Note how the [AssemblyVersion] is included. All four numbers are checked, a type that has Version = 4.0.0.1 is not compatible and generates the compiler error message you got. This is what plays havoc on your code, the author modified his Properties\AssemblyInfo.cs file, it now reads:

 [assembly: AssemblyVersion("3.18.3.0")]

Changed on April 13th from AssemblyVersion("3.18.2.0"). Version 3.18.2.0 was checked-in on April 12th, it survived for just one day :) Looking through the history, the author changes the version often, several times per month on average. Version 3.16.0.0 was released on November 30th, 2013. He has changed it fourteen times since then. For comparison, Microsoft has changed the version number for IDisposable only once in the past 9 years.

You cannot possibly keep up of course.

You ought to get in touch with the author to let him know about this. It is probably going to be difficult to talk him out of it though. You need to deal with this on your end by using a binding redirect. Lightly touched upon by this article about Nuget versioning. It can be done with the Add-BindingRedirect powershell command. This article shows how to run it automatically.