Could not load type 'SqlGuidCaster' from assembly Microsoft.Data.SqlClient

See original GitHub issue

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

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.”

Code:

    public static IEnumerable<Assembly> GetAssembliesWithTypesImplementing<T>()
    {
        return AppDomain.CurrentDomain.GetAssemblies()
            .SelectMany(assembly => assembly.GetTypes())
            .Where(type => !type.IsAbstract && typeof(T).IsAssignableFrom(type))
            .Select(type => type.Assembly)
            .Distinct();
    }

line: assembly.GetTypes()

The error appeared after upgrading from .net 7 to .net 8 preview 1. I searched and I don’t have such Microsoft.Data.SqlClient package installed

Expected Behavior

No response

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

No response

Anything else?

No response

Issue Analytics

  • State:closed
  • Created 7 months ago
  • Comments:18 (15 by maintainers)

github_iconTop GitHub Comments

2reactions
Wraith2commented, Feb 22, 2023

Ok. that’s interesting. The problem isn’t in SqlClient it’s to do without how object layouts are computed in the Jit. It looks like a class that’s laid out safely in 7 is now not safe in 8. Since 8 is still in very early preview this isn’t a pressing problem but i’ll see if i can find the people who might know what to do.

1reaction
tippmar-nrcommented, Jun 1, 2023

This same issue is present in System.Data.SqlClient as I reported here.

Should we expect the fix for this issue to be backported from Microsoft.Data.SqlClient to System.Data.SqlClient?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Could not load file or assembly 'Microsoft.Data.SqlClient
To resolve the version issue, in Visual Studio, right click on the solution and go to Manage NuGet Packages for Solution option and...
Read more >
Could not load file or assembly System.Data.SqlClient
1. Make sure that the 'System.Data.SqlClient' assembly is present in your project's output directory or in a location where it can be discovered ......
Read more >
How to fix Could not load type 'DTSTransform.SCD.6' from ...
I'm trying to run an Integration Services Assessment using the Data Migration Assessment tool, ... The exception was: Could not load type 'DTSTransform....
Read more >
Could not load file or assembly Microsoft.Data.Services. ...
First check what version of this dll you have in your output directory. I'll bet that is 5.6.3.0, so: ... Please sign in...
Read more >
Microsoft.SqlServer.BatchParserClient, Version=14.0.0.0
Hi, I am getting this error " System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.SqlServer.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found