Wednesday, 28 May 2025

Retag an existing ECR image

Sometimes you need to retag an existing AWS ECR (Elastic container registry) image to the latest in order to deploy it as the latest.

 
Use Power shell for these commands

1. Get a Specific Image from ECR by Digest


$Image = Get-ECRImageBatch -ImageId @{ imageDigest="sha256:5cf0bd5fa566c49bba44e9fab18bf340bff5f3ef224217a6f13e43321ce9" } -RepositoryName jagdev-poc/service


2. Extract the Image Manifest


$Manifest = $Image.Images[0].ImageManifest


3. Re-tag the Image with "latest"


Write-ECRImage -RepositoryName jagdev-poc/service -ImageManifest $Manifest -ImageTag latest


4. List All Images in the Repository

Get-ECRImage -RepositoryName jagdev-poc/service

Thursday, 15 June 2023

git pull error :error: remote ref is at but expected

Today I faced strange GIT error while running GIT pull command.

error: cannot lock ref 'refs/remotes/origin/Feature/Performance_Fix': is at 121133f24b3eda9c7167c7be2b0f31d282b0bbb2 but expected 58840e344e3d301761c726e4f833b83f6b261ecb

Solution : 

Run below commands to fix this issue (Update the object name stored in a ref safely, used this to delete the reference) 

git update-ref -d refs/remotes/origin/Feature/Performance_Fix

git pull


Thursday, 8 June 2023

Error : The specified type member 'Date' is not supported in LINQ to Entities

I was trying to use Date property of DateTime field in LINQ query but got this error.

Message = "The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported."

Example query : 

var query = from employeeRecord in _context.EmployeeRecord 

                   where (employeeRecord.StartDate.Date== currentDate)

Solution : Use DbFunctions.TruncateTime to truncate time part from a DateTime.

Updated Query : 

var query = from employeeRecord in _context.EmployeeRecord 

                   where (DbFunctions.TruncateTime(employeeRecord.StartDate) == currentDate)

Saturday, 1 April 2023

Error while upgrading Azure function to .NET6

I was  upgrading a Function App from using version 4.0.0 of Microsoft.Azure.WebJobs.Extensions.Storage to 5.1.0 and then the app crashed on startup with the following error: 

 Error : A host error has occurred during startup operation 'dea811a2-8241-4581-a014-2f94a0aad978'. [2023-03-31T22:00:31.493Z] Microsoft.Azure.WebJobs.Extensions.ServiceBus: Could not load type 'Microsoft.Azure.WebJobs.ParameterBindingData' from assembly 'Microsoft.Azure.WebJobs, Version=3.0.34.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. 

Solution : 
  1. Downgrade to, "Microsoft.Azure.WebJobs.Extensions.Storage" version: 5.0.1 
  2. Clean the solution and run it

Thursday, 19 January 2023

InvalidOperationException: Can't use schemaId for type The same schemaId is already used for type

 After adding new bean to project I got below error during startup


