1

I'm in the process of creating a proof on concept solution that will have a shared project using Entity Framework. I would like the shared project to be referenced by a UWP project and also by a .Net Core website. I was able to get the Website referencing the project and using Entity Framework Core correctly. When I try to get the UWP app to use the same code, it compiles, but fails at run time. I've also tried changing the frameworks around using NetStandard1.4 and NetStandard1.6 but then the Entity Framework Core doesn't work correctly.

My shared project is a .Net Core class library (not an actual Shared Project type in VS).

Here's the error that I get when I run the UWP application. It occurs when I try to create a new Context class that inherits from DbContext:

An exception of type 'System.IO.FileLoadException' occurred in mscorlib.ni.dll but was not handled in user code

Additional information: Could not load file or assembly 'System.Runtime, Version=4.1.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)

Here's the project.json that I have for the shared project.

{
  "version": "1.0.0-*",

  "dependencies": {
    "Microsoft.EntityFrameworkCore.Sqlite": "1.0.0",
    "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
    "NETStandard.Library": "1.6.0",
    "System.ComponentModel.Annotations": "4.1.0",
    "Microsoft.NETCore.App": {
      "version": "1.0.0",
      "type": "platform"
    }
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dotnet5.6",
        "portable-net45+win8"
      ]
    }

  }
}

Here's the project.json for the UWP project

{
  "dependencies": {
    "Microsoft.EntityFrameworkCore.Sqlite": "1.0.0",
    "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
    "Microsoft.NETCore.UniversalWindowsPlatform": "5.2.2"
  },
  "frameworks": {
    "uap10.0": {
      "imports": [
        "netcoreapp1.0"
      ]
    }
  },
  "runtimes": {
    "win10-arm": {},
    "win10-arm-aot": {},
    "win10-x86": {},
    "win10-x86-aot": {},
    "win10-x64": {},
    "win10-x64-aot": {}
  }
}

Here's the project.json for the website project

{
  "dependencies": {
    "Domain": "1.0.0-*",
    "Microsoft.AspNetCore.Diagnostics": "1.0.0",
    "Microsoft.AspNetCore.Mvc": "1.0.0",
    "Microsoft.AspNetCore.Razor.Tools": {
      "version": "1.0.0-preview2-final",
      "type": "build"
    },
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
    "Microsoft.AspNetCore.StaticFiles": "1.0.0",
    "Microsoft.EntityFrameworkCore.Sqlite": "1.0.0",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",
    "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.Extensions.Logging": "1.0.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Extensions.Logging.Debug": "1.0.0",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
    "Microsoft.NETCore.App": {
      "version": "1.0.0",
      "type": "platform"
    },
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0"
  },

  "tools": {
    "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
    "BundlerMinifier.Core": "2.0.238",
    "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dotnet5.6",
        "portable-net45+win8"
      ]
    }
  },

  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },

  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true
    }
  },

  "publishOptions": {
    "include": [
      "wwwroot",
      "Views",
      "Areas/**/Views",
      "appsettings.json",
      "web.config"
    ]
  },

  "scripts": {
    "prepublish": [ "bower install", "dotnet bundle" ],
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }
}
3
  • It cannot be resolved out just by the json file. What is "netcoreapp1.0", did this is your shared project? What type of this shared project? A runtime component? If you can build successfully, could you please debug where the exception throw? Commented Sep 9, 2016 at 8:06
  • I'm not sure how to explain notcoreapp1.0 but I found more info on stackoverflow question: link. Ii'll edit my post with the additional information you asked. Commented Sep 9, 2016 at 13:29
  • Hi! Which type of project did you use in order to separate EFCore? Thanks! Here is inclear what todo github.com/aspnet/EntityFrameworkCore/issues/9672 Commented Feb 18, 2019 at 4:06

2 Answers 2

0

I'm not sure if UWP projects work well with .NET Core projects. Maybe you could try changing your EF project to a Portable Class Library project.

Sign up to request clarification or add additional context in comments.

Comments

0

I figured it out, please see the answer from Brice Lambson on GitHub

2 Comments

("Inlined" the answer.)
You can mark @bricelam's reply as answer to end up this thread.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.