Handling exception in asp.net core?

You can use to handle exceptions UseExceptionHandler(), put this code in your Startup.cs. UseExceptionHandler can be used to handle exceptions globally. You can get all the details of exception object like Stack Trace, Inner exception and others. And then you can show them on screen. Here Here You can read more about this diagnostic middleware … Read more

What’s the difference between .NET CoreCLR, CoreRT, Roslyn and LLILC

Roslyn is a compiler platform that enables you to build static and dynamic analysis tools and custom language extensions and transformations for the C# and VB programming languages.It also enables you to embed these languages within other languages or applications. Roslyn includes the C# and VB compilers and other tools. These compilers emit Common Intermediate … Read more

Do we need interfaces for dependency injection?

No, you don’t need interfaces for dependency injection. But dependency injection is much more useful with them! As you noticed, you can register concrete types with the service collection and ASP.NET Core will inject them into your classes without problems. The benefit you get by injecting them over simply creating instances with new Storage() is … Read more

.Net Framework and .Net Core in same solution

There is an article published in April 2017 on how to support both runtimes from the same solution: https://learn.microsoft.com/en-us/dotnet/core/porting/project-structure It boils down to 2 methods: Having both frameworks configured in the same project (e.g. *.csproj): Replace existing projects with a multi-targeted .NET Core project. Having a separate project for each framework: Keep existing projects and … Read more

Correct way to return HttpResponseMessage as IActionResult in .Net Core 2.2

public class HttpResponseMessageResult : IActionResult { private readonly HttpResponseMessage _responseMessage; public HttpResponseMessageResult(HttpResponseMessage responseMessage) { _responseMessage = responseMessage; // could add throw if null } public async Task ExecuteResultAsync(ActionContext context) { var response = context.HttpContext.Response; if (_responseMessage == null) { var message = “Response message cannot be null”; throw new InvalidOperationException(message); } using (_responseMessage) { response.StatusCode … Read more

How to write to a file in .NET Core?

This code is the skeleton I was looking for when I posed the question. It uses only facilities available in .NET Core. var watcher = new BluetoothLEAdvertisementWatcher(); var logPath = System.IO.Path.GetTempFileName(); var logFile = System.IO.File.Create(logPath); var logWriter = new System.IO.StreamWriter(logFile); logWriter.WriteLine(“Log message”); logWriter.Dispose();

How to set aspnetcore_environment in publish file?

You could pass in the desired ASPNETCORE_ENVIRONMENT into the dotnet publish command as an argument using: /p:EnvironmentName=Staging e.g. dotnet publish /p:Configuration=Release /p:EnvironmentName=Staging This will generate out the web.config with the correct environment specified for your project: <environmentVariables> <environmentVariable name=”ASPNETCORE_ENVIRONMENT” value=”Staging” /> </environmentVariables>

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)