New ASP.NET 5 preview project fails to run - asp.net-core

I created a new ASP.NET 5 preview project in VS 2015 RTM (fully updated). When I try to debug it, it fails with the following exception:
The current runtime target framework is not compatible with
'ProjectName'.
Current runtime Target Framework: 'DNX,Version=v4.5 (dnx45)' Type:
CLR Architecture: x86 Version: 1.0.0-beta6-12256
Please make sure the runtime matches a framework specified in
project.json
I went with the default settings in the new project dialog, which I believe included a dependency on .NET 4.5.1 (though there's no mention of that dependency in the project.json file - contrary to what the exception message claims). I tried the solution offered here (defining the DNX_IIS_RUNTIME_FRAMEWORK environment variable in the project's debug settings) without success.

Install latest tools and try again. Beta 6 isn't apt to be supported and lots changed since then. You can get the tools here: http://www.microsoft.com/en-us/download/details.aspx?id=49442

Related

Resolution of Microsoft.Net.Http.Headers assembly version 2.2.0 versus 6.0.0 depends on seemingly unrelated package references

While trying to use HeaderNames.XFrameOptions, I found that it works in one of my projects and fails in another. Both are targeting .NET 6.
In my app, I need to work with the X-Frame-Options HTTP header. When possible, for maintainability reasons, I try to evade specifying constants for such standard strings myself, relying on standard constants instead. For this header's name, there is HeaderNames.XFrameOptions, available since ASP.NET Core 3.0.
By navigating to the class's implementation in VS, I found that the project where it works uses version 6.0.0.0 (.NET 6, x64) of the Microsoft.Net.Http.Headers assembly:
C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App\6.0.12\Microsoft.Net.Http.Headers.dll
The project where it does not work uses version 2.2.0.0 (.NET Standard 2.0, MSIL) of the assembly:
C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.net.http.headers\2.2.0\lib\netstandard2.0\Microsoft.Net.Http.Headers.dll
The working project is the main project of my console app and the broken project is a library in the same solution, directly referenced by the console app.
When I looked into the broken project's obj\project.assets.json, I found that Microsoft.Net.Http.Headers is really used in version 2.2.0 and it is referenced by Microsoft.AspNetCore.Http.Extensions/2.2.0, which is also used in the broken project.
I used that info to reproduce the failure:
dotnet new globaljson --sdk-version 6.0.404 --roll-forward disable
dotnet new console -f net6.0
dotnet add package Microsoft.AspNetCore.Http.Extensions --version 2.2.0
echo "Console.WriteLine(Microsoft.Net.Http.Headers.HeaderNames.XFrameOptions);" > Program.cs
dotnet run
C:\Repos\playground\Program.cs(1,58): error CS0117: 'HeaderNames' does not contain a definition for 'XFrameOptions' [C:\Repos\playground\playground.csproj]
The build failed. Fix the build errors and run again.
I tried adding all the packages referenced by the working project to the repro project and it fixed it! By elimination and following the dependencies of the last remaining project, I found that the fix can be achieved by adding just a single package (AspNetCore.HealthChecks.UI.Client/6.0.5):
dotnet add package AspNetCore.HealthChecks.UI.Client --version 6.0.5
dotnet run
X-Frame-Options
I see that AspNetCore.HealthChecks.UI.Client references the Microsoft.Net.Http.Headers assembly version 6.0.0.0, but directly, as an assembly, not as a NuGet package. Sadly, the latest packaged version is 2.2.0.0.
How can I make HeaderNames.XFrameOptions work in both my projects at the same time? Is installing an irrelevant package like AspNetCore.HealthChecks.UI.Client the only solution? And is there a more straightforward way to diagnose such assembly resolution issues?

ASP.NET Core - 2.1 to 2.2 Issue

