Showing posts with label .Net Core. Show all posts
Showing posts with label .Net Core. Show all posts

Monday, June 27, 2022

ASP.Net MVC Web API vs .Net 6 Minimal API quick compare in a diagram

 Microsoft introduced the Minimal API in .Net 6, which is a lightweight API development for web api

We can show two with difference in a diagram









we can easily spot the big difference is that there is no Controller component in the Minimal API.

As a result there will much more difference between Mininal API and MVC Web API


you can find out more information with this link  Tutorial: Create a minimal web API with ASP.NET Core


Monday, October 4, 2021

10 best Nuget Package for .Net Developer

Most .NET Developer should love to  integrate the following package in their .NET project developer.

xUnit & NUnit : pacakge for unit testing

Moq & NSubstitute: Mocking libaries for .Net testing

Polly: Provide rich features for policies handling

FluentAssertions: Provide  rich features for Assertions

BenchmarkDotNet: Provider Performance trace

Serilog: Provide logging with full structure events

Autofixture & Bogus : Fake Data Generator

Scrutor: add scanning capabilities to the default Microsoft Extensions. (DependecyInjection DI Container)

Automapper:Object to Object mapper

Dapper & Entity Framework Core: Data Access framework: Dapper is simple and customable

MediatR & Brighter : CQRS stands for Command Query Responsibility Segregation libraries. MediatR is an in-process command dispatcher. Brighter is an out of process command dispatcher

FluentValidation: validation library using fluence interface and lamda expression for building validation rules

Refit & RestSharp: API tools. Refit is an automatic type-safe REST library for .Net. RestSharp is a simple REST and HTTP API Client for .Net.

Json.NET: handle json data


Friday, September 10, 2021

how to fix "The SSL connection could not be established," in Web Api development with ASP.Net Core and .Net 5.0

I implemented two MicroServices in my local machine,  I try to call one service from another with HttpClient. the error was shown as blew after the service call.

"cound not send data to commandservice with errror The SSL connection could not be established, see inner exception. System.Security.Authentication.AuthenticationException: The remote certificate is invalid because of errors in the certificate chain: UntrustedRoot   at System.Net.Security.SslStream.SendAuthResetSignal(ProtocolToken message, ExceptionDispatchInfo exception)

   at System.Net.Security.SslStream.ForceAuthenticationAsync[TIOAdapter](TIOAdapter adapter, Boolean receiveFirst, Byte[] reAuthenticationData, Boolean isApm)"

the error indicated that th SSL connection cannot be established due to certificate issue.

we can the  use the following command to trust the self-singed certificate

dotnet dev-certs https --trust

for more information about this command you can check out the microsoft document website with the link below


https://docs.microsoft.com/en-us/dotnet/core/additional-tools/self-signed-certificates-guide

Friday, March 13, 2020

how to fix "project.assets.json' doesn't have a target for '.NETCoreApp,Version=v3.0"?

After I changed my target framework and rebuild it is fine, then I try to publish my solution again..

then the issue comes up immediately with the following error message.

"Severity    Code    Description    Project    File    Line    Suppression State
Error        Assets file 'C:\Users\admin\source\repos\dandotnetcore\dandotnetcore\obj\project.assets.json' doesn't have a target for '.NETCoreApp,Version=v3.0'. Ensure that restore has run and that you have included 'netcoreapp3.0' in the TargetFrameworks for your project.    dandotnetcore        0
   
"

the root cause of this issue is that i had create the publish profile first, then i changed the target framework. however Visual Studio never update the target framework in the publish profile.



I had to go the publish xml file and manually update it to be netcoreapp3.1







Before

<?xml version="1.0" encoding="utf-8"?>
<!--
This file is used by the publish/package process of your Web project. You can customize the behavior of this process
by editing this MSBuild file. In order to learn more about this please visit https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <WebPublishMethod>FileSystem</WebPublishMethod>
    <PublishProvider>FileSystem</PublishProvider>
    <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish />
    <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
    <ExcludeApp_Data>False</ExcludeApp_Data>
    <ProjectGuid>d30dbc67-142e-4bb0-a07a-5abb280b4ecc</ProjectGuid>
    <publishUrl>C:\Temp\publish</publishUrl>
    <DeleteExistingFiles>True</DeleteExistingFiles>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <SelfContained>false</SelfContained>
  </PropertyGroup>
</Project>




After

<?xml version="1.0" encoding="utf-8"?>
<!--
This file is used by the publish/package process of your Web project. You can customize the behavior of this process
by editing this MSBuild file. In order to learn more about this please visit https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <WebPublishMethod>FileSystem</WebPublishMethod>
    <PublishProvider>FileSystem</PublishProvider>
    <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish />
    <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
    <ExcludeApp_Data>False</ExcludeApp_Data>
    <ProjectGuid>d30dbc67-142e-4bb0-a07a-5abb280b4ecc</ProjectGuid>
    <publishUrl>C:\Temp\publish</publishUrl>
    <DeleteExistingFiles>True</DeleteExistingFiles>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <SelfContained>false</SelfContained>
  </PropertyGroup>
</Project>


how to deploy a dotnet core web api to IIS Server?

my web api was implemented in dot.net core 3.1. i did not have to add services to the container like the previous version of Dot Net Core.





for example we have to use app.UseIISIntegration() in version 2.0

I only have to publish the project to a folder, then set up a new web site with physical path pointing to publish folder.

here is the step to set up the web site for my Dot Net Core Web API.

1. create a new application pool called DotNetCoreAppPool with No Managed Code for .net CLR version






2. create a new website and set the physical to path to publish folder and select the app pool that created in step one.
















Friday, January 10, 2020

How to troubleshoot the sync failed issue in DevOps deployment?

After i push the change from local to Github, then i click on the sync button in the deployment center.






How the status indicated that the sync result is failed. we can check the issue by click on the Log button to expand the log section.











Command: "D:\home\site\deployments\tools\deploy.cmd"
Handling ASP.NET Core Web Application deployment.
D:\Program Files (x86)\dotnet\sdk\2.2.109\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets(137,5): error NETSDK1045: The current .NET SDK does not support targeting .NET Core 3.1.  Either target .NET Core 2.2 or lower, or use a version of the .NET SDK that supports .NET Core 3.1. [D:\home\site\repository\DanCoreWebApp\DanCoreWebApp.csproj]
D:\Program Files (x86)\dotnet\sdk\2.2.109\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets(137,5): error NETSDK1045: The current .NET SDK does not support targeting .NET Core 3.1.  Either target .NET Core 2.2 or lower, or use a version of the .NET SDK that supports .NET Core 3.1. [D:\home\site\repository\WebApp2\WebApp2.csproj]
Failed exitCode=1, command=dotnet restore "D:\home\site\repository\DanCoreWebApp.sln"
An error has occurred during web site deployment.
\r\nD:\Program Files (x86)\SiteExtensions\Kudu\85.11214.4277\bin\Scripts\starter.cmd "D:\home\site\deployments\tools\deploy.cmd"

the error log showed that .Net Core version issue. Currently Azure does not support the .Net Core 3.0 in the production.