Could not load file or assembly

1

I've recently updated to the latest .net core 3.0 SDK, updated all my nugets to also include pre-release versions, however I keep getting this error come up when I try to do anything with Pomeolo / Entity Framework with MySQL.

System.IO.FileLoadException: Could not load file or assembly 'Microsoft.Extensions.Configuration.Abstractions, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. An operation is not legal in the current state. (0x80131509)
File name: 'Microsoft.Extensions.Configuration.Abstractions, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
 ---> System.InvalidOperationException: AssemblyLoadContext is unloading or was already unloaded.
   at System.Runtime.Loader.AssemblyLoadContext.VerifyIsAlive()
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath)
   at AltV.Net.Host.ResourceAssemblyLoadContext.Load(AssemblyName assemblyName)
   at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingLoad(AssemblyName assemblyName)
   at System.Runtime.Loader.AssemblyLoadContext.Resolve(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)
   at Microsoft.EntityFrameworkCore.Storage.Internal.NamedConnectionStringResolverBase.ResolveConnectionString(String connectionString)
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection..ctor(RelationalConnectionDependencies dependencies)
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetService[T](IServiceProvider provider)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope)
   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.Where[TSource](IQueryable`1 source, Expression`1 predicate)

I have tried stable and pre-release versions, I have this file also included in Nuget and it's version is 2.2.0.0. This seems to be an issue with .Net Core 3.0 or Pomelo?

My code:

try
            {
                Console.WriteLine("Before Context");
                using Context context = new Context();
                Console.WriteLine("After Context");
                List<Models.Vehicle> vehicles = context.Vehicle.Where(x => x.Spawned).ToList();

                Console.WriteLine($"Resetting {vehicles.Count} Vehicle Spawn Status");

                foreach (Models.Vehicle vehicle in vehicles)
                {
                    vehicle.Spawned = false;
                    context.SaveChanges();
                }

                Console.WriteLine("Completed resetting vehicle spawn statuses");
                context.Dispose();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }

I am getting to this line:

 Console.WriteLine("After Context");
c#
.net
entity-framework
asked on Stack Overflow Sep 19, 2019 by Moretti

2 Answers

0

You must use exactly the same .NET Core, ASP.NET Core, and EF Core preview version. Make sure all packages from dotnet or aspnet are rc1 as for now. If some dependencies (including direct and indirect) in your project depend on any 2.2 packages that are from dotnet or aspnet and has a 3.0 new version, reference them as 3.0 rc1 version from your own project explicitly.

answered on Stack Overflow Sep 20, 2019 by Alsein
0

You must wait for a .NET Core 3 compatible version of the Pomelo provider.

answered on Stack Overflow Sep 21, 2019 by ErikEJ

User contributions licensed under CC BY-SA 3.0