dotnet / efcore

EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations.
https://docs.microsoft.com/ef/
MIT License
13.8k stars 3.2k forks source link

Problem with EntityFramework.Relational assembly #4617

Closed pantonis closed 2 years ago

pantonis commented 8 years ago

Hi,

I'm trying to run

"Scaffold-Dbcontext EntityFramework.SqlServer -connection "Data Source=Admin;Initial Catalog=TestDB;Integrated Security=True" -ContextClassName TestContext"

And I get:

System.IO.FileLoadException: Could not load file or assembly 'EntityFramework.Relational, Version=7.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) File name: 'EntityFramework.Relational, Version=7.0.0.0, Culture=neutral, PublicKeyToken=null' at System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type) at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext) at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments) at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg) at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent) at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeAssembly assembly, RuntimeType caType) at System.Reflection.RuntimeAssembly.GetCustomAttributes(Type attributeType, Boolean inherit) at System.Attribute.GetCustomAttributes(Assembly element, Type attributeType, Boolean inherit) at System.Attribute.GetCustomAttribute(Assembly element, Type attributeType, Boolean inherit) at System.Reflection.CustomAttributeExtensions.GetCustomAttribute[T](Assembly element) at Microsoft.Data.Entity.Design.Internal.DesignTimeServicesBuilder.GetProviderDesignTimeServices(String provider, Boolean throwOnError) at Microsoft.Data.Entity.Design.Internal.DesignTimeServicesBuilder.Build(String provider) at Microsoft.Data.Entity.Design.DatabaseOperations.ReverseEngineerAsync(String provider, String connectionString, String outputDir, String dbContextClassName, List1 schemas, List1 tables, Boolean useDataAnnotations, CancellationToken cancellationToken) at Microsoft.Data.Entity.Design.OperationExecutor.d19.MoveNext() at System.Linq.Buffer1..ctor(IEnumerable1 source) at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source) at Microsoft.Data.Entity.Design.OperationExecutor.OperationBase.<>cDisplayClass4_0`1.b__0() at Microsoft.Data.Entity.Design.OperationExecutor.OperationBase.Execute(Action action)

Could not load file or assembly 'EntityFramework.Relational, Version=7.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

bricelam commented 8 years ago

Could you also post any relevant fusion logs?

pantonis commented 8 years ago

Tried to run the tool but no logs.

lajones commented 8 years ago

Note: EntityFramework.SqlServer, v7.0.0 was renamed to Microsoft.EntityFrameworkCore.SqlServer v 1.0.0 a while back - what build are you running with?

pantonis commented 8 years ago

`

`

lajones commented 8 years ago

That looks OK. I think @bricelam is right - we need the logs. In the GAC can you make sure HKLM\Software\Microsoft\Fusion\ForceLog is set to 1 before you run Fusion? Also can you make sure you run it as an admin user? The message The located assembly's manifest definition does not match the assembly reference makes me think that, rather than not being able to find EntityFramework.Relational at all, you are picking up an incorrect version of EntityFramework.Relational from somewhere.

pantonis commented 8 years ago

This is output from Fusion:

*** Assembly Binder Log Entry  (22/02/2016 @ 21:03:50) ***

The operation was successful.
Bind result: hr = 0x0. The operation completed successfully.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: DisplayName = EntityFramework.Relational, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
 (Fully-specified)
LOG: Appbase = file:///C:/Users/Account1/Documents/Visual Studio 2015/Projects/ClassLibrary1/ClassLibrary1/bin/Debug/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = devenv.exe
Calling assembly : EntityFramework.Commands, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\Account1\AppData\Local\Microsoft\VisualStudio\14.0\devenv.exe.config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Binding succeeds. Returns assembly from C:\Users\Account1\AppData\Local\assembly\dl3\XPGC1XT9.AYK\QZ35W7P7.B6T\56d68490\b9f07262_666dd101\EntityFramework.Relational.dll.
LOG: Assembly is loaded in default load context.
lajones commented 8 years ago

This line:

LOG: Binding succeeds. Returns assembly from C:\Users\Account1\AppData\Local\assembly\dl3\XPGC1XT9.AYK\QZ35W7P7.B6T\56d68490\b9f07262_666dd101\EntityFramework.Relational.dll

looks suspicious. Can you keep a copy of that DLL somewhere well outside of where VS would look for it and then delete it from that location? Then try again and see if it picks up the correct EntityFramework.Relational.dll this time.

pantonis commented 8 years ago

Did what you suggested. Still the same error.

rowanmiller commented 8 years ago

Probably related to the mix of versions, the beta8 version of SQL Server provider is being mixed with RC1 versions of everything else. Things were not strong named in Beta8 and they are in RC1.

Can you uninstall EntityFramework.SqlServer (7.0.0-beta8) and install EntityFramework.MicrosoftSqlServer (7.0.0-rc1-final).

pantonis commented 8 years ago

Excellent. That did the trick!!!

Thanks a lot guys!