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


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) {


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

Note how the [AssemblyVersion] is included. All four numbers are checked, a type that has Version = 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("")]

Changed on April 13th from AssemblyVersion(""). Version 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 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.