ASP.NET Core WebApp(.NET Core) missing DataAnnotations - asp.net

Following situation:
I have a .sln with multiple projects (data-access, business-objects, business-logic, web-server).
The Web-Project is an ASP.NET Core Web Application using .Net-Core 1.1 with the individual user account authorization (Identity) and the "WebApplication"-Template.
The rest of the projects is using the .Net-Framework 4.6.2.
Now I am about to remove the DBContext from the web-server and instead use the same as in the data-access-project.
I set up my ApplicationDBContext accordingly and my User entity extends the IdentityUser. I also changed everything in the web-server-project to use the ApplicationDBContext (in my case called WTHListModell).
I also has the references to the projects WTHList.GO (business-objects) and WTHList.DZ (data-access).
Now here comes the problem:
Doing this using the full .NET-Framework for the Web-Server (creating a ".NET-Core Web-Application (.Net-Framework)" ) is successful and works just fine.
With .Net-Core 1.1 I am getting a FileNotFound-Exception regarding "System.ComponentModel.DataAnnotations" whenever I try to either log-in or register a user.
Now I have read, that DataAnnotations isn't compatible with .Net-Core and I also tried to add other NuGet-Packages and Assemblies to the Web-Project.
I don't know what else I can do about that, because I am supposed to use the .NET-Core Framework 1.1 for the Web-Projekt and it keeps on giving me this particular error.
Has anybody got a clue on how to solve this issue?
I have searched for a while now and I haven't found a solution for this yet...
And if it has any relevance: I am using the VS2017 Enterprise RC.
Thanks in advance.
UPDATE
This is the content of the csproj file:
<Project ToolsVersion="15.0" Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup Label="Globals">
<SccProjectName>SAK</SccProjectName>
<SccProvider>SAK</SccProvider>
<SccAuxPath>SAK</SccAuxPath>
<SccLocalPath>SAK</SccLocalPath>
</PropertyGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.1</TargetFramework>
<PreserveCompilationContext>true</PreserveCompilationContext>
</PropertyGroup>
<PropertyGroup>
<PackageTargetFallback>$(PackageTargetFallback);portable-net45+win8+wp8+wpa81;</PackageTargetFallback>
</PropertyGroup>
<PropertyGroup>
<UserSecretsId>aspnet-WTHList.Web2-ab5b6dbd-698d-4877-a2b3-6dd9b7a37960</UserSecretsId>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.0" />
<PackageReference Include="Microsoft.NETCore.App" Version="1.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="1.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Routing" Version="1.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.0.1" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="1.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink.Loader" Version="14.0.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="1.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="1.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="1.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="1.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.1.0-preview4-final" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="1.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="1.0.0-msbuild2-final" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0-msbuild2-final" />
<DotNetCliToolReference Include="Microsoft.Extensions.SecretManager.Tools" Version="1.0.0-msbuild2-final" />
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.0-msbuild2-final" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\WTHList.DZ\WTHList.DZ.csproj" />
<ProjectReference Include="..\WTHList.GL\WTHList.GL.csproj" />
<ProjectReference Include="..\WTHList.GO\WTHList.GO.csproj" />
</ItemGroup>
</Project>

Don't be confused with different "Core" terms: .NET Core is new "base" framework, which "looks like" .NET Framework 4.5 (4.6, etc), but this is other framework. You can compile multiple versions of same project (for different frameworks) at once.
ASP.NET Core is like old ASP.NET, but a new one. It is compiled twice - once for .NET Framework 4.5.1 (and "compatible" 4.5.2, 4.6, 4.6.1) and once for .NET Core (actually, for netstandart1.6 which is some kind of "specification", which is implemented by NET Core).
So, you can create web apps using ASP.NET Core which can build/run on .NET Framework 4.5.1 and/or on .NET Core. But you need all dependencies to be also build on (compatible with) .NET Framework 4.5.1 and/or on .NET Core.
So, if your app require some libraries (e.g. System.ComponentModel.DataAnnotations) which is not available for NET Core - you can't build/run app on .NET Core. You can only build ASP.NET Core app on top of .NET Framework 4.5.1+.

Related

How do I update other Microsoft libraries after updating to .Net Core 3.1

