OpenIdConnect .Net 5.0 blazor webassembly gives error on clean: no runtime pack for Microsoft.AspNetCore.App - asp.net-core

If I use Nuget "Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="5.0.0"
with .Net 5.0 blazor webassembly I get the following error on clean: NETSDK1082 There was no runtime pack for Microsoft.AspNetCore.App available for the specified RuntimeIdentifier 'browser-wasm'.
I created a brand new blazor webassembly .Net 5.0 project as in the below project file. The issue occurs when I include an openidconnect reference, but disappears if I delete that reference.
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="5.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="5.0.0" PrivateAssets="all" />
<PackageReference Include="System.Net.Http.Json" Version="5.0.0" />
</ItemGroup>
</Project>

You can try to change your project file to below:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<RuntimeIdentifier>browser-wasm</RuntimeIdentifier>
<UseBlazorWebAssembly>true</UseBlazorWebAssembly>
</PropertyGroup>
If it doesn't work,you can see more details in this thread.

Your question is not related to OpenIddict and is caused by the fact you're trying to reference a package - Microsoft.AspNetCore.Authentication.OpenIdConnect - that you're not supposed to use on Blazor.
It's a pure server-side package that CAN'T work on Blazor, which has its own OIDC authentication stack: https://www.nuget.org/packages/Microsoft.AspNetCore.Components.WebAssembly.Authentication/

Related

Donet core Conflicts between different versions of "Microsoft.AspNetCore.Authentication.Abstractions"

I am currently working on major refactoring of project and in the process trying to remove all Warnings our code base had. Finally down to 11 Warnings, but can't really see what is going on with 9 of them, which all seem to be related. Something like:
Severity Code Description Project File Line Suppression State
Warning MSB3277 Found conflicts between different versions of
"Microsoft.AspNetCore.Authentication.Abstractions" that could not be
resolved. These reference conflicts are listed in the build log when
log verbosity is set to
detailed. #######.Test.Integration C:\Program Files
(x86)\Microsoft Visual
Studio\2019\Professional\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets 2106
I have Consolidated the nuget package versions.
Checked the Csproj file and it seemed fine. (See below.)
All warnings are in Microsoft.AspNetCore.*
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FakeItEasy" Version="5.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\###\###API.csproj" />
<ProjectReference Include="..\###\###.Core.csproj" />
<ProjectReference Include="..\###\###.Data.csproj" />
</ItemGroup>
</Project>
Try to use the web SDK (Microsoft.NET.Sdk.Web instead of Microsoft.NET.Sdk) and add a package reference to Microsoft.AspNetCore.App without specifying a version
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
</Project>
Refer to Integration and unit tests no longer work on ASP.NET Core 2.1 failing to find assemblies at runtime
https://github.com/dotnet/sdk/issues/2253

Upgrading from ASP.NET Core 2.2 to 3.0

I have an ASP.NET Core project with following csproj configuration:
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
I want to upgrade the project to <TargetFramework>netcoreapp3.0</TargetFramework>. Upon doing so, however, I get following warning:
C:\Program Files\dotnet\sdk\3.0.100\Sdks\Microsoft.NET.Sdk\targets\ Microsoft.NET.Sdk.DefaultItems.targets(149,5): warning NETSDK1080: A PackageReference to Microsoft.AspNetCore.App is not necessary when targeting .NET Core 3.0 or higher. If Microsoft.NET.Sdk.Web is used, the shared framework will be referenced automatically. Otherwise, the PackageReference should be replaced with a FrameworkReference.
What precisely is the solution to this? I tried to remove reference to Microsoft.AspNetCore.App, but that does not work. The code does not reference the shared framework.
Also, what does "Otherwise, the PackageReference should be replaced with a FrameworkReference" mean?
If you are building a web project, please make sure the first line of your project file is:
<Project Sdk="Microsoft.NET.Sdk.Web">
In this case, it is automaticly included framework: Microsoft.AspNetCore.App. You don't have to include it again.
https://learn.microsoft.com/en-us/aspnet/core/migration/22-to-30?view=aspnetcore-3.0&tabs=visual-studio#framework-reference
If you are building a razor library not a web project, please make sure the first line of your project file is:
<Project Sdk="Microsoft.NET.Sdk.Razor">
In this case, your library might dependend on some class in ASP.NET Core. You have to add this:
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
Don't forget to add:
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
to <PropertyGroup>
If you are not building a razor library nor a web project, typically you don't need Microsoft.AspNetCore.App. If you can really make sure what you are doing and really need it , consider adding:
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
Updating the project file with the following fix it for me:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<UserSecretsId>My-secret</UserSecretsId>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="3.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="3.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.0.0" />
</ItemGroup>
</Project>
Reference

StackExchange.Redis.StrongName is refrenced but not included as package

