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

UWP commands: generate binding redirects #5471

Closed
natemcmaster opened this issue May 23, 2016 · 4 comments
Closed

UWP commands: generate binding redirects #5471

natemcmaster opened this issue May 23, 2016 · 4 comments
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug

Comments

@natemcmaster
Copy link
Contributor

natemcmaster commented May 23, 2016

Because UWP commands use netcore50 assemblies but actually execute on net451, we can run into issues with assembly versions.

Example error:

PS > Add-Migration Test
System.IO.FileLoadException: Could not load file or assembly 'System.IO.FileSystem.Primitives, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'System.IO.FileSystem.Primitives, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
   at Microsoft.EntityFrameworkCore.Migrations.Design.MigrationsScaffolder.Save(String projectDir, ScaffoldedMigration migration, String outputDir)
   at Microsoft.EntityFrameworkCore.Design.MigrationsOperations.AddMigration(String name, String outputDir, String contextType)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigration.<>c__DisplayClass0_1.<.ctor>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)

Other examples:

Solution

We need to generate binding redirects so UWP tooling can get the right assembly versions

Workaround

Users can manually generate these. Add a file named "app.config" to the UWP project to explicitly redirect to the right assembly versions.

<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.IO.FileSystem.Primitives"
                          publicKeyToken="b03f5f7f11d50a3a"
                          culture="neutral" />
        <bindingRedirect oldVersion="4.0.0.0"
                         newVersion="4.0.1.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Threading.Overlapped"
                          publicKeyToken="b03f5f7f11d50a3a"
                          culture="neutral" />
        <bindingRedirect oldVersion="4.0.0.0"
                         newVersion="4.0.1.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.ComponentModel.Annotations"
                          publicKeyToken="b03f5f7f11d50a3a"
                          culture="neutral" />
        <bindingRedirect oldVersion="4.1.0.0"
                         newVersion="4.0.0.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>
@StuartSmith
Copy link

StuartSmith commented Sep 30, 2016

see issue 6551 for solution by Librazy

@sjb-sjb
Copy link

sjb-sjb commented Oct 3, 2016

The UWP / SQLite getting started page (http://ef.readthedocs.io/en/latest/platforms/uwp/getting-started.html) should be updated to show that redirects for EF core 1.0.0 must be included in the App.config file. In addition, when I tried it the demo required "using EFGetStarted.UWP;" in MainPage.xaml.cs and App.xaml.ca

The necessary redirects (from Librazy's solution) are:

  <dependentAssembly>
    <assemblyIdentity name="Microsoft.EntityFrameworkCore" publicKeyToken="adb9793829ddae60" culture="neutral" />
    <bindingRedirect oldVersion="1.0.0.0" newVersion="1.0.1.0"/>
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="Microsoft.EntityFrameworkCore.Relational" publicKeyToken="adb9793829ddae60" culture="neutral" />
    <bindingRedirect oldVersion="1.0.0.0" newVersion="1.0.1.0"/>
  </dependentAssembly>

@rowanmiller rowanmiller removed this from the 1.1.0 milestone Oct 17, 2016
@divega divega modified the milestones: 1.1.0, 1.2.0, 1.1.0-preview1 Oct 17, 2016
@divega
Copy link
Contributor

divega commented Oct 17, 2016

Bringing back to 1.1.0-preview1. I made a comment on the PR at https://github.com/aspnet/EntityFramework.Tools/pull/12/files#r83714506 but I fogot github doesn't send it now until you publish a review and apparently I didn't submit it on time for it to be considered.

I suspect the stopgap fix is missing some important issues we were trying to fix for 1.1.0-preview1.

@bricelam bricelam removed this from the 1.1.0-preview1 milestone Oct 18, 2016
@rowanmiller rowanmiller modified the milestones: 1.1.0-preview1, 1.2.0, 1.1.0 Oct 19, 2016
@rowanmiller rowanmiller modified the milestones: 1.2.0, 1.1.0 Nov 1, 2016
@bricelam bricelam added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Nov 4, 2016
@bricelam
Copy link
Contributor

bricelam commented Nov 8, 2016

By hooking AppDomain.AssemblyResolve, we're able to remove the need to add binding redirects.

@bricelam bricelam closed this as completed Nov 8, 2016
bricelam added a commit to aspnet/EntityFramework.Tools that referenced this issue Nov 9, 2016
Notable changes:
* Remove Use-DbContext
* Allow -From and -To as positional arguments on Script-Migration
* Remove support for xproj
* Remove --config option from ef.exe
* Hook AppDomain.AssemblyResolve when --no-appdomain

Resolves dotnet/efcore#5471, resolves dotnet/efcore#6916

# Conflicts:
#	src/Microsoft.EntityFrameworkCore.Tools.DotNet/project.json
#	src/Microsoft.EntityFrameworkCore.Tools/project.json
#	src/Microsoft.EntityFrameworkCore.Tools/tools/EntityFrameworkCore.psm1
@bricelam bricelam modified the milestones: 1.2.0, tools-1.0.0 Nov 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Projects
None yet
Development

No branches or pull requests

6 participants