title: Could not load file or assembly 'System.ComponentModel.Annotations
body: <p>I have a Framework 4.7.2 Unit Test calling a .NetStandard2.0 project </p>
  
  <p>The debugger indicates the test is failing in some data access code.
  <a href="https://i.stack.imgur.com/BpkBU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BpkBU.png" alt="File Not Found"></a></p>
  
  <p>The error is </p>
  
  <pre><code>Test method UnitTestProject3.UnitTest1.TestMethod1 threw exception: 
  System.IO.FileNotFoundException: Could not load file or assembly 'System.ComponentModel.Annotations, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
      at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.CoreConventionSetBuilder.CreateConventionSet()
     at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.CreateConventionSet(IConventionSetBuilder conventionSetBuilder)
     at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.CreateModel(DbContext context, IConventionSetBuilder conventionSetBuilder, IModelValidator validator)
     at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.&lt;&gt;c__DisplayClass5_0.&lt;GetModel&gt;b__1()
     at System.Lazy`1.CreateValue()
     at System.Lazy`1.LazyInitValue()
     at System.Lazy`1.get_Value()
     at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.GetModel(DbContext context, IConventionSetBuilder conventionSetBuilder, IModelValidator validator)
     at Microsoft.EntityFrameworkCore.Internal.DbContextServices.CreateModel()
     at Microsoft.EntityFrameworkCore.Internal.DbContextServices.get_Model()
     at Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServicesBuilder.&lt;&gt;c.&lt;TryAddCoreServices&gt;b__7_2(IServiceProvider p)
     at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory(FactoryCallSite factoryCallSite, ServiceProviderEngineScope scope)
     at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
     at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope)
     at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
     at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProviderEngineScope scope)
     at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
     at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope)
     at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
     at Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine.&lt;&gt;c__DisplayClass1_0.&lt;RealizeService&gt;b__0(ServiceProviderEngineScope scope)
     at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
     at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType)
     at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
     at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
     at Microsoft.EntityFrameworkCore.DbContext.get_DbContextDependencies()
     at Microsoft.EntityFrameworkCore.DbContext.get_InternalServiceProvider()
     at Microsoft.EntityFrameworkCore.DbContext.get_DbContextDependencies()
     at Microsoft.EntityFrameworkCore.DbContext.get_Model()
     at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.get_EntityType()
     at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.get_EntityQueryable()
     at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.System.Linq.IQueryable.get_Provider()
     at System.Linq.Queryable.SingleOrDefault[TSource](IQueryable`1 source, Expression`1 predicate)
     at SBD.VivPackAndSend.PackAndSend.GetReadyBy(Int32 headId, String connectionString) in D:\devnet10\SBD.Common\SBD.VivPackAndSend\PackAndSend.cs:line 65
     at UnitTestProject3.UnitTest1.TestMethod1() in D:\devnet10\SBD.Common\UnitTestProject3\UnitTest1.cs:line 15
  </code></pre>
  
  <p>The .NetStandard2.0 project file is</p>
  
  <pre><code>&lt;Project Sdk="Microsoft.NET.Sdk"&gt;
  
    &lt;PropertyGroup&gt;
      &lt;OutputType&gt;Library&lt;/OutputType&gt;
      &lt;TargetFramework&gt;netstandard2.0&lt;/TargetFramework&gt;
      &lt;CopyLocalLockFileAssemblies&gt;true&lt;/CopyLocalLockFileAssemblies&gt;
    &lt;ApplicationIcon /&gt;
      &lt;StartupObject /&gt;
      &lt;SignAssembly&gt;true&lt;/SignAssembly&gt;
      &lt;AssemblyOriginatorKeyFile&gt;Software by Design.snk&lt;/AssemblyOriginatorKeyFile&gt;
    &lt;/PropertyGroup&gt;
  
    &lt;ItemGroup&gt;
      &lt;PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.6" /&gt;
      &lt;PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="2.2.6" /&gt;
      &lt;PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.6" /&gt;
      &lt;PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" /&gt;
    &lt;/ItemGroup&gt;
  
    &lt;ItemGroup&gt;
      &lt;ProjectReference Include="..\StandardCommon\SBD.StandardCommon.csproj" /&gt;
    &lt;/ItemGroup&gt;
  
  &lt;/Project&gt;
  </code></pre>
  
  <p>I looked at <a href="https://stackoverflow.com/questions/44053187/could-not-load-file-or-assembly-system-componentmodel-annotations-version-4-1">this similar question</a> and tried to add a reference to System.ComponentModel.Annotations using VS2019->Tools->Manage Nuget Packages for solution</p>
  
  <p>But the lowest version available is 4.4.0</p>
  
  <p>I tried it anyway but it did not help.</p>