I'm starting a new project using StackExchange.Redis and .Net Core 2.0.
But I get a conflict:
The type 'ConnectionMultiplexer' exists in both 'StackExchange.Redis.StrongName, Version=1.2.4.0, Culture=neutral, PublicKeyToken=c219ff1ca8c2ce46' and 'StackExchange.Redis, Version=1.2.6.0, Culture=neutral, PublicKeyToken=null'
Why is this showing even thou I'm not referencing StackExchange.Redis.StrongName and it's not even the same assembly version?
I found my solution here.
By adding this (below) to my csproj:
<Target Name="ChangeAliasesOfStrongNameAssemblies" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<ItemGroup>
<ReferencePath Condition="'%(FileName)' == 'StackExchange.Redis.StrongName'">
<Aliases>signed</Aliases>
</ReferencePath>
</ItemGroup>
</Target>
It is possible to use Strongname in your entire application, 1.2.6 is newer and will be used. The problem is when you add Redis.Stackexchange you will have the same namespace from two different dll's. .Net compiler doesn't know which one to use. If you need 1.2.6, use the StrongName version throughout your application and no more problems ....
I added a conditional flag to the "StackExchange.Redis" package, that makes it work. I Tried this solution on two new projects on two machines. Don't ask me why it works tho.
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="StackExchange.Redis" Version="1.2.6" />
</ItemGroup>
</Project>
Microsoft.Extensions.Caching.Redis 2.0 that ships with Asp .Net Core 2.0 internally uses StackExchange.Redis.StrongName, Version=1.2.4.0, that there is for example in C:\Program Files\dotnet\sdk\NuGetFallbackFolder\stackexchange.redis.strongname\1.2.4\lib\netstandard1.5 folder.
So looks it's causes a conflict between different versions of StackExchange.Redis.

Installed NuGet package, Visual Studio claims assembly not referenced

you can see that I have referenced it through nuget, but is still complaining. This is in a .net 4.6.1 framework class library in an embedded view component.
I'm also using a .net framework asp.net core web app.
I'm having a bunch of issues trying to get razor to work, but this one is a new one. MenuViewPage inherits RazorPage and is located in another assembly.
I think I should just install .net core 2, and aspnetcore.all ;)\
Anyone have any ideas why this is happening?
So after hours of trying to sort this issue out I've come to a solution:
When creating a web class library, whether you are using it for application parts or you are creating your core project with base classes I advise you covert it from a normal .net class library to a web enabled one.
To convert it to a web class library you need to change the project to use the following .csproj, then make sure to run dotnet restore.
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<OutputType>Library</OutputType>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net461</TargetFramework>
<RuntimeIdentifier>win7-x86</RuntimeIdentifier>
<PreserveCompilationContext>true</PreserveCompilationContext>
<ApplicationIcon />
<OutputTypeEx>library</OutputTypeEx>
<StartupObject />
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DocumentationFile></DocumentationFile>
<NoWarn>1701;1702;1705;1591</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.3" />
<PackageReference Include="Microsoft.AspNetCore.Session" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Razor">
<Version>1.1.2</Version>
</PackageReference>
<PackageReference Include="Microsoft.AspNetCore.Razor.Runtime">
<Version>1.1.2</Version>
</PackageReference>
<PackageReference Include="System.Net.Http" Version="4.3.2" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.1" />
</ItemGroup>
</Project>
Make sure you are making the output type a library.
I ran into issues with the assembly info file, it seems to be generated during build now, so I commented out the assembly.info stuff by double clicking "Properties"
I hope this helps someone in the future.

.NET Core how to test with net461 and xunit

dotnet new xunit ->
dotnet restore ->
dotnet test
Total tests: 1. Passed: 1. Failed: 0. Skipped: 0.
Test Run Successful.
Test execution time: 1,7148 Seconds.
.csproj; change target framework to net461:
<PropertyGroup>
<TargetFramework>net461</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="xunit" Version="2.2.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
</ItemGroup>
</Project>
then
dotnet restore ->
dotnet test
Starting test execution, please wait...
No test is available in C:\Projects\testing\bin\Debug\net461\testing.dll. Make sure that installed test discoverers & executors, platform & framework version sett
ings are appropriate and try again.
How am I supposed to test net461-projects with xunit?
I already have a big project I've upgraded from .NET Core 1.0, and testing worked fine before the upgrade, so changing test framework would require some work.
Update
As it turns out, this is probably not related to xunit and testing - ASP.NET Core projects targeting net461 won't run at all on my machine anymore, neither through VS or from cmd.
The project I am trying to run is an new empty web project from the VS template. The csproj looks like this:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net461</TargetFramework>
<RuntimeIdentifier>win7-x86</RuntimeIdentifier>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.1" />
</ItemGroup>
</Project>
The error I get is this:
dotnet run
Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.AspNetCore.Hosting, Version=1.1.1.0, Culture=neutral, PublicKeyTo
ken=adb9793829ddae60' or one of its dependencies. The system cannot find the file specified.
at WebApplication2.Program.Main(String[] args)
I have tried removing all traces of Visual Studio and .NET Core from my machine and reinstalling them, but the error is the same.
There is an issue with runtime identifier inference and how the test sdk works.
Try adding this to your <PropertyGroup> (assuming you're on a 64 bit windows):
<RuntimeIdentifier>win7-x64</RuntimeIdentifier>
you could also add
<OutputType>Exe</OutputType>
which would turn your class library project into an exe but this should work around the issue.
Yeah, I've experienced the same issue. Not sure if Microsoft already has a fix available, but it seems that some packages of ASP.NET Core 1.1.x are targeting NetStandard Library 1.6.1, which is not compatible with .NET Framework... See the matrix on MS website here: https://learn.microsoft.com/en-us/dotnet/articles/standard/library#net-platforms-support
We've decided to stick to ASP.NET Core 1.0.x for now.