Friday, November 12, 2021

how to enable .Net 6.0 hot reload in Visual Studio Code?

 Hot Reload is a cool feature in .Net 6. we can easily enable this feature in Visual Studio Code with executing the following command 

dotnet watch run 

then we do not have to rerun the dotnet run to recompile the whole application to see the change immediatley.


 

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, October 1, 2021

Immediate Git Commands

a list of handy git commands

# check the change of the file 

git diff filename

# check in parital change of the file -p flag will show us the change in patch level

git add -p filename

# use git commit to enter the concise message

git commit 

# use git log to check the commit history to ensure the change had been commit

git log

# create a branch   

git branch test

# use the branch

git checkout test

# push the change back to the repository

git push --set-upstream origin test

# merge the change

git merge test

# undo the merge and rebase

git merge --abort

git rebase--abort

#use mergetool to perform the merge

git mergetool




Monday, September 13, 2021

How to fix "HTTP Error 404.0 - Not Found" in Kubernetes ingress-nginx services?

i had setup the kubernetes Ingress with ingress-nginx with the following code, in my local machine,

which will direct the traffic to the backend service in kubernetes

apiVersionnetworking.k8s.io/v1
kindIngress
metadata:
  nameingress-srv
  annotations:
    kubernetes.io/ingress.classnginx
    nginx.ingress.kubernetes.io/use-regex"true"
spec:
  rules:
    - hostacme.com
      http:
        paths:
          - path/api/platforms
            pathTypePrefix
            backend:
              service:
                nameplatformservice-clusterip-srv
                port:
                  number80
          - path/api/c/platforms
            pathTypePrefix
            backend:
              service:
                namecommandservice-clusterip-srv
                port:
                  number80

after the setup is complete. i try to browse to the platform service web api which is hosted in the backend server.

http://acme.com/api/platforms/  but the error comes up immediately, which indicated that 

  • The directory or file specified does not exist on the Web server.

since the directory was not hosted in the IIS, it had been deployed to the pods in the kuberentes


As we manipulate the kubernetes in the local environment, we can check what process is using the port 80

C:\code\dotnet-microservices\k8s>netstat -ano | findstr ":80" | findstr "LISTENING"

  TCP    0.0.0.0:80             0.0.0.0:0              LISTENING       4

  TCP    0.0.0.0:8081           0.0.0.0:0              LISTENING       4

  TCP    [::]:80                [::]:0                 LISTENING       4

  TCP    [::]:8081              [::]:0                 LISTENING       4


the PID 4 represnet that the port 80 had been assigned to IIS local host.  we should stop the World Wide Web Publishing Service, in order to release the port 80 for Kubernetes services. 



after I stop the World Wide Web Publishing Service, the we can see that port 80 had been assigned to different processes.

C:\code\dotnet-microservices\k8s>netstat -ano | findstr ":80" | findstr "LISTENING"

  TCP    0.0.0.0:80             0.0.0.0:0              LISTENING       3440

  TCP    [::]:80                [::]:0                 LISTENING       3440

  TCP    [::1]:80               [::]:0                 LISTENING       16096

Now we should be able to access the web api host in the kubernetes.

[{"id":1,"name":"dotnet","cost":"free","publisher":"Microsoft"},{"id":2,"name":"SQL Server Express","cost":"free","publisher":"Microsoft"},{"id":3,"name":"Kubernetes","cost":"free","publisher":"Cloud Native Computer Foundation"}]







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

how to fix "Unable to connect to the server: dial tcp: lookup myaksclust-myresourcegroup-3f2c36-40a876eb.hcp.eastus.azmk8s.io: no such host" error?

when I try to check the version of Kubectl with kubectl version that is installed in my local desktop. i got the following error

"Unable to connect to the server: dial tcp: lookup myaksclust-myresourcegroup-3f2c36-40a876eb.hcp.eastus.azmk8s.io: no such host"

I check the kubectl configuration file with Kubectl config view

it shows with information below

apiVersion: v1                                                                                                                                       

clusters:                                                                                                                                            

- cluster:                                                                                                                                           

    certificate-authority-data: DATA+OMITTED                                                                                                  

    server: https://aks-cluste-aks-rg-3f2c36-a86fa58c.hcp.eastus.azmk8s.io:443                                                                       

  name: aks-cluster                                                                                                                                  

- cluster:                                                                                                                                           

    certificate-authority-data: DATA+OMITTED                                                                                                         

    server: https://kubernetes.docker.internal:6443                                                                                                  

  name: docker-desktop                                                                                                                               

- cluster:                                                                                                                                           

    certificate-authority-data: DATA+OMITTED                                                                                                         

    server: https://kuar-clust-kuar-3f2c36-3176b3bf.hcp.eastus.azmk8s.io:443                                                                         

  name: kuar-cluster                                                                                                                                 

- cluster:                                                                                                                                           

    certificate-authority: C:\Users\admin\.minikube\ca.crt                                                                                           

    server: https://192.168.2.14:8443                                                                                                                

  name: minikube                                                                                                                                     

