Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when migrations are inside the webapp project #37

Closed
wh1sp3r opened this issue Mar 13, 2017 · 18 comments
Closed

Error when migrations are inside the webapp project #37

wh1sp3r opened this issue Mar 13, 2017 · 18 comments
Assignees
Labels

Comments

@wh1sp3r
Copy link

wh1sp3r commented Mar 13, 2017

Hello,
I have a problem with enabling migrations for my project.
After I wrote "dotnet ef migrations enable" into package console, it builds my project without any error and it shows an error that it's missing "Microsoft.DotNet.PlatformAbstractions, Version=1.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60". I installed this library, but there is no version 1.0.1, just 1.0.3+ ( latest 1.1.1 ). It's shows same error.

Also there is an error in console output: Build Failure. Error: 'path' cannot be an empty string ("") or start with the null character.
Parameter name: path

if I installed "Microsoft.DotNet.PlatformAbstractions" 1.0.3 (only version which shows different output), it says something about different assembly versions and then It ends with an error that it cannot find assembly ( my project ).

Thanks! :)

@mrahhal
Copy link
Owner

mrahhal commented Mar 13, 2017

Hello,

Are you still on project.json or are using the new tooling in VS 2017? Please check the README.md file. I'll quote the most important parts:


Looking for the project.json version?

Checkout the preview2 tree version of this repository.

Release notes

The 1.1.* releases align with .NET Core tooling 1.0.

1.1.0

This release is for tooling 1.0 and VS 2017 support.


The 1.0.* releases align with .NET Core tooling 1.0.0-preview2.

1.0.8

This release is for .Net Core 1.1.0


If you're on project.json, you should reference 1.0.8. If you're on csproj, you should reference 1.1.0. If you're still facing issues even after you resolve this, please put more info about what your platform is and what steps you followed.

@wh1sp3r
Copy link
Author

wh1sp3r commented Mar 13, 2017

Hi, I am currently using VS2017.

My steps:
I added a reference to Migrator.E6.Tools

<ItemGroup>
    <PackageReference Include="EntityFramework" Version="6.1.3" />
    <PackageReference Include="EPPlus" Version="4.1.0" />
    <PackageReference Include="Merz.Core" Version="1.0.4" />
    <PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="1.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
    <PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.1.1" />
    <PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="1.1.1" />
    <PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.1" />
    <PackageReference Include="Migrator.EF6.Tools" Version="1.1.0" PrivateAssets="All" />
</ItemGroup>

and I Created a new Itemgroup and added Migrator.EF6.Tools

<ItemGroup>
    <DotNetCliToolReference Include="Migrator.EF6.Tools" Version="1.1.0" />
</ItemGroup>

There is only one project in my solution and it is a Web core based on .NET Framework.
My Database Context is in Database Folder called DatabaseService and it also contains default constructor without parameters.

whole package output:

PM> dotnet ef migrations enable
Microsoft (R) Build Engine version 15.1.548.43366
Copyright (C) Microsoft Corporation. All rights reserved.
Merz.Ems.Olympic -> C:\Merz\Projekty\Tfs\BU EMS\─îesk├Ż olympijsk├Ż v├Żbor\Merz.Ems.Olympic\bin\Debug\net46\Merz.Ems.Olympic.exe
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:05.79

Nelze na´┐Ż´┐Żst soubor nebo sestaven´┐Ż Microsoft.DotNet.PlatformAbstractions, Version=1.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60 nebo jeden z jejich z´┐Żvisl´┐Żch prvk´┐Ż. Zji´┐Żt´┐Żn´┐Ż definice manifestu sestaven´┐Ż neodpov´┐Żd´┐Ż odkazu na sestaven´┐Ż. (V´┐Żjimka na z´┐Żklad´┐Ż hodnoty HRESULT: 0x80131040)

The last error is in Czech language saying It cannot find an assembly blablabla.

Output says:
Build started ...
Build Failure. Error: 'path' cannot be an empty string ("") or start with the null character.
Parameter name: path
========== Build: 0 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

PS: well, I installed it to really big project, so i will try it with a new project.

EDIT: I created a new clean project, Iinstalled EF6, Migrator and added clitool into project.
when I write dotnet ef migrations enable, it says No executable found :)

@mrahhal
Copy link
Owner

mrahhal commented Mar 13, 2017

It seems to be a problem with the new version that supports tooling 1.0. I'll make some time soon to look into this.

@mrahhal mrahhal self-assigned this Mar 13, 2017
@mrahhal mrahhal added the bug label Mar 13, 2017
@mrahhal
Copy link
Owner

mrahhal commented Mar 14, 2017

I confirmed this problem. This is only happening when the project has a dependency on Mvc it appears, which is a major blocker (I tested on a console app when I released that's why I didn't notice). I still have no idea what's going on though.

@mrahhal
Copy link
Owner

mrahhal commented Mar 14, 2017

