a bit of a problem when using library with net 8.0
hi borris, we updated to .net 8 and since then we have a problem.
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<TypeInfo> System.Reflection.RuntimeAssembly.get_DefinedTypes() at IImplementationTypeSelector Scrutor.TypeSourceSelector.InternalFromAssemblies(IEnumerable<Assembly> assemblies)+(Assembly asm) => { } [0] at bool System.Linq.Enumerable+SelectManySingleSelectorIterator<TSource, TResult>.MoveNext() at bool System.Linq.Enumerable+WhereSelectEnumerableIterator<TSource, TResult>.MoveNext() at void Scrutor.LifetimeSelector.Scrutor.ISelector.Populate(IServiceCollection services, RegistrationStrategy strategy) at void Scrutor.ServiceTypeSelector.Scrutor.ISelector.Populate(IServiceCollection services, RegistrationStrategy registrationStrategy) at void Scrutor.ImplementationTypeSelector.Scrutor.ISelector.Populate(IServiceCollection services, RegistrationStrategy registrationStrategy) at void Scrutor.TypeSourceSelector.Populate(IServiceCollection services, RegistrationStrategy registrationStrategy) at IServiceCollection Microsoft.Extensions.DependencyInjection.ServiceCollectionExtensions.Populate(IServiceCollection services, ISelector selector, RegistrationStrategy registrationStrategy) at IServiceCollection Microsoft.Extensions.DependencyInjection.ServiceCollectionExtensions.Scan(IServiceCollection services, Action<ITypeSourceSelector> action) at IServiceCollection WebApi.Extensions.AddServicesExtensions.AutoRegisterScoped<TService>(IServiceCollection services) in C:/Users/NaftalyWeinberger/source/repos/inventory-fba/WebApi/Extensions/AddServicesExtensions.cs:line 83 at IServiceCollection WebApi.Extensions.AddServicesExtensions.AddServices(IServiceCollection services) in C:/Users/NaftalyWeinberger/source/repos/inventory-fba/WebApi/Extensions/AddServicesExtensions.cs:line 35 at void WebApi.Startup.ConfigureServices(IServiceCollection services) in C:/Users/NaftalyWeinberger/source/repos/inventory-fba/WebApi/Startup.cs:line 82 at object RuntimeMethodHandle.InvokeMethod(object target, Void** arguments, Signature sig, bool isConstructor) at object System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(object obj, IntPtr* args) at object System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(object obj, Span
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