I have a web app solution that is quite old where the main project is Asp.Net 4.6 and a small companion project is .Net Core 2.
I want to first upgrade them both to .Net Core 3.1, and then upgrade to .Net 7 later this year.
According to the Microsoft documentation I have to update the target framework and associated libraries.
So I updated this part in my project file:
<TargetFramework>netcoreapp3.1</TargetFramework>
However, the other referenced libraries don't seem to have 3.1 updates. How would I upgrade these?
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.0.2" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices" Version="2.0.3" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.4" />
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="2.0.2" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="2.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.3" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="System.ServiceModel.Duplex" Version="4.3.0" />
<PackageReference Include="System.ServiceModel.Security" Version="4.3.0" />
Thanks!
When Microsoft introduced .NET Core 3.0, they stopped producing a large number of NuGet packages (If you're interested, you can see the list here).
Microsoft made them part of the shared framework Microsoft.AspNetCore.App that is implicitly referenced if your .csproj targets Microsoft.NET.Sdk.Web SDK. You can check this in your .csproj project.
<Project Sdk="Microsoft.NET.Sdk.Web">
...
</Project>
If your project targets Microsoft.NET.Sdk, then you might have to add a FrameworkReference, as explained here.
Assuming the latter is not your case, removing the references to those NuGet packages should be fine.
For microsoft .net core packages,I think you could search in the document and found the correspond packages.
https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore?view=aspnetcore-2.2
example1:
example2:

VS2019 Error Says Project is Targetting 'netcoreapp3.1' when it is Targetting netcoreapp2.2

I have a multi-project solution that was working fine in VS2017, I've installed VS2019 and on compile I receive five error messages:
Four of the format: This version of Microsoft.AspNetCore.App is only compatible with netcoreapp2.2 taret framework. Please target netcoreapp2.2 or chose a version of Microsoft.AspNetCore.app compatible with netcoreapp3.1
And one of the format: Project '..\project-path\project.csproj' targets 'netcoreapp3.1;. It cannot be reference by a project that targets '.NETCoreApp,Version=v2.2'
Additionally if you look at the projects referenced in the error messages the Dependencies, Packages, SDK all have the yellow warning symbol on them (hover and right-click don't seem to provide additional details)
I've tried cleans, delete bin and obj folders, rebuilds, checking SDK versions, but no luck
I can confirm I have a global.json with the SDK version (2.2.103) and that when in any of these projects directories and I run 'dotnet --verson' I get back 2.2.103
What is happening here? What / where is it picking up netcoreapp3.1 from and how do I resolve these errors?
Update: CSPROJ Details
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<LangVersion>7.3</LangVersion>
</PropertyGroup>
<ItemGroup>
<None Include="appsettings.json" CopyToOutputDirectory="Always" />
<None Include="favicon.ico" CopyToOutputDirectory="Always" />
<None Include="appDevLocalOverride.json" />
<PackageReference Include="Lamar.Microsoft.DependencyInjection" Version="3.1.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.8.1" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.AzureKeyVault.HostingStartup" Version="2.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Cors" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="3.1.2" />
<PackageReference Include="Microsoft.Azure.KeyVault" Version="3.0.3" />
<PackageReference Include="Microsoft.Azure.Services.AppAuthentication" Version="1.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="2.2.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.2.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Configuration.AzureKeyVault" Version="2.2.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.3" />
</ItemGroup>
I'm not sure why or how this works, but I have stumbled on a solution:
Open the csproj
Edit <PackageReference Include="Microsoft.AspNetCore.App" /> to <PackageReference Include="Microsoft.AspNetCore.App" Version="2.2.0" />
Build > Clean Solution
Manually remove ALL bin and obj folders (even if they are only remotely related to the solution)
Build > Rebuild Solution
Edit <PackageReference Include="Microsoft.AspNetCore.App" Version="2.2.0" /> to <PackageReference Include="Microsoft.AspNetCore.App" />
That seemed to work for me, why a simple Clean Solution and Rebuild wasn't the answer is odd; but hopefully this will help someone else!

Nuget Packages Conflict .net core

I'm working on creating sample for clean architecture. When I had made core and infrastructure projects there were no problems. No I had add new API project and I got problem, picture bellow
I had tried to add project references in csproj but still have a problem, can anyone help me to fix this problem ?
Here is the link for project: https://github.com/danijel88/Clean-Architecture
Regards,
Danijel
Here's a question similar to yours
Here's a sample .csproj. Be sure to have
<TargetFramework>netcoreapp2.2</TargetFramework>
Make sure your project is on 2.2 before updating your packages to 2.2.
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<TypeScriptToolsVersion>3.1</TypeScriptToolsVersion>
<AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel>
<CopyRefAssembliesToPublishDirectory>false</CopyRefAssembliesToPublishDirectory>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Gelf.Extensions.Logging" Version="1.5.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="3.1.2" />
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.2.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.1" />
<PackageReference Include="SlackLogger" Version="2.0.5" />
<PackageReference Include="System.Xml.Linq" Version="3.5.21022.801" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Nozomi.Infra.Preprocessing\Nozomi.Infra.Preprocessing.csproj" />
<ProjectReference Include="..\Nozomi.Infra.Service.Identity\Nozomi.Infra.Service.Identity.csproj" />
<ProjectReference Include="..\Nozomi.Infra.Service\Nozomi.Infra.Service.csproj" />
</ItemGroup>
<ItemGroup>
<_ContentIncludedByDefault Remove="Areas\Identity\Pages\_ViewImports.cshtml" />
</ItemGroup>
</Project>

Reference XtraReport in Dotnet Core application

I would like to create a dotnet core console application that should create pdf report using DevExpress XtraReport.
How can I reference the devexpress dll in my csproj?
Thanks a lot
EDIT:
the project targets net462
This is my csproj
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net462</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel.Https" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="1.0.0" />
</ItemGroup>
<ItemGroup>
<Folder Include="wwwroot/" />
</ItemGroup>
<ItemGroup>
<Content Include="Properties/**">
<CopyToPublishDirectory>Always</CopyToPublishDirectory>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="tempkey.rsa">
<CopyToPublishDirectory>Always</CopyToPublishDirectory>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>
Refer this - Reporting support for .Net core
It's hard to speak about possible estimates here as NET Core 2.0 does
not support System.Drawing, Sörnt. Right now, everything that is
available in .NET Standard 2.0 is a few drawing primitives, that's all
(see diff). On the other hand, implementing a custom drawing library
that would work for any possible target .NET platform is a very
complex task — I'd say it's just as hard as doing a new reporting
engine from scratch. Yes, there are some alternatives for drawing
(e.g., Mono's gdipluslib), but they have a lot of compatibility issues
we need to deal with, not to mention that some areas (like the actual
printing) are not covered at all. Of course, being compatible with the
.NET Standard is something is that we look forward to, but there are
still missing pieces our engine heavily relies on. Needless to say,
the .NET Core development is moving really fast comparing to the
legacy .NET Framework, so it's highly possible that we'll see more and
more features / APIs provided by the corefx team very soon.
It is not yet supported in .net core apps. There may be some workaround to use in asp.net core applications.. See below reference links.
References:
XtraReports in .NET Core
XtraReports for ASP.NET Core
Reporting support for .Net core
XtraReports does support the dotnet core platform starting with v18.1.
https://community.devexpress.com/blogs/reporting/archive/2018/04/26/reporting-net-core-support-ctp-v18-1.aspx
https://docs.devexpress.com/XtraReports/119717/create-end-user-reporting-applications/web-reporting/aspnet-core-reporting

ASP.NET Core 2.0 TagHelper errors after upgrade

I am getting this cryptic error after updating my ASP.NET MVC Service running in Service Fabric. After a lot of faffing around with the actual upgrade I managed to get it running on my local Service Fabric on my machine.
I am now trying to deploy it to an actual Service Fabric cluster. I am now getting errors such as:
Error RZ3501: Invalid tag helper bound property 'RouteValues' on tag helper 'Microsoft.AspNetCore.Mvc.TagHelpers.AnchorTagHelper'.
'Microsoft.AspNetCore.Razor.TagHelpers.HtmlAttributeNameAttribute.DictionaryAttributePrefix' must be null unless property type implements 'IDictionary<string, TValue>'.
(0,0): Error RZ3501: Invalid tag helper bound property 'RouteValues' on tag helper 'Microsoft.AspNetCore.Mvc.TagHelpers.FormActionTagHelper'.
Note that I have not changed any code during the upgrade of the ASP.NET MVC service to version 2.0
This is a sample of how I used TagHelpers:
#{
IDictionary<string,string> routeData = SpecialMethodThatCalculatesRouteData();
}
<a asp-route="MyRoute" asp-all-route-data="#routeData" >
This code worked fine before the upgrade.
Has anybody stumbled upon this?
Thanks
EDIT: These are the references I have in the csproj file:
<PackageReference Include="CompressedStaticFiles" Version="1.0.3" />
<PackageReference Include="Microsoft.AspNetCore" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.0" />
<PackageReference Include="Microsoft.ServiceFabric" Version="5.7.198" />
<PackageReference Include="Microsoft.ServiceFabric.AspNetCore.WebListener" Version="2.7.198" />
<PackageReference Include="Microsoft.ServiceFabric.Data" Version="2.7.198" />
<PackageReference Include="Microsoft.ServiceFabric.Services" Version="2.7.198" />
<PackageReference Include="Microsoft.ServiceFabric.Services.Remoting" Version="2.7.198" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="2.0.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.1.1" />
<PackageReference Include="Microsoft.ApplicationInsights.ServiceFabric.Native" Version="1.0.0-beta2" />
<PackageReference Include="NETStandard.Library.NETFramework" Version="2.0.0-preview2-25405-01" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
<PackageReference Include="React.AspNet" Version="3.1.0" />
<PackageReference Include="Microsoft.Azure.DocumentDB" Version="1.17.0" />
<PackageReference Include="Microsoft.Extensions.Caching.SqlServer" Version="2.0.0" />
EDIT: More info. I had to add these tasks to my build definition in VSTS to get the project to compile
I just ran into the same problem, setting the vsts build to 'clean' seemed to resolve it.
I had a global.json file pointing against an old SDK (1.1), removing that file solved this problem for me.
Turns out that our build agent had VS version 15.2 and by upgrading the build agent to the latest version 15.5, that solved the problem.

Resources