After following the upgrade instructions here;
Migrate Core 3.1 to 5.0
On my Blazor WebAssembly project (running as .Server project, .Shared project and .Client project).
Everything seems to have gone well apart from when I reference another project in the solution. I want the client side to reference the .Shared and another class library (this was working with 3.1 prior). I get the following error;
Error BLAZORSDK1001 The project references the ASP.NET Core shared
framework, which is not supported by Blazor WebAssembly apps. Remove
the framework reference if directly referenced, or the package
reference that adds the framework reference.
My Client.csproj has the following;
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.6" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="5.0.6" PrivateAssets="all" />
<PackageReference Include="blazor.extensions.logging" Version="2.0.4" />
<PackageReference Include="Blazored.LocalStorage" Version="4.1.1" />
<PackageReference Include="Blazorise.Bootstrap" Version="0.9.3.6" />
<PackageReference Include="Blazorise.Components" Version="0.9.3.6" />
<PackageReference Include="Blazorise.DataGrid" Version="0.9.3.6" />
<PackageReference Include="Blazorise.Icons.FontAwesome" Version="0.9.3.6" />
<PackageReference Include="Blazorise.Sidebar" Version="0.9.3.6" />
<PackageReference Include="Microsoft.AspNetCore.Components" Version="5.0.6" />
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="5.0.6" />
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="2.2.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.11.1" />
<PackageReference Include="Toolbelt.Blazor.HttpClientInterceptor" Version="9.2.1" />
</ItemGroup>
<ItemGroup>
<Folder Include="wwwroot\images\" />
<Folder Include="wwwroot\tinymce\" />
</ItemGroup>
<!-- When publishing, swap service-worker.published.js in place of service-worker.js -->
<ItemGroup Condition="'$(DesignTimeBuild)' != 'true'">
<Content Remove="wwwroot\service-worker.js" />
<Content Update="wwwroot\service-worker.published.js" Link="wwwroot\service-worker.js" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Blazor.Shared\Blazor.Shared.csproj" />
<ProjectReference Include="..\Core.Search\Core.Search.csproj" />
<ProjectReference Include="..\Core\Core.csproj" />
</ItemGroup>
<ItemGroup>
<Content Update="wwwroot\favicon.ico">
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
<Content Update="wwwroot\manifest.json">
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
<Content Update="wwwroot\service-worker.js">
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
<Content Update="wwwroot\service-worker.published.js">
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
</ItemGroup>
</Project>
and the .csproj of the referenced projects are;
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="fluentvalidation.aspnetcore" Version="8.6.2" />
<PackageReference Include="microsoft.aspnetcore.identity" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="3.1.7" />
<PackageReference Include="microsoft.identitymodel.tokens" Version="6.7.1" />
</ItemGroup>
</Project>
The error you are seeing is caused by the fluentvalidation.aspnetcore package. The current release of this package contains references to the ASP.NET Core shared framework. These references are required for certain server-side features of FluentValidation such as when you are implementing a validator interceptor.
If you are trying to use the same validator for both your WASM client and your ASP.NET server project, and if you implement one of those features like the IValidatorInterceptor interface, then your shared validator will have to reference the fluentvalidation.aspnetcore package which Blazor will not work with.
Rather than use the integrated validation in your Startup.cs class where you add fluentvalidation to your MVC controllers, you'll have to instantiate a different validator in the Controller action and call the Validate method on the object you're validating to get around this issue.
At this point, Blazor client-side validation is not integrated into the official FluentValidation package, but rather entails use of separate packages as indicated in the FluentValidation documentation.
https://docs.fluentvalidation.net/en/latest/blazor.html
I'm not sure how easy it will be to exclude the ASP.NET reference if one is using Blazor, but at least by manually validating the incoming object you have a work-around.
Related
I'm currently migrating an Azure Function from v2 to Azure Functions v4. I already migrated my project to .NET6 and fixed all the package reference errors. I have in the solution 3 projects which I adjusted to .NET6 and Azure Function v4. For that I edited the .csproj files of each of those projects and upgraded/substituted packages which are not working with .NET6. The project file of each project looks like:
Azure Function Project:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Azure.Messaging.ServiceBus" Version="7.11.1" />
<PackageReference Include="Azure.Messaging.EventHubs" Version="5.7.5" />
<PackageReference Include="DocumentFormat.OpenXml" Version="2.18.0" />
<PackageReference Include="Microsoft.Azure.WebJobs" Version="3.0.33" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.EventHubs" Version="5.1.2" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="5.8.1" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.Extensions.Azure" Version="1.6.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.Identity.Client" Version="4.48.1" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.1.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PCM.1.z\x.1.z.csproj" />
</ItemGroup>
<ItemGroup>
<Compile Update="2.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Compile>
<Compile Update="1.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Compile>
<Compile Update="3.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Compile>
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
Second Project:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Azure.Messaging.ServiceBus" Version="7.11.1" />
<PackageReference Include="Azure.Messaging.EventHubs" Version="5.7.5" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.21.0" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Azure.Devices" Version="1.38.2" />
<PackageReference Include="Microsoft.Azure.WebJobs" Version="3.0.33" />
<PackageReference Include="SendGrid" Version="9.28.1" />
<PackageReference Include="StackExchange.Redis" Version="2.6.80" />
<PackageReference Include="Twilio" Version="6.0.1" />
<PackageReference Include="UnitsNet" Version="4.149.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\x.1.w\x.1.w.csproj" />
</ItemGroup>
</Project>
Third Project:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.0" />
</ItemGroup>
</Project>
When I build the project I got no errors. But when I debug the project I got an exception which looks like:
Exception:
Exception thrown: 'System.IO.FileNotFoundException' in Microsoft.Azure.WebJobs.Host.dll.
An exception of type 'System.IO.FileNotFoundException' occurred in Microsoft.Azure.WebJobs.Host.dll but was not handled in user code
Could not load file or assembly 'Microsoft.Extensions.Configuration.Abstractions, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
I have tried the last two weeks different packages since when I googled this error, the suggestion was to see which packages are not supported by package:
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.1.3" />. I analyzed all my packages. After changing them back and force I got still the same error.
Can anyone help me and say what exactly I have to change?
As #Codebrane said, Microsoft.Extensions.Configuration.Abstractions, Version=7.0.0.0 has the issues in working with Azure Functions v4 Version and it has been shown practically in this thread.
Try by downgrading the Microsoft.Extensions.Configuration.Abstractions to Version 6.0.0 and check.
Microsoft.NET.Sdk.Functions depends on the NuGet Packages related to the Code but these can be suggested by VS IntelliSense and installed automatically, or it shows these packages required.
Also, NuGet Packages varies between In-Process and Out-of-Process worker type in Azure Functions. Refer to one of my threads for more information.
I am building an Azure function as v4 in net6. Since I also got the System.IO.FileNotFoundException regarding library Microsoft.Extensions.Configuration.Abstraction 7.0.0 when starting up the function,
I downgraded to Microsoft.Extensions.Configuration.Abstractions 6.0.0 and also had to downgrade other dependencies such as Microsoft.EntityFrameworkCore to 6.0.12 and, since I am using PostgreSQL also Npgsql.EntityFrameworkCore.PostgreSQL to 6.0.8. Now everything works.
I fixed it by including the package Microsoft.Extensions.Configuration.Abstractions 6.0.0 and building it. To include this package doesn't solve the problem directly it just shows which packages have a conflict. By downgrading these conflicting packages the project could be debugged. To check which packages are conflicting you have to open up the packages on the right side in visual studio and look where is a exclamation mark. Then you have to analyze these packages to know on what version you have to downgrade them. It changes from project to project.
I get a missing reference error when I try to inherit from the class DynamicRouteValueTransformer in a class library but when I do it from my MVC app it works fine.
public class ProductRouteTransformer : Microsoft.AspNetCore.Mvc.Routing.DynamicRouteValueTransformer
DynamicRouteValueTransformer is in namespace Microsoft.AspNetCore.Mvc.Routing which is part of Microsoft.AspNetCore.Mvc.Core.dll. I've added the DLL to the class library using Nuget and can see that it is installed but I still get a missing reference error. The class is just missing from the namespace.
I'm using .NET Core 3.1.
The csproj is below:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AutoMapper" Version="9.0.0" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Http.Extensions" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
<PackageReference Include="Microsoft.AspNetCore.Routing" Version="2.2.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.0" />
<PackageReference Include="NLog" Version="4.6.8" />
</ItemGroup>
<ItemGroup>
<Folder Include="Database\EntityUtils\" />
</ItemGroup>
</Project>
There's a topic in the docs that was introduced recently, which covers this in great detail:
With the release of .NET Core 3.0, many ASP.NET Core assemblies are no longer published to NuGet as packages.
If you take a look at the contents of your .csproj, you'll see that you've added references to 2.2.x versions of a few Microsoft.AspNetCore.* packages. I'm sure you intended to reference 3.1.x versions of these, but, as the docs quote above shows, these packages are no longer produced for 3.0+.
The next few lines from the docs explain what's happened here:
Instead, the assemblies are included in the Microsoft.AspNetCore.App shared framework, which is installed with the .NET Core SDK and runtime installers.
As of .NET Core 3.0, projects using the Microsoft.NET.Sdk.Web MSBuild SDK implicitly reference the shared framework. Projects using the Microsoft.NET.Sdk or Microsoft.NET.Sdk.Razor SDK must reference ASP.NET Core to use ASP.NET Core APIs in the shared framework.
As your project is referencing Microsoft.NET.Sdk, you'll need to add a FrameworkReference, as described above, and remove those old PackageReferences:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="AutoMapper" Version="9.0.0" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.0" />
<PackageReference Include="NLog" Version="4.6.8" />
</ItemGroup>
<ItemGroup>
<Folder Include="Database\EntityUtils\" />
</ItemGroup>
</Project>
Note that not all of the packages have been folded into the shared framework. For example, Microsoft.EntityFrameworkCore.SqlServer is still provided as a NuGet package.
I was developing a web application (Asp.net Core 2.0 MVC) using Visual Studio 2017, then i transferred to Visual Studio 2019. then I changed the target framework from .NET Core 2.0 to .NET Core 2.2.
after that, I created Models from Database using (Scaffold-DbContext) command.
Then i Followed next Steps:
Right-Click on Controller Folder.
Add.
New Scaffolded Item.
MVC Controller with views, using Entity Framework.
Select Model, DbContext, Controller Name.
Add.
Then i get this
Error
This is part of .csproj file:
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.2.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.0.0-preview5.19227.1" PrivateAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.0.0-preview5-19264-04" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.1" />
<DotNetCliToolReference Include="Microsoft.Extensions.SecretManager.Tools" Version="2.0.0" />
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.2" />
</ItemGroup>
If you need any further information, please let me know.
You shouldn't be using the 3.0.0-preview5.19227.1 version packages of Microsoft.EntityFrameworkCore.Tools or Microsoft.VisualStudio.Web.CodeGeneration.Design in what looks liks a version 2.2 app, you need to use the 2.2.x versions of those packages.
Try changing the versions to the following:
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.2.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.2.4" PrivateAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.3" PrivateAssets="All" />
</ItemGroup>
I create a WEB API in .NET CORE with the 'dotnet new' command. i want to configure this with Entity Framework Core but i cant. I install this with the 'Manage Nugets Pakages' in VS2017 and VS give me a error.
I tried to restore packages but the error persist.
my csproj file:
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CORE\CORE.csproj" />
<ProjectReference Include="..\DAL\DAL.csproj" />
<ProjectReference Include="..\DOORACCESS\DOORACCESS.csproj" />
<ProjectReference Include="..\DPFINGER\DPFINGER.csproj" />
<ProjectReference Include="..\LOGIC\LOGIC.csproj" />
<ProjectReference Include="..\utest\utest.csproj" />
</ItemGroup>
</Project>
As you can see download the packages but do not add them to the csproj. I tried to do it manually, but when I put it in, I was asking for its dependencies one by one.
I am having the weirdest of issues in a .net core web api project I have added a .net standard library which houses my models and EF code first. This all works when I deploy to IIS Express but when I attempt to publish it to IIS, the build fails.
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\logs\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.3" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.3" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="NLog.Web.AspNetCore" Version="4.5.4" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet">
<Version>1.0.0-*</Version>
</DotNetCliToolReference>
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\mobileapp\forms\xxxCallManager\xxxDalCoreStandard\xxxDalCoreStandardxxxlDalCoreStandard.csproj" />
</ItemGroup>
<ItemGroup>
<Reference Include="System.Text.Encoding.CodePages">
<HintPath>..\..\..\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v1.0\Facades\System.Text.Encoding.CodePages.dll</HintPath>
</Reference>
</ItemGroup>
</Project>
As you see from about their is no mention of system.refelection so i can only asume its one the nuget in my standard project that is messing it up below is my standard.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.1" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.2" />
</ItemGroup>
</Project>
The error I am getting is as follows now I tried adding the nuget of system.reflection but still no joy
Edit 1
The suggestion below helped a bit but now I am stuck with this error.
Severity Code Description Project File Line Suppression State
Error The command ""dotnet" exec --runtimeconfig
"C:\Work\xxxApp\xxxlApis\bin\Release\netcoreapp2.0\FuelApis.runtimeconfig.json"
--depsfile "C:\Work\FxxxApp\xxxlApis\bin\Release\netcoreapp2.0\xxxApis.deps.json"
"C:\Program
Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.mvc.razor.viewcompilation\2.0.3\build\netstandard2.0\Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.dll"
#"obj\Release\netcoreapp2.0\microsoft.aspnetcore.mvc.razor.viewcompilation.rsp""
exited with code 1. xxxlApis 0
You are using a wrong version of EF tools in the first project, it looks like a 1.0 preview version, it should be:
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.*" />
also I would remove this part:
<ItemGroup>
<Reference Include="System.Text.Encoding.CodePages">
<HintPath>..\..\..\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v1.0\Facades\System.Text.Encoding.CodePages.dll</HintPath>
</Reference>
I don't think you need that especially the hint path part. I would try remove that altogether