Visual Studio 2017 15.9.18 on Windows 10
I have an ASP.NET Core Project that I need to update the Target Framework from 2.1 to 2.2
After changing the Target Framework, I cleaned an re-built the project.
I now get a compile error saying that says one of the assemblies in my project uses 'Microsoft.AspNetCore.Http.Abstractions, Version=2.1.1.0 which has a higher version than referenced assembly 'Microsoft.AspNetCore.Http.Abstractions' with identity 'Microsoft.AspNetCore.Http.Abstractions, Version=2.0.1.0
In my project dependencies I have Microsoft.NETCore.App 2.2.0 installed. I was going to update this but in package manager the Update button is disabled, saying "Implicitly referenced by an SDK. To update the package, update the SDK to which it belongs." The versions available show they go up to 2.2.8
Using Nuget Package Manager I installed Microsoft.AspNetCore.Http.Abstractions 2.1.1.0 and that seemed to work in debug, but after publishing, my site fails to load.
Should I be manually updating the version of Microsoft.NETCore.App, or is it fine to just update the Microsoft.AspNetCore.Http.Abstractions?
I added the following to my project file:
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<RuntimeFrameworkVersion>2.2.0</RuntimeFrameworkVersion>
</PropertyGroup>
I also noticed some invalid sections in my publish profile:
I also read somewhere that I should add:
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
but SetCompatibilityVersion does not appear as a method.
I would discourage upgrading from .NET Core 2.1 to .NET Core 2.2 at this time.
Today's date is 1/4/2020 and as of December 23, 2019 .NET Core 2.2 is at the End of Lifecycle (EOL)
If you're going to spend the time migrating your code at this time, you should move to a version of .NET Core that is going to receive patches if there is anything broken or there are any vulnerabilities.
You can see the EOL dates here https://dotnet.microsoft.com/platform/support/policy/dotnet-core

MsBuild failing for .Net Standard project with error "Package System.Security.Cryptography.ProtectedData, version x.x.x was not found"

Project Setup : Mixed framework solution
.Net Framework 4.6.2 projects in solution : 15
.Net Standard 2.0 projects in solution - 1
Development Machine
Visual Studio 2017(15.7.4) : Builds without any errors
Build Server
TeamCity Version 2017.1.3
Build Steps
Nuget Restore(3.4.4)
dotnet Restore
MSBuild( Build Tools 2017), Tools Version 15.0
Build fails with following error in the .net standard 2.0 project : [ResolvePackageAssets] C:\Program Files\dotnet\sdk\2.1.301\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(198, 5): Package System.Security.Cryptography.ProtectedData, version 4.4.0 was not found. It might have been deleted since NuGet restore. Otherwise, NuGet restore might have only partially completed, which might have been due to maximum path length restrictions.
What's interesting is I can't find reference or use of System.Security.Cryptography.ProtectedData anywhere in the project. Any help is greatly appreciated.
P.S - Can't use dotnet build, as the solution needs building of licenses.licx files, and the component which builds it (Microsoft.Build.Tasks.LC) is not ported to .Net Core. The suggestion from various posts was to use MsBuild.exe

VS2017 : Target framework drop down does not show .NET Core 2.1 option

