Open nafberger opened 6 months ago
like this .
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.
at RuntimeType[] System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at RuntimeType[] System.Reflection.RuntimeModule.GetDefinedTypes()
at IEnumerable
it maybe has to do with scrutor whith aseemply scaning.
I tried to download your library and I ripped out microsoft sql data client completely, but it didn't help.
we use PostgreSQL. can we please just use the PostgreSQL part without anything that touches the sqlclient library. or do u have any other solution. any help will be greatly appreciated
it seems like its the same issue as here. https://github.com/dotnet/SqlClient/issues/1930
Try the latest version 8.0.2, it uses Microsoft.Data.SqlClient 5.1.5 Also instead of main nuget you can use specific one per provider, so EFCore.BulkExtensions.PostgreSql
If the problem remains can you write a test where the issue would be reproducible.
As for the removing SqlClient client it could be done in principle, but you would need to uninstall that nuget from the source, excluce Batch folder with all files (not need for Bulk ops), also remove SqlBulkCopyOptions and in Config replace it with just KeepIdentity.
thanks @borisdj, we solved it by excluding Microsoft.Data.SqlClient from our assembly scanning code in which we use scrutor for DI.
I can provide code example if someone needs help.
btw, I tried 5.1.5 it didn't help, I even tried removing Microsoft.Data.SqlClient 5.1.5 completely from the solution but it didn't help because it comes in hidden, as a transitive package, anyway by excluding it the issue is solved. thanks for your reply.
you can close the issue if u want,
@nafberger so did you exclude the assmbly like this. I am running into the same issue.
var dataTypes = AppDomain.CurrentDomain.GetAssemblies().Where(x=>x.FullName != "Microsoft.Data.SqlClient")
public static readonly IReadOnlyCollection<string> ExcludedAssemblies = [ "Microsoft.Data.SqlClient" ];
private static ILifetimeSelector ApplicationDependenciesTypeSelector<TService>(ITypeSourceSelector scan) where TService : class
{
return scan
.FromApplicationDependencies(assembly => !ExcludedAssemblies.Contains(assembly.GetName().Name))
.AddClasses(classes => classes
.AssignableTo<TService>()
.WithoutAttribute<SkipAutoRegistrationAttribute>()
)
.UsingRegistrationStrategy(RegistrationStrategy.Skip)
.AsSelfWithInterfaces();
}
this is our code, hope that helps
Thank you @nafberger this is most helpful. Be well
hi borris, we updated to .net 8 and since then we have a problem.