I recently upgraded my .NET 7 web API project to .NET 8, and I'm encountering an issue with Scrutor version 4.2.2. The application was working fine before the upgrade, but now I'm facing the following error:
System.Reflection.ReflectionTypeLoadException: 'Unable to load one or more of the requested types.
Could not load type 'SqlGuidCaster' from assembly 'Microsoft.Data.SqlClient, Version=5.0.0.0, Culture=neutral, PublicKeyToken=23ec7fc2d6eaa4a5' because it contains an object field at offset 0 that is incorrectly aligned or overlapped by a non-object field.'
Program.cs :
using Scrutor;
using WebApplication1.Model;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
builder.Services.Scan(scan => scan.FromApplicationDependencies()
.AddClasses(classes => classes.InExactNamespaces("WebApplication1.Model"))
.UsingRegistrationStrategy(RegistrationStrategy.Skip)
.AsImplementedInterfaces()
.WithTransientLifetime()
);
//builder.Services.AddScoped<SaqmmdbContext,SaqmmdbContext>();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();
Additional Information:
- Scrutor Version: 4.2.2
- .NET Version: 8
- Microsoft.Data.SqlClient Version: 5.0.0.0
Are there any known compatibility issues between Scrutor 4.2.2 and .NET 8?
Can anyone please help me here by providing their guidance
This is a known problem in Microsoft.Data.SqlClient that will be fixed in the next version, 5.2.0. In the meantime you'll have to install the latest preview of 5.2.0. At the moment it's
5.2.0-preview3.23201.1. According to one of the comments it may work with 5.1.2, but the real fix is in 5.2.The problem was caused because Microsoft.Data.SqlClient used a performance hack that no longer works