.NET Core 2 – EF Core Error handling Save changes

Looking through the GitHub issues, there is no DbEntityValidationException equivalent in Entity Framework Core. There’s a blog post (linked from issue #9662 on GitHub), that gives a code example for performing the validation logic yourself, included here for completeness: class MyContext : DbContext { public override int SaveChanges() { var entities = from e in … Read more

The input was not valid .Net Core Web API

Don’t use FromBody. You’re submitting as x-www-form-urlencoded (i.e. standard HTML form post). The FromBody attribute is for JSON/XML. You cannot handle both standard form submits and JSON/XML request bodies from the same action. If you need to request the action both ways, you’ll need two separate endpoints, one with the param decorated with FromBody and … Read more

Local user account store for Web API in ASP.NET Core 2.0

Try start your project in the console with the command dotnet new webapi -au Individual You can open your project in VS after that. (to work around the dialog). Then you can use for example the authorize-attribute. But the project is still configured to use Azure Bearer Authentication. You have to decide where to get … Read more

ASP.NET Core 2 Unable to resolve service for type Microsoft EntityFrameworkCore DbContext

StudentService expects DbContext but the container does not know how to resolve it based on your current startup. You would need to either explicitly add the context to the service collection Startup services.AddScoped<DbContext, SchoolContext>(); services.AddScoped<IStudentService, StudentService>(); Or update the StudentService constructor to explicitly expect a type the container knows how to resolve. StudentService public StudentService(SchoolContext … Read more

The specified framework ‘Microsoft.AspNetCore.App’, version ‘2.1.0’ was not found

.NET Core 2.1 SDK will be released this week. If you can’t wait until then, add this to your *.csproj <Project Sdk=”Microsoft.NET.Sdk.Web”> <PropertyGroup> <TargetFramework>netcoreapp2.1</TargetFramework> <RestoreAdditionalProjectSources> https://dotnetfeed.blob.core.windows.net/orchestrated-release-2-1/20180515-07/final/index.json </RestoreAdditionalProjectSources> </PropertyGroup> …. </Project> And download the final SDK from: https://dotnetcli.blob.core.windows.net/dotnet/Sdk/2.1.300/dotnet-sdk-2.1.300-win-x64.exe For more details visit: https://github.com/aspnet/Home/wiki/2.1.0-Early-Access-Downloads

How to unique identify each request in a ASP.NET Core 2 application (for logging)

ASP.NET Core also has HttpContext.TraceIdentifier which uniquely identifies the current request. It is generated for each incoming request by Kestrel, so isn’t suitable for correlating calls to one service from another, but is suitable for correlating logs for a single request together, or to correlating an error message that might be displayed to the user … Read more