I have already installed VS2017 Enterprise 15.6.4. Recently installed .NET Core 2.1.101 SDK from official site
I was expecting .NET Core 2.1 as one of the target framework available if I create console or asp.net core application. Can someone help me understanding what I am missing here.
As suggested in comments, I installed 15.7 preview 2. Still no luck and same issue.
I have faced the same problem. I solved this by installing the right SDKs with Runtime for .NET Core 2.1.
Basically to run/create 2.1 projects from VS Preview, you need to install the "2.1.300" (not 2.1.4) .NET Core SDKs and Runtime. https://www.microsoft.com/net/download/dotnet-core/sdk-2.1.300-preview1 (this includes required Runtime already)
The good explanation of this misleading with versions i found here https://github.com/dotnet/cli/issues/8309 (dasMulli commented on Feb 24).
In case this helps someone else... After installing VS 15.9.2 my project that was working fine with 2.2 preview-3 stopped working. VS could not see the preview SDK. I could build the solution using dotnet.exe but not VS.
To solve this I created a global.json at the root folder of this solution pointing to the preview sdk. That allowed VS to see the preview version.
This is a change of behavior in VS between 15.8.x and 15.9.x.
To create the global.json you can navigate to the desired folder and type this:
dotnet new globaljson
Make sure dotnet PATH variables are in correct order
If you have installed an SDK for a different system architecture (e.g., if you installed 32-bit/x86 SDK on a 64-bit computer), then a new entry in the PATH variable would have been created for that specific location (e.g., C:\Program Files\dotnet or C:\Program Files (x86)\dotnet).
The problem is that Visual Studio, when searching for installed frameworks, will stop at the first PATH variable entry it finds that contains an SDK. So, if the first version you installed used an incorrect architecture, then you'll have to adjust the position of those entries before any of the correct SDKs will appear in the Target Framework drop down.
Source: this absurdly-hard-to-find comment within issue #8309.
TL;DR: Make sure the first "C:\Program Files\dotnet\" entry in your path variable you see in the list matches your system architecture:
64-bit = C:\Program Files\dotnet\
32-bit = C:\Program Files (x86)\dotnet\
Make sure that Visual Studio 2017 is up to date. Go to "Tools" -> "Extensions and Updates" to install visual studio updates. This resolved the issue for me.
I have faced the similar situation I tried to install the preview version of the dot net but it did not help.
However after I updated visual studio (from 15.8 to 15.9.6 ).
I Could see dot net core 2.1 in the target framework.
Updated to Latest VS 2017 and installed latest .Net Core SDK.
Changed global.json to point to latest version installed.
This resolved for me.
I had faced the similar issue. I then just updated my Visual Studio 2017 to 15.9.16 version and restarted the system. The problem got resolved.
I was facing the similar issue, I uninstalled the .Net Core 2.2 runtime and then from the below link:
https://dotnet.microsoft.com/download/visual-studio-sdks?utm_source=getdotnetsdk&utm_medium=referral
Install the .Net Core 2.2 Visual Studio SDK, Restarted the Visual Studio and my issue got resolved, .Net Core 2.2 is now getting listed in Target Framework list in the project properties in Visual Studio 2017 Version 15.9.16
I created a new project under .net core 2.1 and it was ok but in my old project have not appeared. So I opened both ".cproject" files and compared them together and found the problem.
Open your project's ".cproject" file in a text editor then replace below line
<TargetFramework>netstandard2.1</TargetFramework>
with this one:
<TargetFramework>netcoreapp2.1</TargetFramework>

Visual Studio 15.3.1 can't find core DLLs after update

I'm getting the runtime error:
InvalidOperationException: Can not find assembly file mscorlib.dll at '...\bin\Debug\net462\refs,...\bin\Debug\net462\'
This had not been a problem until I updated to version 15.3.1 this morning, and installed the .Net Core 2.0 SDK.
The DLL's are present in my ~\.nuget\packages folder. I'd had the same issue with the "Microsoft.Csharp.dll" assembly until I copied and pasted it into the stated folder.
I tried specifying to use .Net Core 1.1.0 via a global.json file, but then I get the build error:
The version of Microsoft.NET.Sdk used by this project is insufficient to support references to libraries targeting .NET Standard 1.5 or higher. Please install version 2.0 or higher of the .NET Core SDK.
This error goes away if I clean the solution then restore Nuget packages via Command Line- not via the GUI. However it comes back if I change the version of a nuget package.
OK, this seem slightly different to my issue here: Visual Studio update 2017 15.3.1 forces ASP.NET Core SDK 2.0, which then doesn't find "reference assemblies"
If you install the SDK 2.0 from https://www.microsoft.com/net/download/core
You will then "probably" be able to build and run the project again but you'll be back to having the missing Microsoft.CSharp.dll / mscorelib.dll error.
If you then make sure the dependency is correct for the netstandard version:
<DependsOnNETStandard>netstandard1.5</DependsOnNETStandard>
See here: https://learn.microsoft.com/en-us/dotnet/standard/net-standard for the right version for you. My project is using core 1.1 targeting the full framework 4.6.1 and targeting netstandard1.6 has worked for me.
The final piece of the puzzel, was found on the GitHub issues here: https://github.com/dotnet/sdk/issues/1488
Add the following to your references in the .csproj file:
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="2.0.0" />
This will then build the project as a 1.1 project, but using the 2.0 SDK (which from what I can tell, it's supposed to do!). I can now run the project, update packages and generally got on with my work!