Could not load file or assembly 'System.ComponentModel.Annotations, Version=


I have a .NET Standard 1.4 class library that references the System.ComponentModel.Annotations (4.3.0) NuGet package.

I'm then referencing this class library from a .NET Framework 4.6.2 test project. It builds fine, but at runtime I get the following error:

System.IO.FileLoadException occurred HResult=0x80131040
Message=Could not load file or assembly 'System.ComponentModel.Annotations, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

I tried adding a reference to the System.ComponentModel.Annotations (4.3.0) NuGet package from the net462 project, but that didn't make any difference.

I tried adding a reference to the .NET Standard library from the net462 project, but still no luck.

Am I missing something here? Is this a known bug, if so is there a work around?

Any help is much appreciated!

asked on Stack Overflow May 18, 2017 by Dan Ellis

8 Answers


In many cases, this can be solved by adding the following the the csproj file of your test project:


This forces the build process to create a .dll.config file in the output directory with the needed binding redirects.

The reason is that "classic" csproj test projects are true "libraries" and are not considered to need binding redirects by default. But running unit tests requires this. This only becomes an issue if referenced projects need those redirects to work correctly. This usually works when directly installing all NuGet packages that the referenced library uses, but with the new PackageReference style of NuGet packages, it does not.

See other instances where this fix has helped:

Could not load file or assembly Microsoft.Extensions.DependencyInjection.Abstractions, Version=

When using .Net Standard 1.4 in a library and .Net framework 4.6.1 in and application, unable to load file System.IO.FileSystem, Version=

answered on Stack Overflow May 19, 2017 by Martin Ullrich • edited Jun 5, 2017 by Martin Ullrich

I had similar problem but none of the above answers helped me. It turns out that solution is very easy, I've just run following command in Package Manager:

Install-Package System.ComponentModel.Annotations -Version 4.1.0

answered on Stack Overflow Jul 15, 2017 by Lukasz Cokot

In my case, I was using 4.0.0, so I fixed it by adding in

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <assemblyIdentity name="System.ComponentModel.Annotations"
                      publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="" newVersion=""/>

Adapt to your required version.

answered on Stack Overflow May 23, 2017 by Guillaume

Got it working by using assembly redirection as described in: just invoke FunctionsAssemblyResolver.RedirectAssembly() in the begining of your program.

using System.Reflection;
using System.Diagnostics;
using System.Linq;

public class FunctionsAssemblyResolver
    public static void RedirectAssembly()
        var list = AppDomain.CurrentDomain.GetAssemblies().OrderByDescending(a => a.FullName).Select(a => a.FullName).ToList();
        AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;

    private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
        var requestedAssembly = new AssemblyName(args.Name);
        Assembly assembly = null;
        AppDomain.CurrentDomain.AssemblyResolve -= CurrentDomain_AssemblyResolve;
            assembly = Assembly.Load(requestedAssembly.Name);
        catch (Exception ex)
        AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
        return assembly;

answered on Stack Overflow Nov 24, 2018 by Neil

For me, none of the other solutions worked.

I resolved this by manually adding a reference to System.ComponentModel.DataAnnotations myself (via project -> References), rather than letting Visual Studio handle it via the light-bulb quick-fix menu.

answered on Stack Overflow Feb 2, 2018 by Rich

Also for version error this is fixed for me in web.config:

    <assemblyIdentity name="System.ComponentModel.Annotations" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="" newVersion="4.6.0" />
answered on Stack Overflow Sep 23, 2019 by kodcu

I fixed this error by doing the Clean Solution command in Visual Studio 2019.

answered on Stack Overflow Sep 30, 2019 by user1605822

This usually happens when visual studio can't figure out the correct bindingRedirect.

Most likely the cause it that the version of the nugget does not match the version of the produced library.

To fix do this:

  1. From package manage console do:

    Get-Project –All | Add-BindingRedirect

    to regenerate assemblyBinding configuration at the config file

  2. If id didn't fix, then add manually the binding redirection:

        <assemblyIdentity name="System.ComponentModel.Annotations"    publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="" newVersion="Y" />


    1. X is the version that can't be load, from the error message
    2. Y is the version on your project references. To get it, select the library from the references node, and look for the version on property pane.
answered on Stack Overflow Dec 17, 2019 by MiguelSlv

User contributions licensed under CC BY-SA 3.0