.net-core-2.1

How to use HttpClientHandler with HttpClientFactory in .NET Core

半城伤御伤魂 提交于 2019-12-30 05:44:08
问题 I want to use the HttpClientFactory that is available in .NET Core 2.1 but I also want to use the HttpClientHandler to utilize the AutomaticDecompression property when creating HttpClients . I am struggling because the .AddHttpMessageHandler<> takes a DelegatingHandler not a HttpClientHandler . Does anyone know how to get this to work? Thanks, Jim 回答1: Actually I'm not using automatic decompression but the way to achieve this is to properly register http client services.AddHttpClient

Access IServiceProvider when using generic IHostBuilder

时间秒杀一切 提交于 2019-12-24 10:38:24
问题 I'm using IHostBuilder in a .NET Core 2.1 console application. Main looks like this: public static async Task Main(string[] args) { var hostBuilder = new HostBuilder() .UseServiceProviderFactory(new AutofacServiceProviderFactory()) .ConfigureServices(services => { // Register dependencies // ... // Add the hosted service containing the application flow services.AddHostedService<RoomService>(); }); await hostBuilder.RunConsoleAsync(); } } Before, with IWebHostBuilder , I had the Configure()

VSTest-Task not running .NET Core 2.1 xUnit-Tests from Test-plan

核能气质少年 提交于 2019-12-23 19:01:39
问题 I'm trying to create a release pipeline in VSTS that runs my xUnit-tests as specified in a Test Plan . Long story short: I can't get it to work. What I'm using: Azure DevOps (formerly VSTS) Visual Studio Test task (v2.*) Test project targeting .NET Core 2.1 xunit 2.4 with xunit.runner.visualstudio 2.4 In Azure DevOps I defined a Test Plan that contains a Test Suite which contains a Test that has an Associated Automation which points to my xUnit test. I had to use the REST API to link the test

Debugging Swashbuckle Error - Failed to load API Definition

北城余情 提交于 2019-12-23 09:22:15
问题 Is there any way to get a stack trace or inner exceptions on Swashbuckle/Swagger errors? At some point, it stopped working. I'm not sure if it was when I upgraded from .Net Core 2.0 to 2.1, but I'm pretty sure it was still working after that. When I navigate to myapidomain/swagger/index.html I get this error: Which is not very helpful. It was working 2 or so weeks ago... I didn't change any Swagger configuration. It's the same as it's always been: public void ConfigureServices

.NET Core publish as exe: How to put assembly infos into exe

[亡魂溺海] 提交于 2019-12-23 04:48:30
问题 My question is similar to this one (How to add copyright to published EXE (.Net Core)) which wasn't really answered. I have a .NET core executable project. I can put assembly information like AssemblyFileVersion into my .NET Core project and compile it, it will produce a DLL and Windows Explorer will show this info in the details tab of the file properties. When I publish as native x64 EXE, I'll get an EXE of the same name and the original DLL. But only the DLL will contain the assembly info

.NET Core 2.1 Override Automatic Model Validation

大憨熊 提交于 2019-12-22 08:08:42
问题 In the latest .NET Core 2.1, an automatic validation for the model state validation is introduced (https://blogs.msdn.microsoft.com/webdev/2018/02/02/asp-net-core-2-1-roadmap/#mvc). Previously I could override the validation error response by the following code below: public class ApiValidateModelAttribute : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext context) { if (!context.ModelState.IsValid) { context.Result = new BadRequestObjectResult(new context

HttpClient with .Net Core 2.1 hangs

本秂侑毒 提交于 2019-12-21 07:36:50
问题 Given the following .Net Core 2.1 Console App... using System; using System.Diagnostics; using System.Net.Http; using System.Net.Http.Headers; namespace TestHttpClient { class Program { static void Main(string[] args) { try { using (var httpClient = new HttpClient()) { httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); string url = "https://jsonplaceholder.typicode.com/posts/1"; var response = httpClient.GetAsync(url).Result; string

.HttpContext.Features.Get<IHttpResponseFeature>().ReasonPhrase is not working in .net core 2.1?

巧了我就是萌 提交于 2019-12-14 01:33:36
问题 We are using the code below to send the custom message from server side to client side in HTTP request. It is working properly in .NET Core 2.0 Response.HttpContext.Features.Get<IHttpResponseFeature>().ReasonPhrase While using the same code in .NET Core 2.1 it does not work. It doesn't throw any script errors but we couldn't get message in client side success. How to resolve this problem? 回答1: I hope it answers your question: This is not caused by any code changes in the framework, it's

Microsoft.VisualBasic.FileIO reference

≡放荡痞女 提交于 2019-12-11 14:46:54
问题 I want to use TextFieldParser in my project. For that I need using Microsoft.VisualBasic.FileIO . However Visual Studio accepts using Microsoft.VisualBasic without the FileIO . but it does not recognize the TextFieldParser class. On other forums, I read I should add Microsoft.VisualBasic reference. I am not able to work out how to do this, since the window of Reference Manager is completely blank, so I do not have any option to chose from. Any help ? 回答1: The "Add Reference" dialog that you

.NET Core (2.1) web API controller accepting all that follows within the request url as parameter

孤人 提交于 2019-12-11 09:02:08
问题 What I have is a .NET Core 2.1 web API controller (in the following the TestController) that should generate redirects to other urls when receiving GET requests. Example: The controller is called like: http://localhost/api/v1/Test/somedir/somesubdir/filename.extension and it should return a redirect to https://example-domain.com/somedir/somesubdir/filename.extension My example controller for this question looks like: [Authorize] [Route("api/v1/[controller]")] public class TestController :