.net-core

How to use Dependency Injection in .Net core Console Application

て烟熏妆下的殇ゞ 提交于 2020-12-29 03:47:15
问题 I have to add data to my database using a Console Application. In the Main() method I added: var services = new ServiceCollection(); var serviceProvider = services.BuildServiceProvider(); var connection = @"Server = (localdb)\mssqllocaldb; Database = CryptoCurrency; Trusted_Connection = True; ConnectRetryCount = 0"; services.AddDbContext<CurrencyDbContext>(options => options.UseSqlServer(connection)); In another class I add functionality to work with database, and made it like a Web Api

How to use Dependency Injection in .Net core Console Application

泪湿孤枕 提交于 2020-12-29 03:44:34
问题 I have to add data to my database using a Console Application. In the Main() method I added: var services = new ServiceCollection(); var serviceProvider = services.BuildServiceProvider(); var connection = @"Server = (localdb)\mssqllocaldb; Database = CryptoCurrency; Trusted_Connection = True; ConnectRetryCount = 0"; services.AddDbContext<CurrencyDbContext>(options => options.UseSqlServer(connection)); In another class I add functionality to work with database, and made it like a Web Api

Azure functions: Unable to load DLL 'sni.dll' or one of its dependencies: The specified module could not be found. (0x8007007E)

扶醉桌前 提交于 2020-12-27 06:58:17
问题 Trying to run this Azure Function in Azure portal but fails with above title error: using System; using System.IO; using System.Net; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Microsoft.Azure.WebJobs; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Primitives; using Newtonsoft.Json; using System.Data.SqlClient; public static string Run(HttpRequest req, ILogger log) { string name="dbconn"; string conStr = System

dotnet.exe command for .NET and .NET Core

夙愿已清 提交于 2020-12-26 11:01:54
问题 I have installed ".NET Framework" on my computer. I have also installed ".NET Core Framework". Which framework is used, when I run the dotnet.exe command? I was thinking there will be 2 dotnet.exe commands, but there is only one. 回答1: The dotnet.exe tool belongs to .Net Core CLI (Command Line Interface), there really isn't an equivalent in the older .Net Framework. You can have multiple dotnet.exe files on your system, but they would all be .Net Core, as it allows side-by-side installations

How to use Console.SetWindowSize(); on Linux using .Net Core?

懵懂的女人 提交于 2020-12-26 10:33:58
问题 I'm currently working on some fancy console app. I'm using .Net Core 2.1. It was all fine, when I was working on Windows, but then I wanted to test it on Linux and use that glorious "cross-platform". To be specyfic I was using that: System.Console.SetWindowSize(); And them... Exception has occurred: CLR/System.PlatformNotSupportedException An unhandled exception of type 'System.PlatformNotSupportedException' occurred in System.Console.dll: 'Operation is not supported on this platform.' at

How to use Console.SetWindowSize(); on Linux using .Net Core?

天涯浪子 提交于 2020-12-26 10:25:20
问题 I'm currently working on some fancy console app. I'm using .Net Core 2.1. It was all fine, when I was working on Windows, but then I wanted to test it on Linux and use that glorious "cross-platform". To be specyfic I was using that: System.Console.SetWindowSize(); And them... Exception has occurred: CLR/System.PlatformNotSupportedException An unhandled exception of type 'System.PlatformNotSupportedException' occurred in System.Console.dll: 'Operation is not supported on this platform.' at

How to use Console.SetWindowSize(); on Linux using .Net Core?

折月煮酒 提交于 2020-12-26 10:24:35
问题 I'm currently working on some fancy console app. I'm using .Net Core 2.1. It was all fine, when I was working on Windows, but then I wanted to test it on Linux and use that glorious "cross-platform". To be specyfic I was using that: System.Console.SetWindowSize(); And them... Exception has occurred: CLR/System.PlatformNotSupportedException An unhandled exception of type 'System.PlatformNotSupportedException' occurred in System.Console.dll: 'Operation is not supported on this platform.' at

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":[

.NET Core: Finally block not called on unhandled exception on Linux

陌路散爱 提交于 2020-12-25 07:08:09
问题 I have created the following C# program: namespace dispose_test { class Program { static void Main(string[] args) { using (var disp = new MyDisposable()) { throw new Exception("Boom"); } } } public class MyDisposable : IDisposable { public void Dispose() { Console.WriteLine("Disposed"); } } } When I run this using dotnet run , I see the following behavior: Windows: Exception text written to console, "Disposed" printed ~20 second later, program exits. Linux: Exception text written to console,