@hikalkan are you not facing this problem? @Abdruggi?

@mrahhal
Copy link
Owner

mrahhal commented Mar 14, 2017

The problem is with the dependency on "PlatformAbstractions". Dispatching to the full .Net framework itself is not discussed or documented anywhere after 1.0. I might just be doing something wrong, but I doubt it. I understand that this is a major blocker.

I opened an issue with a repro on the cli repo for now: dotnet/cli#6028

@hikalkan
Copy link

In our solutions, we have a dedicated project (class library) for Entity framework dependency and it has no reference to Mvc. So, I don't have this problem @mrahhal

@mrahhal
Copy link
Owner

mrahhal commented Mar 14, 2017

@hikalkan thanks for your input. Moreover, I checked, and looks like the restriction that wouldn't allow core cli tools to run in class libraries in preview2 of tooling was removed, so that's super nice. @joshgarwood and @sagoo33 might be interested to know about this.

@wh1sp3r the only workaround I see right now is to put your migrations in a pure class library project that doesn't have a dependency on anything aspnetcore related. Actually, I have a big webapp running in production, and I think I'll try moving migrations from the webapp to the "models" project.

I think the reasonable thing to do right now is to recommend putting models + migrations in a separate pure class library project going forward.

@Abdruggi
Copy link
Contributor

Abdruggi commented Mar 14, 2017

@mrahhal I use separate projects for MVC and EF (console app, containing migrations and models). Therefore, I am not affected.

@mrahhal
Copy link
Owner

mrahhal commented Mar 14, 2017

@Abdruggi yeah looks like that's the only way to go for now. I actually just updated a project, simply moving the migrations folder and moving the "Migrator.EF6.Tools" dependency to that class library does it. It's nice that tools finally support class libraries with no workarounds.

@mrahhal mrahhal added wontfix and removed bug labels Mar 14, 2017
@mrahhal
Copy link
Owner

mrahhal commented Mar 14, 2017

Can't fix really. @wh1sp3r please try using a different class library for your migrations. If you're still facing problems after that feel free to open another issue.

@mrahhal mrahhal closed this as completed Mar 14, 2017
@mrahhal mrahhal changed the title dotnet ef migrations enable error Error when migrations are inside the webapp project Mar 14, 2017
@nphmuller
Copy link
Contributor

nphmuller commented Mar 20, 2017

So there's basically a dependency that has a reference to Microsoft.Extensions.PlatformAbstractions v1.0.1.0, but since there's no assembly binding version redirect to the latest version (for me v1.1.1) it crashes with a FileLoadException.

As a workaround you can create a binding redirect configuration in the build directory.

Create dotnet-ef.exe.config with the following content:
(And maybe change the versions if your actual dependecies have a version other than 1.1.0.)

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <runtime>
    <gcServer enabled="true" />
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.DotNet.PlatformAbstractions" publicKeyToken="adb9793829ddae60" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.1.1.0" newVersion="1.1.1.0" />
      </dependentAssembly>
    </assemblyBinding>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.AspNetCore.Identity" publicKeyToken="adb9793829ddae60" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.1.1.0" newVersion="1.1.1.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

Looking at the necessary redirects, the problem might lie somewhere in Microsoft.AspNetCore.Identity, but I haven't looked into the issue far enough to be sure.

Will add more info if I know more.

Update: See my later post for a perhaps easier workaround.

@mrahhal
Copy link
Owner

mrahhal commented Mar 20, 2017

@nphmuller thanks! If you want you can add your findings at dotnet/cli#6028 which I opened to track the issue.

@nphmuller
Copy link
Contributor

@mrahhal I've added some additional details to the issue.
I'm not sure why the bindingredirect is not added automatically though, because that should happen anyway. Will look into it later.

@nphmuller
Copy link
Contributor

nphmuller commented Mar 21, 2017

As an easier to maintain workaround I currently just add a build target to my csproj file that copies the .config file from my main assembly:

<!-- Workaround for Migrator.EF6 assembly version binding problem. See: https://github.com/mrahhal/Migrator.EF6/issues/37/ -->
<Target Name="ToolingAssemblyBinding" AfterTargets="Build">
  <Copy SourceFiles="$(OutputPath)$(AssemblyName).exe.config" DestinationFiles="$(OutputPath)dotnet-ef.exe.config" />
</Target>

@wh1sp3r
Copy link
Author

wh1sp3r commented Mar 22, 2017

Hi, working around is working !

I just have a last problem. if my project is set to AnyCPU, migrations are working fine but Kestrel is not working ( BadImageFormatException). If i set my project to x86, kestrel is working, but migrations are not becuase BadImageFormatException: cannot load my project.

@mrahhal
Copy link
Owner

mrahhal commented Mar 22, 2017

@wh1sp3r please open other issues for other problems. That said, I don't think this is a problem with this project.

@tuespetre
Copy link

Thanks @nphmuller!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants