The following array collection expression with spread operator fails on .Net SDK version 8.0.204 but works on SDK version 8.0.104.
VsCode Version: 1.89.0
OS: Windows 10
Dotnet version: .Net 8
C# Language Version: 12
Code that raises the exception
Type[] types = [
.. Assembly.GetAssembly(typeof(Application.DependencyInjection))!
.GetTypes(),
.. Assembly.GetAssembly(typeof(Infrastructure.DependencyInjection))!
.GetTypes()
];
Full Exception
Exception has occurred: CLR/System.ArrayTypeMismatchException
Exception thrown: 'System.ArrayTypeMismatchException' in System.Private.CoreLib.dll: 'Attempted to access an element as a type incompatible with the array.'
at System.ThrowHelper.ThrowArrayTypeMismatchException()
at System.Span`1..ctor(T[] array)
at Webmonitor.Infrastructure.Data.Dapper.DapperMappingRegistration.RegisterDapperMappers() in C:MahbuburProjectsWM 4NextGenAPIWebmonitor.InfrastructureDataDapperDapperMappingRegistration.cs:line 21
Full code
public static void RegisterDapperMappers()
{
Type[] types = [
.. Assembly.GetAssembly(typeof(Application.DependencyInjection))!
.GetTypes(),
.. Assembly.GetAssembly(typeof(Infrastructure.DependencyInjection))!
.GetTypes()
];
var typesWithColumnAttributes = types
.Where(t => t.GetProperties().Any(p => p.GetCustomAttribute<ColumnAttribute>() is not null))
.Where(t => !t.IsInterface && !t.IsAbstract);
foreach (var type in typesWithColumnAttributes)
{
SqlMapper.SetTypeMap(type, new DapperCustomAtrributeMapper(type));
}
}
Removing the collection expression works.
Type[] types = Assembly
.GetAssembly(typeof(Webmonitor.Application.DependencyInjection))!
.GetTypes()
.Concat(Assembly.GetAssembly(typeof(Webmonitor.Infrastructure.DependencyInjection))!.GetTypes())
.ToArray();
Going back to older .net sdk version 8.104 works too.