- cluster:                                                                                                                                           

    certificate-authority-data: DATA+OMITTED                                                                                                         

    server: https://myaksclust-myresourcegroup-3f2c36-40a876eb.hcp.eastus.azmk8s.io:443                                                  

  name: myAKSCluster                                                                                                                                

contexts:                                                                                                                                            

- context:                                                                                                                                           

    cluster: aks-cluster                                                                                                                             

    user: clusterUser_aks-rg_aks-cluster                                                                                                             

  name: aks-cluster                                                                                                                                  

- context:                                                                                                                                           

    cluster: docker-desktop                                                                                                                          

    user: docker-desktop                                                                                                                             

  name: docker-desktop                                                                                                                               

- context:                                                                                                                                           

    cluster: kuar-cluster                                                                                                                            

    user: clusterUser_kuar_kuar-cluster                                                                                                              

  name: kuar-cluster                                                                                                                                 

- context:                                                                                                                                           

    cluster: minikube                                                                                                                                

    user: minikube                                                                                                                                   

  name: minikube                                                                                                                                     

- context:                                                                                                                                           

    cluster: myAKSCluster                                                                                                                            

    user: clusterUser_myResourceGroup_myAKSCluster                                                                                                   

  name: myAKSCluster                                                                                                                                 

current-context: myAKSCluster                                                                                                                        

kind: Config                                                                                                                                         

preferences: {}                                                                                                                                      

users:                                                                                                                                               

- name: clusterUser_aks-rg_aks-cluster                                                                                                               

  user:                                                                                                                                              

    client-certificate-data: REDACTED                                                                                                                

    client-key-data: REDACTED                                                                                                                        

    token: e4d785d3065d5697f03ac404ac27460f68b973b7185ea4697679077e39ff106437d3a7fe9c79f3be5cc84bbab6728e2d71bc010d0a6c6628bf05162958c122bb          

- name: clusterUser_kuar_kuar-cluster                                                                                                                

  user:                                                                                                                                              

    client-certificate-data: REDACTED                                                                                                                

    client-key-data: REDACTED                                                                                                                        

    token: afc713faf0d9c13f494711c3ab569d52c48c4ac1bef72f53329ab832247c0180f87a167d59c1a784ea0951bd11f043e8eb8aa6089caec2d9d71f61ea58d29b48          

- name: clusterUser_myResourceGroup_myAKSCluster                                                                                                     

  user:                                                                                                                                              

    client-certificate-data: REDACTED                                                                                                                

    client-key-data: REDACTED                                                                                                                        

    token: 2906f9edf219806a855010df4aa104f25eceea94ce748cf1b7813f3af93c531a60b853654b6bc0b24c448491ab3a5896ad36e0fa00d898507c44db7c69f8b283          

- name: docker-desktop                                                                                                                               

  user:                                                                                                                                              

    client-certificate-data: REDACTED                                                                                                                

    client-key-data: REDACTED                                                                                                                        

- name: minikube                                                                                                                                     

  user:                                                                                                                                              

    client-certificate: C:\Users\admin\.minikube\profiles\minikube\client.crt                                                                        

    client-key: C:\Users\admin\.minikube\profiles\minikube\client.key        


we can see that the current-context is myAKSCluster, which is Azure Kubernetes Service. the error is sterm from that either authoriation token had been expired or the  service instance had been removed from azure

Since we already know the root cause of the issue, we can change the kubectl context to the new AKS or the local docker-desktop.

we can follow the steps below 

#to get all the context available in the kubectl configuration file

kubectl config get-contexts

CURRENT   NAME             CLUSTER          AUTHINFO                                   NAMESPACE

          aks-cluster      aks-cluster      clusterUser_aks-rg_aks-cluster

          docker-desktop   docker-desktop   docker-desktop

          kuar-cluster     kuar-cluster     clusterUser_kuar_kuar-cluster

          minikube         minikube         minikube

*         myAKSCluster     myAKSCluster     clusterUser_myResourceGroup_myAKSCluster

#update the current context with local docker-desktop

kubectl config use-context docker-desktop

                                                                  


Monday, September 6, 2021

how to add a list of empty folders to github in windows environment?

When we setup the project structure in the development. the Github have prevent us to push all empty folder to the GitHub Repository in remote server. we can use gitkeep utility in the Macs and Linux environmen to create gitkeep for those blank folder. we cannot gitkeep in the Windows environment. but there is a work around. we can use the powershell scripts to loop through all subfolders under the current project folder and add .gitkeep file in each empty folder. then we can upload those folders to the server.

here is the code to be execute in the windows PowerShell ISE, you should copy it to your windows PowerSehll ISE and replace {Your Current Project Folder path} with your own folder path

Get-ChildItem '{Your Current Project Folder path}' -Recurse -Directory | 

Where-Object {[System.IO.Directory]::GetFileSystemEntries($_.FullName).Count -eq 0} | 

ForEach-Object { New-Item ($_.FullName + "\.gitkeep") -ItemType file}