ASP.NET CORE 1.0: Multiple Frameworks Target Issues


The Core ASP.NET had several changes after being updated from RC1 to RC2 version. Now, after creating a new ASP.NET Core Web Application (.NET Core), only the .NET CORE (netcoreapp1.0) is added by default.

core

 

To add full .NET Framework into the project, you must include a reference to it, through the project.json configuration file, as:

“frameworks”: {
“netcoreapp1.0″: {
“imports”: [
“dotnet5.6″,
“dnxcore50″,
“portable-net45+win8″
],
“dependencies”: {
“Microsoft.NETCore.App”: {
“version”: “1.0.0-rc2-3002702″,
“type”: “platform”
}
}
},
    “net461″: { }
},

However, after saving the changes, the following error will be generated:

error NU1002: The dependency System.Runtime.Loader 4.0.0-rc2-24027 does not support framework .NETFramework,Version=v4.6.1.

 

erro

 

This error occurs because the dependence Microsoft.NETCore.App is not compatible with FULL version of the .NET Framework. To eliminate the error, you must open the project.json file and move the Microsoft.NETCore.App dependency out of “dependencies”:

dep

 

Into a new “dependencies” section under the “netcoreapp1.0” key in “frameworks”, as:

“frameworks”: {
“netcoreapp1.0″: {
“imports”: [
“dotnet5.6″,
“dnxcore50″,
“portable-net45+win8“],
      “dependencies”: {
        “Microsoft.NETCore.App”: {
          “version”: “1.0.0-rc2-3002702″,
          “type”: “platform”
        }
}
},
“net461″: { }
},

 

I hope have helped.

