Closed ZvonimirMatic closed 3 years ago
regarding: Could not load type 'System.DateOnly' from assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
with PostgreSQL
I had the same issue on a ubuntu linux server running dotnet 6.0 Preview 2, after updating to Preview 5 the issue was gone. Not sure if the model is pre-compiled on demand or something like that and the issue might happen again, but for me updating to the latest preview fixed it.
@Spacefish DateOnly is a new type which was only introduced in .NET 6.0 preview5.
Appears to be fixed in 6.0.0-rc1
@AndriySvyryd what is the status on DateOnly & TimeOnly conversions in RC1?
Do we still need to write custom converters for SQL Server?
Do we still need to write custom converters for SQL Server?
Yes, SQLClient doesn't natively support them yet, see https://github.com/dotnet/SqlClient/issues/1009
I"m not seeing this fixed in 6 RC1.
entity.Property(o => o.UsageLogType)
.HasMaxLength(10)
.HasConversion(new EnumToStringConverter<UsageLogType>());
System.InvalidOperationException: The property 'UsageLog.UsageLogType' has a value converter configured. Use 'HasConversion' to configure the value converter type.
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGenerator.Create(IProperty property, Dictionary`2 propertyVariables, CSharpRuntimeAnnotationCodeGeneratorParameters parameters)
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGenerator.CreateEntityType(IEntityType entityType, IndentedStringBuilder mainBuilder, IndentedStringBuilder methodBuilder, SortedSet`1 namespaces, String className, Boolean nullable)
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGenerator.GenerateEntityType(IEntityType entityType, String namespace, String className, Boolean nullable)
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpRuntimeModelCodeGenerator.GenerateModel(IModel model, CompiledModelCodeGenerationOptions options)
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.CompiledModelScaffolder.ScaffoldModel(IModel model, String outputDir, CompiledModelCodeGenerationOptions options)
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.Optimize(String outputDir, String modelNamespace, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OptimizeContextImpl(String outputDir, String modelNamespace, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OptimizeContext.<>c__DisplayClass0_0.<.ctor>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
The property 'UsageLog.UsageLogType' has a value converter configured. Use 'HasConversion' to configure the value converter type.
@aherrick Use
entity.Property(o => o.UsageLogType)
.HasMaxLength(10)
.HasConversion<EnumToStringConverter<UsageLogType>>();
I was unable to create a compiled model (#1906) if there was a custom value converter in the model. The problem is related to EF Core version 6.0 preview 5. EF Core tools (
dotnet ef
) are also version 6 preview 5. To reproduce the problem you can create an application (dotnet new web --name CompiledModelConverter
), install preview 5 versions ofMicrosoft.EntityFrameworkCore.SqlServer
andMicrosoft.EntityFrameworkCore.Design
and replace the content ofStartup.cs
with the following code:Now running the command
dotnet ef dbcontext optimize --verbose
produces the following error:I tried replacing the converter configuration as suggested in the issue #1906 with the following code:
Now running the same command produces the following error:
Removing the conversion configuration all together results in a successful generation of compiled model. So does using a generic overload of
HasConversion
method without specifying a converter, for example:Using one of the built in converters such as
StringToBoolConverter
does not work, it produces same error as a custom value converter.I have tried this with SQL Server and SQLite and behavior is the same.
I have also tried using PostgreSQL but I get the following error whether I have value converters configured or not:
Could not load type 'System.DateOnly' from assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
I suppose that PostgreSQL error is related to something else or I might have misconfigured something (I only installedNpgsql.EntityFrameworkCore.PostgreSQL
and replaced.UseSqlServer
with.UseNpgsql
). I decided to metionEF Core version: 6.0 preview 5 Database provider: Microsoft.EntityFrameworkCore.SqlServer, Microsoft.EntityFrameworkCore.SqlLite Target framework: .NET 6.0 preview 5 Operating system: Windows 10 IDE: VS Code