Posts

c# no more boiler plate code for assigning value to properties

With c# record, no longer have to do manual instantiation or setting property when passing value as part of the constructor, for example, using the following  record WeatherForecast ( DateOnly Date , int TemperatureC , string ? Summary ) {     public int TemperatureF => 32 + ( int )( TemperatureC / 0.5556 ); } Is the 'almost' equivalent of public class WeatherForecast {     public int TemperatureC { get ; set ; }     public int Date { get ; set ; }     public string Summary { get ; set ; }     public WeatherForecast ( DateOnly date , int temperatureC , string ? summary )     {         Summary = summary ;         Date = date ;         TemperatureC = temperatureC ;     } }

AADSTS500033: There is an issue with the key, It has both x5t and x5c values, but they do not match

There's an issue with the jwt token being presented.  x5t: This refers to a value representing the thumbprint of a certificate used for authentication. A thumbprint is a unique identifier derived from the certificate. x5c: This refers to the certificate chain itself.  The error message is saying that the thumbprint (x5t) doesn't match the certificate (x5c) being presented.     

Azure devops docker service connection's service principal been removed

Image
  An issue with an Azure DevOps Docker service connection where the service principal is no longer available. As I have limited access to my organization AD, I am unable to carry out much investigation. I suspect the service principal has been removed. This is not the same as service principal expired where you can For expired service principal token Go to your Azure DevOps project settings and navigate to  Service connections . Locate the Docker service connection using a service principal. Click  Edit  on the connection. In the edit window, click  Verify . This attempts to refresh the token using the existing credentials. In my case, didn't even have a "verify" button - so i suspect this is more for Azure ARM Manager.  Or a variation of the workaround from stackoverflow link where you need to remove the secret before making meaningless update to re-generate the secret. To resolve it, i have to change my Docker service connection to use "Other" and setup the f

hotchoc calling API endpoint - working sample

  Here is a working sample for hotchoc graphql calling an endpoint. The sample code can be found here https://github.com/mitzenjeremywoo/graphql-api-integration To get started install swag tool  dotnet new tool-manifest To install nswag console cli tool into your local project  dotnet tool install NSwag.ConsoleCore --version 13.10 .9 Generate the swagger.json from your API endpoint. This file will be used for code generation later curl -o swagger.json http://localhost:5000/swagger/v1/swagger.json Next, generate your client API that will be consuming or calling your API dotnet nswag swagger2csclient /input:swagger.json /classname:TodoService /namespace:TodoReader /output:TodoService.cs And finally add newtonsoft.json library  dotnet add package Newtonsoft.Json The step above is for generating the client.  Integrate this client into your application code by following the code github code example.   You should be able to use Banana Cake Pop to run some graphql query against API. 

using netcat to test connectivity without dns resolution

Sometimes when troubleshooting DNS related issue, we would like to skip dns lookup and go straight to the target host. To do that we can use  nc -z -n IP_address port_number which can be quite handy.

powershell command for network

Test-NetConnection are useful in many ways To get detail information  Test-NetConnection -ComputerName www.contoso.com -InformationLevel Detailed   To check for TraceRoute - shows you the path to the destination server, in this case www.contoso.com. As traceroute operates on layer 3, it will be good to ensure connectivity is good, before proceeding to troubleshoot network connectivity at a higher level like DNS. (layer 7). Test-NetConnection -ComputerName www.contoso.com -TraceRoute Route diagnostics  Test-NetConnection -ComputerName www.contoso.com -DiagnoseRouting -InformationLevel Detailed or if you want to limit it to a specific network adapter (constraint interface) Test-NetConnection -ComputerName www.contoso.com -ConstrainInterface 6 -DiagnoseRouting -InformationLevel Detailed To get your adapter, you can run " Get-NetAdapter " Test-Connection is another useful utility. This is a ICMP request. ICMP works on layer 3 of the TCPIP and are not associated to a

hothoc - calling REST API endpoint troubleshooting

If you're getting the following error messages :-  "Could not deserialize the response body stream as System.Collections.Generic.ICollection`1[[TodoReader.WeatherForecast]' Or  "Unable to resolve service for type 'System.String' while attempting to activate service" These are indications that the conversion issue from JSON after calling the endpoint is not working. To troubleshoot this - NSWAG typically generate code that hides the actual error. You have to do some debugging and find out which type wasn't really being serialized successfully.  Or  "No service for type 'System.Net.Http.IHttpClientFactory' has been registered." This means you haven't register IHttpClientFactory to your service.

using NSwag console to generate code from OpenAPI endpoint

  To generate code from an Open API endpoint, you can use the nswag cli. The following are easy steps to do the code generations. The source here is swagger.json.  The /classname is the name of your class that will be generated and the same applies to  /namespace and  /output dotnet new tool-manifest dotnet tool install NSwag.ConsoleCore --version 13.10.9 curl -o swagger.json http://localhost:5199/swagger/v1/swagger.json dotnet nswag swagger2csclient /input:swagger.json /classname:PartnerService /namespace:ExternalAPI /output:PartnerService.cs For more options, please refer to this link here https://github.com/RicoSuter/NSwag/wiki/CommandLine/ce950c5aea7bf52a85ec6e517ad8ea96762181ed

install codegpt to vscode

Image
To install Codegpt to your vscode, first open up your vscode, then goto extension.  Then look for "CodeGpt" (the one with 1 million download) Install that extension.  Once you've done that, goto View -> Open View -> CodeGpt.  Ask away!   

hotchoc - graphql - getting started

  Create a dotnet core api project using cli. I am using dotnet 8. dotnet new webapi -n app  Then add the hotchoc packages  dotnet add package HotChocolate.AspNetCore Then you can add the necessary code to Program.cs  using HotChocolate ; using HotChocolate . AspNetCore ; var builder = WebApplication . CreateBuilder ( args ); builder . AddGraphQLServer ()     . AddQueryType < Query >(); var app = builder . Build (); app . MapGet ( "/" , () => "Hello World!" ); app . Run (); AddQueryType<Query> - this query is a class that contain simple code here. namespace app . model {     public class Query     {         public Book GetBook () =>         new Book         {             Title = "C# in depth." ,             Author = new Author             {                 Name = "Jon Skeet"             }         };     }     public class Book     {         public string Title { get ; set ; }         public Author Au

Mr Parker - terraform plan - complaining missing realm and openid client scope resources for Mr Parker provider

 When there's missing client especially when you restore a database and then run the pipeline, you will get this error - This has been fixed in a more recent version of the provider. A June 2023 version of the provider should work.  The only way to resolve this, assuming you're like me - unable to update, is the initialize your terraform and then run terraform state rm to remove the states accordingly. Please note, this would result in re-creation of the scopes or whatever resources that you're planning to remove.  Example command:  terraform state rm module.your_organization. keycloak_openid_client_ default_scopes.client_mobile_ edr_default_scopes

PSQL command to help with session termination

I find the following PSQL command quite useful for terminating session for a specific database in Postgres. Let say you want to alter the database name but there's tons of connections.  ALTER DATABASE "keycloak" RENAME TO "keycloakcurrent" So first you see which process is active in the database  SELECT * FROM pg_stat_activity where datname='keycloak' Then you issue multiple command to terminate the session.  SELECT pg_terminate_backend(9026) If you bump into an error whereby you need to be a member of pg_signal_backend, then you can use this command to grant yourself a member to that role called pg_signal_backend. GRANT pg_signal_backend TO psqladmin