PomeloFoundation / Pomelo.EntityFrameworkCore.MySql

Entity Framework Core provider for MySQL and MariaDB built on top of MySqlConnector
MIT License
2.71k stars 384 forks source link

FileNotFoundException on refering System.Runtime.InteropServices at runtime #174

Closed Shavakan closed 7 years ago

Shavakan commented 7 years ago

Steps to reproduce

Any attempt to query DbContext triggers my issue.

The issue

The exception I am seeing:

Exception message: Exception thrown: 'System.IO.FileNotFoundException' in Microsoft.EntityFrameworkCore.dll
Additional information: Could not load file or assembly 'System.Runtime.InteropServices.RuntimeInformation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
Stack trace:
   at: MySql.Data.Serialization.ConnectionSettings..ctor(MySqlConnectionStringBuilder csb)
   at: MySql.Data.MySqlClient.MySqlConnection.set_ConnectionString(String value)
   at: MySql.Data.MySqlClient.MySqlConnection..ctor(String connectionString)
   at: Microsoft.EntityFrameworkCore.Storage.Internal.MySqlRelationalConnection.get_DbConnection()
   at: Microsoft.EntityFrameworkCore.Storage.Internal.MySqlRelationalConnection.Open()
   at: Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable.Enumerator.BufferlessMoveNext(Boolean buffer)
   at: Microsoft.EntityFrameworkCore.Storage.Internal.NoopExecutionStrategy.Execute[TState,TResult](Func`2 operation, Func`2 verifySucceeded, TState state)
   at: Microsoft.EntityFrameworkCore.ExecutionStrategyExtensions.Execute[TState,TResult](IExecutionStrategy strategy, Func`2 operation, TState state)
   at: Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable.Enumerator.MoveNext()
   at: Microsoft.EntityFrameworkCore.Query.QueryMethodProvider.<_ShapedQuery>d__3`1.MoveNext()
   at: Microsoft.EntityFrameworkCore.Query.Internal.MySqlQueryingEnumerable`1.MySqlEnumerator.MoveNext()
   at: Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.<_TrackEntities>d__15`2.MoveNext()
   at: Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.MoveNext()
   at: System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at: System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at: # Here comes the Fluent API statement I wrote to query my dataset, all the way up to web controller

Of course the HintPath is correctly stated in .csproj, and the dll (that HintPath points to) is present in {solutionDir}/packages/ .

Further technical details

MySQL version: mariadb 10.2.0 Operating system: Windows 7 x64 Pomelo.EntityFrameworkCore.MySql version: 1.1.0

Other details about my project setup: Target framework: .NET Framework 4.6.1

The only NuGet packages installed are:

I first experienced this issue in an attempt to migrate my existing code base from NHibernate. At first I thought this was due to some dependency collision, so I decided to start a new project. On a fresh new solution, I moved only the source codes and installed packages stated above from scratch (instead of trying to replace NHibernate dependencies & references), but the problem consists.

I looks mysterious to me why a seemingly existing file is reported to be absent. Please inspire me if I'm missing something. Thanks.

caleblloyd commented 7 years ago

What version of tooling are you using? dotnet --version

Can you upload a simple program including .Csproj, Program.cs, Startup.cs, and DbContext to a new GitGub repository or Gist? I think we will need these to recreate.

At first sight this seems to be an issue with the Csproj or MsBuild tools you are on.

caleblloyd commented 7 years ago

Also, can you try the latest prerelease Pomelo.EntityFrameworkCore.MySq 1.1.1-*, we've made some changes to dependencies since 1.1.0

yukozh commented 7 years ago

What is your VS version? MSBuild in vs2017 has a bad support for .net core. We suggest you use Roslyn to build .net core project.

yukozh commented 7 years ago

@caleblloyd I think we should add VS version into github issue template.

Shavakan commented 7 years ago

I'm using VS 2015 Community edition Version 14.0.25431.01 Update 3, and dotnet --version shows 1.0.0-preview2-003133

I have tried installing the latest prerelease 1.1.1 version, but the same error persists with a different binary: System.Collections.Immutable, Version=1.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

I'll come back once I write the program that recreates the issue (in a version that I can publish!).

caleblloyd commented 7 years ago

My recommendation is to use VS 2017 RC to upgrade to the latest MSBuild, it interacts better when you are using .NET Core enabled libraries with NET 4.* projects.

Install the ".NET Core and Docker (Preview)" component for VS 2017 RC and it will add the dotnet CLI Preview4 tooling, which will allow you to dotnet restore msbuild projects from the command line.

yukozh commented 7 years ago

No, I've tried vs2017 it will cause many conflicts when you building .net core project with full .net framework. MSBuild in vs2017 is still in alpha version, it is very unstable so I have downgraded to vs2015.

yukozh commented 7 years ago

@Shavakan coyld you show me your project.json

caleblloyd commented 7 years ago

@Kagamine there's definitely some issues to work through once you switch to VS 2017. I have converted a .NET 4.6.2 project over to it though and have it fully working with Kestrel, MVC6, and Pomelo.EntityFrameworkCore.MySql while still providing the full .NET 4.6.2 framework, so it's possible...

sm-g commented 7 years ago

I have similar issue, but stacktrace differs:

   в MySql.Data.Utility.IsWindows()
   в MySql.Data.Serialization.ConnectionSettings..ctor(MySqlConnectionStringBuilder csb)
   в MySql.Data.MySqlClient.MySqlConnection.set_ConnectionString(String value)
   в MySql.Data.MySqlClient.MySqlConnection..ctor(String connectionString)
   в Microsoft.EntityFrameworkCore.Storage.Internal.MySqlRelationalConnection.get_DbConnection()
   в Microsoft.EntityFrameworkCore.Storage.Internal.MySqlRelationalConnection.<OpenAsync>d__39.MoveNext()

WCF service on .net 4.6.1, latest VS 2017

yukozh commented 7 years ago

@sm-g Could you please provide us a repro project, and more information about this issue?

sm-g commented 7 years ago

I was trying to reproduce, creating step by step copy of my working solution. Finally I notice, that in fresh solution there is in web.config:

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

which solves the issue.

ruibarbosareb commented 7 years ago

I have Some Problem

System.BadImageFormatException
   em MySql.Data.Utility.IsWindows()
   em MySql.Data.Serialization.ConnectionSettings..ctor(MySql.Data.MySqlClient.MySqlConnectionStringBuilder)
   em MySql.Data.MySqlClient.MySqlConnection.set_ConnectionString(System.String)
   em MySql.Data.MySqlClient.MySqlConnection..ctor(System.String)
   em Microsoft.EntityFrameworkCore.Storage.Internal.MySqlConnectionSettings+<>c__DisplayClass2_0.<GetSettings>b__0(System.String)
   em System.Collections.Concurrent.ConcurrentDictionary`2[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].GetOrAdd(System.__Canon, System.Func`2<System.__Canon,System.__Canon>)

how did you solve it?

I have a project Win Forms -> net461, which references another netcore2 project.

http://prntscr.com/ghskfg