.net-core-2.1

Handling Model Binding Errors when using [FromBody] in .NET Core 2.1

心不动则不痛 提交于 2020-12-25 11:01:48
问题 I am trying to understand how I can intercept and handle model binding errors in .net core. I want to do this: // POST api/values [HttpPost] public void Post([FromBody] Thing value) { if (!ModelState.IsValid) { // Handle Error Here } } Where the Model for "Thing" is: public class Thing { public string Description { get; set; } public int Amount { get; set; } } However if I pass in an invalid amount like: { "description" : "Cats", "amount" : 21.25 } I get an error back like this: {"amount":[

Handling Model Binding Errors when using [FromBody] in .NET Core 2.1

随声附和 提交于 2020-12-25 11:01:29
问题 I am trying to understand how I can intercept and handle model binding errors in .net core. I want to do this: // POST api/values [HttpPost] public void Post([FromBody] Thing value) { if (!ModelState.IsValid) { // Handle Error Here } } Where the Model for "Thing" is: public class Thing { public string Description { get; set; } public int Amount { get; set; } } However if I pass in an invalid amount like: { "description" : "Cats", "amount" : 21.25 } I get an error back like this: {"amount":[

How to use ConfigurePrimaryHttpMessageHandler generic

∥☆過路亽.° 提交于 2020-05-29 06:13:31
问题 I want to add an HttClientHandler for a Typed HttpClient in order to include certificate authentication. All the examples I'm finding on the internet are like this: services.AddHttpClient<IMyService, MyService>() .ConfigurePrimaryHttpMessageHandler(() => { return new HttpClientHandler() { // Set here whatever you need to get configured }; }); But I don't want to include all the logic to obtain the certificate here, so I would like to use the generic version of

System.Runtime, Version=4.2.1.0, PublicKeyToken=b03f5f7f11d50a3a has a higher version than referenced assembly

爱⌒轻易说出口 提交于 2020-05-13 04:26:50
问题 I upgraded my ASP.NET CORE application from sdk .NET Core 2.0 to .NET Core 2.1. I can run the solution in my localhost but when I deploy it to another server there is an exception. And the exception is below. The steps I have done to solve the issue so far are below and it throws the same error with all the modification that I did seems nothing works. Does anybody have any suggestion how to solve this issue? Steps I've done: Modify the setting for the project <PropertyGroup> <TargetFramework

System.Runtime, Version=4.2.1.0, PublicKeyToken=b03f5f7f11d50a3a has a higher version than referenced assembly

﹥>﹥吖頭↗ 提交于 2020-05-13 04:26:40
问题 I upgraded my ASP.NET CORE application from sdk .NET Core 2.0 to .NET Core 2.1. I can run the solution in my localhost but when I deploy it to another server there is an exception. And the exception is below. The steps I have done to solve the issue so far are below and it throws the same error with all the modification that I did seems nothing works. Does anybody have any suggestion how to solve this issue? Steps I've done: Modify the setting for the project <PropertyGroup> <TargetFramework

System.Runtime, Version=4.2.1.0, PublicKeyToken=b03f5f7f11d50a3a has a higher version than referenced assembly

风流意气都作罢 提交于 2020-05-13 04:25:48
问题 I upgraded my ASP.NET CORE application from sdk .NET Core 2.0 to .NET Core 2.1. I can run the solution in my localhost but when I deploy it to another server there is an exception. And the exception is below. The steps I have done to solve the issue so far are below and it throws the same error with all the modification that I did seems nothing works. Does anybody have any suggestion how to solve this issue? Steps I've done: Modify the setting for the project <PropertyGroup> <TargetFramework

This version of Microsoft.AspNetCore.All is only compatible with the netcoreapp2.1 target framework

随声附和 提交于 2020-01-22 10:35:10
问题 When I try to publish my application to the web server after upgrading to .NET Core 2.1 from 2.0, I get this message: "This version of Microsoft.AspNetCore.All is only compatible with the netcoreapp2.1 target framework. Please target netcoreapp2.1 or choose a version of Microsoft.AspNetCore.All compatible with netcoreapp2.0." It runs fine on my development machine. Here is my project file: <Project Sdk="Microsoft.NET.Sdk.Web"> <PropertyGroup> <TargetFramework>netcoreapp2.1</TargetFramework>

swagger.json paths and definitions are empty. No operations defined in spec

烈酒焚心 提交于 2020-01-21 18:15:22
问题 I am developing a .netcore web application. I am using of swagger and I've made all the necessary adjustments. Unfortunately it does not work and I just see No operations defined in spec! in the swagger output page. The swagger file with /swagger/v1/swagger.json has the following content: { "swagger": "2.0", "info": { "version": "v1", "title": "Something" }, "paths": {}, "definitions": {} } I want to see my controllers and their actions in swagger output page. 回答1: after some research i was

Character encoding errors with .NET Core on Linux

青春壹個敷衍的年華 提交于 2020-01-15 09:21:05
问题 This has been driving me batty for days, and I've finally got it down to a simple, reproducible issue. I have a NUnit test project, which is .NET Core 2.1. It references a library (let's call it "Core") which is .NET Standard 2.0. In my test project: [TestCase(true, false)] [TestCase(false, false)] [TestCase(false, true)] public void ShouldStartWith(bool useInternal, bool passStartsWith) { var result = useInternal ? StartsWithQ("¿Que?") : StringUtilities.StartsWithQ("¿Que?", passStartsWith ?

Get List of Entity Models in DbContext Entity Framework Core 2.1

孤街醉人 提交于 2020-01-02 06:26:08
问题 I'm trying to find a way to get a List of all of the entity models in my DbContext. For instance, if I have two models called Customer and Invoice defined in C# which through code-first I created EF entities and a database, how do I now query the DbContext to get a List that has Customer and Invoice in it -- i.e., all of the entities in that context? I want to be able to call a method that returns a List of all the entities -- not the data, just a list of the entities. It seems to me this