I created a blank webapi project for .NET8,Install two packages Microsoft.Extensions.DependencyModel,Microsoft.Data.SqlClient The following is the source code: using Microsoft.Extensions.DependencyModel; using System.Reflection; using System.Runtime.Loader; var builder = WebApplication.CreateBuilder(args); var list = DependencyContext.Default.RuntimeLibraries.ToList(); var assemblies = list.Select(m =>{ try { return AssemblyLoadContext.Default.LoadFromAssemblyName(new AssemblyName(m.Name)); }catch { return null; } }).Where(m => m != null).ToList(); foreach (var assembly in assemblies) {foreach (var type in assembly.GetTypes()) { } } app.Run();

After compilation, an error message such as the title will be prompted. This does not exist in .NET6. A similar error will occur when changing Microsoft.Data.SqlClient to System.Data.SqlClient How to solve it? Thank you so much.

1

There are 1 best solutions below

1
On

This is due to a bug in Microsoft.Data.SqlClient and as mentioned here, the workaround for now seems to be to update the Microsoft.Data.SqlClient NuGet package to the latest preview version, which is currently v5.2.0-preview3.23201.1. I had the same issue and can confirm, that this workaround is working.