13:44:19:254 ---> System.InvalidOperationException: Can't use schemaId "$Employee" for type "$staff.Employee". The same schemaId is already used for type "$test.Employee" 13:44:19:254 at Swashbuckle.AspNetCore.SwaggerGen.SchemaRepository.RegisterType(Type type, String schemaId) 13:44:19:254 at Swashbuckle.AspNetCore.SwaggerGen.SchemaGenerator.GenerateReferencedSchema(DataContract dataContract, SchemaRepository schemaRepository, Func`1 definitionFactory) 13:44:19:254 at Swashbuckle.AspNetCore.SwaggerGen.SchemaGenerator.GenerateConcreteSchema(DataContract dataContract, SchemaRepository schemaRepository) 13:44:19:254 at Swashbuckle.AspNetCore.SwaggerGen.SchemaGenerator.GenerateSchemaForType(Type modelType, SchemaRepository schemaRepository) 13:44:19:254 at Swashbuckle.AspNetCore.SwaggerGen.SchemaGenerator.GenerateSchema(Type modelType, SchemaRepository schemaRepository, MemberInfo memberInfo, ParameterInfo parameterInfo) 13:44:19:254 at Swashbuckle.AspNetCore.SwaggerGen.SchemaGenerator.CreateArraySchema(DataContract dataContract, SchemaRepository schemaRepository) 13:44:19:254 at Swashbuckle.AspNetCore.SwaggerGen.SchemaGenerator.<>c__DisplayClass10_0.b__1() 13:44:19:254 at Swashbuckle.AspNetCore.SwaggerGen.SchemaGenerator.GenerateConcreteSchema(DataContract dataContract, SchemaRepository schemaRepository) 13:44:19:254 at Swashbuckle.AspNetCore.SwaggerGen.SchemaGenerator.GenerateSchemaForParameter(Type modelType, SchemaRepository schemaRepository, ParameterInfo parameterInfo) 13:44:19:254 at Swashbuckle.AspNetCore.SwaggerGen.SchemaGenerator.GenerateSchema(Type modelType, SchemaRepository schemaRepository, MemberInfo memberInfo, ParameterInfo parameterInfo) 13:44:19:254 at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GenerateSchema(Type type, SchemaRepository schemaRepository, PropertyInfo propertyInfo, ParameterInfo parameterInfo) 13:44:19:254 --- End of inner exception stack trace --- 13:44:19:254 at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GenerateSchema(Type type, SchemaRepository schemaRepository, PropertyInfo propertyInfo, ParameterInfo parameterInfo) 13:44:19:254 at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GenerateRequestBodyFromBodyParameter(ApiDescription apiDescription, SchemaRepository schemaRepository, ApiParameterDescription bodyParameter) 13:44:19:254 at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GenerateRequestBody(ApiDescription apiDescription, SchemaRepository schemaRepository) 13:44:19:254 at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GenerateOperation(ApiDescription apiDescription, SchemaRepository schemaRepository) 13:44:19:254 --- End of inner exception stack trace --- 13:44:19:254 at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GenerateOperation(ApiDescription apiDescription, SchemaRepository schemaRepository) 13:44:19:254 at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GenerateOperations(IEnumerable`1 apiDescriptions, SchemaRepository schemaRepository) 13:44:19:254 at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GeneratePaths(IEnumerable`1 apiDescriptions, SchemaRepository schemaRepository) 13:44:19:254 at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GetSwagger(String documentName, String host, String basePath) 13:44:19:254 at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider) 13:44:19:254 at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context) 13:44:19:254 at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

Solution : 

The only change needed is in your Startup.cs inside the method ConfigureServices.

You should add the following:

services.AddSwaggerGen(options =>

{

    options.CustomSchemaIds(type => type.ToString());

});

Wednesday, 7 December 2022

How do I fix dependency conflicts in npm install?

Today I was working on a front end app. I faced below error while running npm install command.


npm ERR! Conflicting peer dependency: @angular/core@6.1.10

npm ERR! node_modules/@angular/core

npm ERR!   peer @angular/core@"^6.0.3" from @angular-redux/router@9.0.0

npm ERR!   node_modules/@angular-redux/router

npm ERR!     @angular-redux/router@"^9.0.0" from the root project


Fix for Conflicting peer dependency in node.js

  • Downgrade the npm version to the previous version.
  • remove the node_modules folder.
  • remove package-lock.json.
  • please do npm install one more time to do a fresh installation of the dependency.

Saturday, 12 March 2022

Detecting a active transaction in spring application

Sometimes we need to use transactions (@Transactional) in code. We use @Transactional annotation on class and method to generate transactions.

In order to troubleshoot transaction issues, it could be helpful to verify if we have an active transaction in the current method or not.

Spring has provided a class called TransactionSychronizationManager. This class has a static method that allows us to know whether we are in a transaction (active transaction or no transaction), called isActualTransactionActive().

You can call this method and print output in logs. It will be true for active transactions false otherwise.

For example :

logger.error("Transaction is active " + TransactionSynchronizationManager.isActualTransactionActive());