Bug #116381 System.NullReferenceException after upgrade to net8
Submitted: 16 Oct 2024 16:39 Modified: 17 Oct 2024 8:42
Reporter: Neil Scales Email Updates:
Status: Unsupported Impact on me:
None 
Category:Connector / NET Severity:S3 (Non-critical)
Version:8.0.10 OS:Any
Assigned to: CPU Architecture:Any
Tags: C#, DDL, migration, NET

[16 Oct 2024 16:39] Neil Scales
Description:
I get the exception below after upgrading to .net8 from net 6.  This is during a migration, doesn't matter if I drop the schema.
I have around 300 tables, so have no idea which table is causing the problem.

Message: 
System.NullReferenceException : Object reference not set to an instance of an object.

  Stack Trace: 
RelationalTypeMappingSource.FindCollectionMapping(RelationalTypeMappingInfo info, Type modelType, Type providerType, CoreTypeMapping elementMapping)
<>c.<FindMappingWithConversion>b__8_0(ValueTuple`4 k, RelationalTypeMappingSource self)
ConcurrentDictionary`2.GetOrAdd[TArg](TKey key, Func`3 valueFactory, TArg factoryArgument)
RelationalTypeMappingSource.FindMappingWithConversion(RelationalTypeMappingInfo mappingInfo, Type providerClrType, ValueConverter customConverter)
RelationalTypeMappingSource.FindMappingWithConversion(RelationalTypeMappingInfo mappingInfo, IReadOnlyList`1 principals)
RelationalTypeMappingSource.FindMapping(IProperty property)
<>c.<get_TypeMapping>b__94_0(IProperty property)
NonCapturingLazyInitializer.EnsureInitialized[TParam,TValue](TValue& target, TParam param, Func`2 valueFactory)
Property.get_TypeMapping()
IReadOnlyProperty.FindTypeMapping()
RelationalPropertyExtensions.FindRelationalTypeMapping(IReadOnlyProperty property)
RelationalPropertyExtensions.GetColumnType(IReadOnlyProperty property)
RelationalPropertyExtensions.GetColumnType(IProperty property)
RelationalModel.CreateDefaultColumnMapping(ITypeBase typeBase, ITypeBase mappedType, TableBase defaultTable, TableMappingBase`1 tableMapping, Boolean isTph, Boolean isTpc)
RelationalModel.AddDefaultMappings(RelationalModel databaseModel, IEntityType entityType, IRelationalTypeMappingSource relationalTypeMappingSource)
RelationalModel.Create(IModel model, IRelationalAnnotationProvider relationalAnnotationProvider, IRelationalTypeMappingSource relationalTypeMappingSource, Boolean designTime)
RelationalModel.Add(IModel model, IRelationalAnnotationProvider relationalAnnotationProvider, IRelationalTypeMappingSource relationalTypeMappingSource, Boolean designTime)
RelationalModelRuntimeInitializer.InitializeModel(IModel model, Boolean designTime, Boolean prevalidation)
ModelRuntimeInitializer.Initialize(IModel model, Boolean designTime, IDiagnosticsLogger`1 validationLogger)
Migrator.FinalizeModel(IModel model)
Migrator.GenerateUpSql(Migration migration, MigrationsSqlGenerationOptions options)
MySQLMigrator.GenerateUpSql(Migration migration, MigrationsSqlGenerationOptions options)
<>c__DisplayClass16_2.<GetMigrationCommandLists>b__2()
Migrator.Migrate(String targetMigration)
RelationalDatabaseFacadeExtensions.Migrate(DatabaseFacade databaseFacade)

Any pointers on how to narrow down the issue would be useful.

How to repeat:
.
[16 Oct 2024 16:52] MySQL Verification Team
HI Mr. Scales,

Thank you for your bug report.

However, 8.0.10 is a VERY old release, both for our Server and C/NET.

Can you first try to upgrade your MySQL server to 8.0.40. Before you do, please take a backup.

Then switch to C/NET 8.0.40 and try again.

If you have problems with 8.0.40, on both client and server sides, please let us know.
 
Unsupported.
[17 Oct 2024 8:42] Neil Scales
8.0.10 is the latest entity framework core package.

I've also update the MySql specific packages to the latest versions:

  "MySql.Data" Version="9.1.0"
  "MySql.EntityFrameworkCore" Version="8.0.8"

I still get the same stack trace.
[17 Oct 2024 9:24] MySQL Verification Team
Hi Mr. Scales,

It turns out this is not true.

Even Connector/NET 9.1.0 is EntityFrameworkCore release.

https://dev.mysql.com/doc/connector-net/en/connector-net-entity-framework.html

Please, upgrade your C/NET too .....

Then, if you get the same problem with MySQL Server 8.0.40 and C/NET 8.0.40, then send us your program so that we can try to repeat it ......