Comments (16)

  1. Mohsen Afshin says:

    Thank your for the tip

  2. nikola schou says:

    I get this error "error NU1002: The dependency System.Runtime.Loader 4.0.0-rc2-24027 does not support framework .NETFramework,Version=v4.6." as you describe but still it is not working.

    I only build for net46 (I exclude netcoreapp1.0) so inspired by this article I remove this dependency entirely:
    "Microsoft.NETCore.App": {
    "version": "1.0.0-rc2-3002702",
    "type": "platform"
    },
    However, this gives me lots of other errors such as "error CS0246: The type or namespace name 'IActionResult' could not be found (are you missing a using directive or an assembly reference?)"

    What am I missing?

    1. Hi Nikola,
      It is hard to know without the full code. But, take a look at the global.json (file inside the "solutions items" folder of VS). Double-check if the file is point to the last version of .NET Core.

      "sdk": {
      "version": "1.0.0-preview2-003121"
      }
      If the information is not confidential, you can send me the project.json.

  3. Sunny says:

    Hi Luis,
    Thanks so much for posting the solution!
    I've been stuck for such a long time until I find your article to at least be able to add a reference to my classic non-core class library from a .NET Core project.
    I don't have the exact same issue to start with, but using your solution, I was able to at least setup a .NET Core project targeting both ASP.NET and ASP.NET Core. In my case, I have a .NET Core Web Application, and I tried to reference my ASP.NET class library (non-core).
    Before reading your solution, I was not even able to add a reference to my asp.net class library. After using your solution. I was able to add my library and did see it in the reference list under .NET Framework 4.6.1.
    However, as I compiled the project, I got this error, Severity Code Description Project File Line Suppression State
    Error CS0246 The type or namespace name 'XXX' could not be found (are you missing a using directive or an assembly reference?) WebApplication1..NETCoreApp,Version=v1.0 C:\qs\proj\test\VS2015\WebApplication1\src\WebApplication1\Program.cs 6 Active
    where XXX is the name of my ASP.NET library.
    Also, as I hover my mouse over "Using XXX" in my class, I got a warning saying
    WebApplication1..NET Framework 4.6.1 - Available
    WebApplication1..NETCoreApp,Version=v1.0-Not Available
    I'm using Visual Studio 15 on Windows 10.
    It looks like I successfully added the reference to the library but when building, the project could not see it.
    Can you please help me out?
    Below is my project.json:
    {
    "dependencies": {
    "Microsoft.ApplicationInsights.AspNetCore": "1.0.0",
    "Microsoft.AspNetCore.Diagnostics": "1.0.0",
    "Microsoft.AspNetCore.Mvc": "1.0.1",
    "Microsoft.AspNetCore.Razor.Tools": {
    "version": "1.0.0-preview2-final",
    "type": "build"
    },
    "Microsoft.AspNetCore.Routing": "1.0.1",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
    "Microsoft.AspNetCore.StaticFiles": "1.0.0",
    "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.VisualStudio.Web.BrowserLink.Loader": "14.0.0"
    },

    "tools": {
    "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",
    "dnxcore50",
    "portable-net45+win8"
    ],
    "dependencies": {
    "Microsoft.NETCore.App": {
    "version": "1.0.0",
    "type": "platform"
    }
    }
    },
    "net461": {
    "dependencies": {
    "TCShipping": "1.0.0"
    }
    }
    },

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

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

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

    "scripts": {
    "prepublish": [ "bower install", "dotnet bundle" ],
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
    }
    }

  4. Squid16 says:

    Hi Luis,
    Thanks so much for posting the solution!
    I've been stuck for such a long time until I find your article to at least be able to add a reference to my classic non-core class library from a .NET Core project.
    I don't have the exact same issue to start with, but using your solution, I was able to at least setup a .NET Core project targeting both ASP.NET and ASP.NET Core. In my case, I have a .NET Core Web Application, and I tried to reference my ASP.NET class library (non-core).
    Before reading your solution, I was not even able to add a reference to my asp.net class library. After using your solution. I was able to add my library and did see it in the reference list under .NET Framework 4.6.1.
    However, as I compiled the project, I got this error, Severity Code Description Project File Line Suppression State
    Error CS0246 The type or namespace name 'XXX' could not be found (are you missing a using directive or an assembly reference?) WebApplication1..NETCoreApp,Version=v1.0 C:\qs\proj\test\VS2015\WebApplication1\src\WebApplication1\Program.cs 6 Active
    where XXX is the name of my ASP.NET library.
    Also, as I hover my mouse over "Using XXX" in my class, I got a warning saying
    WebApplication1..NET Framework 4.6.1 - Available
    WebApplication1..NETCoreApp,Version=v1.0-Not Available
    I'm using Visual Studio 15 on Windows 10.
    It looks like I successfully added the reference to the library but when building, the project could not see it.
    Can you please help me out?
    Below is my project.json:
    {
    "dependencies": {
    "Microsoft.ApplicationInsights.AspNetCore": "1.0.0",
    "Microsoft.AspNetCore.Diagnostics": "1.0.0",
    "Microsoft.AspNetCore.Mvc": "1.0.1",
    "Microsoft.AspNetCore.Razor.Tools": {
    "version": "1.0.0-preview2-final",
    "type": "build"
    },
    "Microsoft.AspNetCore.Routing": "1.0.1",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
    "Microsoft.AspNetCore.StaticFiles": "1.0.0",
    "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.VisualStudio.Web.BrowserLink.Loader": "14.0.0"
    },

    "tools": {
    "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",
    "dnxcore50",
    "portable-net45+win8"
    ],
    "dependencies": {
    "Microsoft.NETCore.App": {
    "version": "1.0.0",
    "type": "platform"
    }
    }
    },
    "net461": {
    "dependencies": {
    "TCShipping": "1.0.0"
    }
    }
    },

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

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

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

    "scripts": {
    "prepublish": [ "bower install", "dotnet bundle" ],
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
    }
    }

    1. Hi, thanks for the feedback.
      So, ASP.NET Core allows you to choose the .NET Framework that you wants to use (.NET FRAMEWORK FULL - that runs on Windows OR .NET CORE - Cross Platform version). Observe that the .NET Framework Full has about 200MB while the .NET CORE has about 20MB. That is why most of the libraries are not compatible with .NET CORE yet.
      I believe that you are using both of the frameworks while developing. In this case, I believe that you are referring components that are incompatible with the .NET Standard Libraries (base of .NET Core). Maybe is better keeping only the .NET Full Framework as reference.
      Regards

      1. Squid says:

        Hi Luis,
        Thanks for the reply!
        I commented out the below netcoreapp1.0 from the framework section in my package.json, and it works.
        “netcoreapp1.0”: {
        “imports”: [
        “dotnet5.6”,
        “dnxcore50”,
        “portable-net45+win8”
        ],
        “dependencies”: {
        “Microsoft.NETCore.App”: {
        “version”: “1.0.0”,
        “type”: “platform”
        }
        }
        }
        But when i clicked on the References section in Visual Studio now, only the ".NET Framework 4.6.1" is listed. The ".NETCoreApp,Version=1.0" was removed. Both of them were there before.
        Can you please let me know if removing .Net Core entry from the frameworks section means that my project is no longer a .NET core Web Application project but, is, instead, just a .NET Web Application project?
        Thanks!

        1. Squid says:

          Hi Luis,
          I have a more general question.
          In your comments, you stated, "Observe that the .NET Framework Full has about 200MB while the .NET CORE has about 20MB. That is why most of the libraries are not compatible with .NET CORE yet." Do you know if Microsoft will or has any plan to make most/all of the .NET Framework Full compatible with .NET CORE? If not, then does it mean we cannot have a .NET Core cross platform project that can reference non-core libraries/projects that use libraries that are not compatible with .NET CORE and fall outside of the 20MB .NET Core framework? Does it also mean we have to find equivalent libraries for the .NET Framework Full in the .NET CORE framework? But since the later is smaller (only 20MB), it does not look like this is doable, which leads it right back to your original comment,"Observe that the .NET Framework Full has about 200MB while the .NET CORE has about 20MB. That is why most of the libraries are not compatible with .NET CORE yet." I'm just wondering because there's a "yet" at the end of your statement...:)
          Thanks for your time!

          1. Squid says:

            Hello Luis,
            Back to my general question, I have a Xamarin project (using visual studio 2015), from which i can reference my same .NET library(none core) without any issue and without having to make any additional configuration changes to the project settings. I really hope we can do the same from a .NET Core projects.
            Thanks!

  5. Great question Squid.
    QUICK ANSWER: No, your project still be a ASP.NET CORE but, the application will use the .NET FRAMEWORK FULL that runs only on Windows.

    Nowadays, there are two models of Web development: ASP.NET Web Applications and ASP.NET CORE (.NET Framework Full or .NET CORE).
    The first model (ASP.NET Web App), is the traditional model that is based on System.Web.dll to implement the main functionalities (MVC, WebForms, WebAPI, WCF). In this model, we have for example, the global.asax, web.config, bundling, and so on.

    Talking about the second model (ASP.NET CORE), everything have changed. The model does not implement all the pipeline inside System.Web.dll for example. When you create a empty project, the request pipeline only knows how to return a text. It depends on you to specify the middleware (MVC, StaticFiles, logs, etc). And all that packages are added in this model as Nuget Packages. We have now a wwwroot folder inside the project. You don't need to have the IIS if you don't want (but if you are using Windows it is strongly recommended to keep).
    Using this second model, you can opt to use the .NET FULL FRAMEWORK or .NET CORE. You were using both versions to develop, but in time of deployment, you will need to choose the framework that you will use. Note that the .NET CORE is cross-platform, and for example, we don't have Event Viewer class to log the events. We don't have performance counters.

    For more details, the oficial documentation is: https://docs.microsoft.com/en-us/aspnet/core/

    Feel free to send me any question.

    Regards,

    1. Squid says:

      Hi Luis,
      I understand why we need cross-platform features for windows phone, iphone, and android, but i still dont see the need for it for Web Applications other than which host system we are to deploy our web applications on. Please let me know if I'm missing anything..
      I'm newbie to both ASP.NET and ASP.NET Core.
      By the way, Many many Thanks again for your feedback. Time is valuable, so i really appreciate your taking time reading my questions and answering my them! I have been stuck for a long time until i found you!!! Finally you helped me resolve my "core referencing non-core" issue! I read github and stackoverflow but still could not solve the problem... I'm wondering if you can also help me get to the right resource to learn the right way for consuming web services from .NET CORE projects.
      Prior to the addition of .NET CORE, from a classical .NET class library(non-core), i can use "add service reference" to consume a web service from a provided wsdl file.
      Now from a .NET Core class library, this option is not even available. I had to download Visual Studio WCF Connected Service from https://marketplace.visualstudio.com/items?itemName=erikcai-MSFT.VisualStudioWCFConnectedService in order to do the same thing. However, this approach did not work completely. It lets me add the web service reference, but i could not see any methods. For example i can only see the request and response object. I could not reference the method to send requests and receive responses.
      Further, "Visual Studio WCF Connected Service " is not even available for Visual Studio 2017.
      Can you please advise on the proper ways to consume a web service (rest, soap) from a .net core project?
      Thanks so much for all of your time!

  6. Marc Pike says:

    Very helpful. Thanks!

    1. Thank you Marc.
      I'm glad to had helped.
      Regards

      1. Marc Pike says:

        Only Issue I have now is with the Controller trying to call my class library which is a Data Access Layer to my Mongo database. Even though I added it as a "net461" dependency I cannot seem to use in any of my Controllers. My project.json looks like this:

        {
        "dependencies": {
        //"Microsoft.NETCore.App": {
        // "version": "1.1.0",
        // "type": "platform"
        //},
        "Microsoft.AspNetCore.Diagnostics": "1.1.0",
        "Microsoft.AspNetCore.Mvc": "1.1.0",
        "Microsoft.AspNetCore.Razor.Tools": {
        "version": "1.0.0-preview2-final",
        "type": "build"
        },
        "Microsoft.AspNetCore.Mvc.Formatters.Json": "1.1.0",
        "Microsoft.AspNetCore.Server.IISIntegration": "1.1.0",
        "Microsoft.AspNetCore.Server.Kestrel": "1.1.0",
        "Microsoft.AspNetCore.SpaServices": "1.1.0-*",
        "Microsoft.AspNetCore.StaticFiles": "1.1.0",
        "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.1.0",
        "Microsoft.Extensions.Configuration.Json": "1.1.0",
        "Microsoft.Extensions.Configuration.CommandLine": "1.1.0",
        "Microsoft.Extensions.Logging": "1.1.0",
        "Microsoft.Extensions.Logging.Console": "1.1.0",
        "Microsoft.Extensions.Logging.Debug": "1.1.0",
        "Microsoft.Extensions.Options.ConfigurationExtensions": "1.1.0",
        "MongoDB.Driver": "2.4.1"
        },

        "tools": {
        "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
        "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final",
        "Microsoft.DotNet.Watcher.Tools": "1.0.0-preview2-final"
        },

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

        "frameworks": {
        "netcoreapp1.1": {
        "imports": [
        "dotnet5.6",
        "portable-net45+win8"
        ],
        "dependencies": {
        "Microsoft.NETCore.App": {
        "version": "1.1.0",
        "type": "platform"
        }
        }
        },
        "net461": {
        "dependencies": {
        "DAL.Quotes.Mongo": {
        "target": "project"
        }
        }
        }
        },
        "buildOptions": {
        "emitEntryPoint": true,
        "preserveCompilationContext": true,
        "compile": {
        "exclude": [ "node_modules" ]
        }
        },

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

        "publishOptions": {
        "include": [
        "appsettings.json",
        "ClientApp/dist",
        "Views",
        "web.config",
        "wwwroot"
        ],
        "exclude": [
        "wwwroot/dist/*.map"
        ]
        },

        "scripts": {
        "prepublish": [
        "npm install",
        "node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js --env.prod",
        "node node_modules/webpack/bin/webpack.js --env.prod"
        ],
        "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
        },

        "tooling": {
        "defaultNamespace": "CrmWebapp"
        }
        }

        So close, but perhaps I will have to create a separate WinApi project and call it from my Angular 2 app. Bummer, since this adds another layer.

        1. You have two ways to fix that.
          The first one, is change the target framework at the dropdown that is available in the left up side of the controller class.
          The other one, is to remove the netcoreapp1.1 framework and working only with the full framework. In this case you should remove the following code:

          “netcoreapp1.1”: {
          “imports”: [
          “dotnet5.6”,
          “portable-net45+win8”
          ],
          “dependencies”: {
          “Microsoft.NETCore.App”: {
          “version”: “1.1.0”,
          “type”: “platform”
          }
          }
          },

          In this case, you will develop using the new structure of solution but the framework will be the Full Framework.

          1. Marc Pike says:

            Beautiful! After going down a different rabbit hole of trying to create a Portable Class Library (which didn't work) I came back to this thread and chose option #2. Other than some pesky System.IO exceptions at startup I am able to reach all my required projects! Since we are running only on Windows servers this solution is perfect. Thanks Luis!

Skip to main content