0

I am trying to reference a .NET 4.6 assembly from my ASP.NET 5 project. I'm running ASP.NET and Web Tools 2015 (RC1 Update 1).

I've read the following question but could not get it to work: ASP.NET 5 Application Reference .NET 4.6 DLL

I've also read the following question but I can't even get the project to build: Referencing a .NET 4.6 project from ASP.NET 5 causes build error

When the target framework on the referenced assembly is set to 4.5.1, I can build and run the application but as soon as the target framework on the referenced assembly is changed to 4.6, the compiler reports the following error:

"The type or namespace name 'ClassLibrary' could not be found (are you missing a using directive or an assembly reference?)"

Below are some of the sections of my project.json file where "ClassLibrary" is my referenced .Net 4.6 assembly.

"dependencies": {
  "Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
  "Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
  "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
  "Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
  "Microsoft.Extensions.Configuration.FileProviderExtensions" : "1.0.0-rc1-final",
  "Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final",
  "Microsoft.Extensions.Logging": "1.0.0-rc1-final",
  "Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",
  "Microsoft.Extensions.Logging.Debug": "1.0.0-rc1-final"
},

"commands": {
  "web": "Microsoft.AspNet.Server.Kestrel"
},

"frameworks": {
  "dnx46": {
    "dependencies": {
      "ClassLibrary": "1.0.0-*"
    }
  },
},
Janni Kajbrink
  • 661
  • 2
  • 7
  • 21
  • It did not help to change "dnx46" to "net46". I still get the same error. But as I stated in my original question, it all works if the target framework of the referenced library is changed to 4.5.1. – Janni Kajbrink May 09 '16 at 14:21

1 Answers1

0

In order to consume a .NET 4.6 library from within your DNX project, you need target the framework correctly. You're currently targeting dnx46 which is different than net46.

Change this:

"frameworks": {
  "dnx46": {
    "dependencies": {
      "ClassLibrary": "1.0.0-*"
    }
  }

to this:

"frameworks": {
  "net46": {
    "dependencies": {
      "ClassLibrary": "1.0.0-*"
    }
  }

Scott Allen has a great article on the DNX options here. Note, DNX is retiring and this will all change soon with .NET Core.

David Pine
  • 23,787
  • 10
  • 79
  • 107