dotnetcore / dotnetcore/WTM

项目文件中开启Nullable时会报错无法将空值转为字符串

Open
#581 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
C#
Stars
4.3k
Forks
896
PR merge metrics
No merged PRs in 30d

Description

看到新生成项目文件中TargetFramework为net6.0,觉得可以使用一些新特性了,就加了enable,结果在debug模式下,点击登录报如下错误:System.AggregateException: One or more errors occurred. (An error occurred while reading a database value for property 'FrameworkUser.Address'. The expected type was 'System.String' but the actual value was null.)
---> System.InvalidOperationException: An error occurred while reading a database value for property 'FrameworkUser.Address'. The expected type was 'System.String' but the actual value was null.
---> System.InvalidCastException: Unable to cast object of type 'System.DBNull' to type 'System.String'.
at MySqlConnector.MySqlDataReader.GetString(Int32 ordinal) in /_/src/MySqlConnector/MySqlDataReader.cs:line 283
at lambda_method70(Closure , QueryContext , DbDataReader , ResultContext , SingleQueryResultCoordinator )

经排查发现错误是由Nullable配置引起的,当他的值为enable,annotations时会报上面的错,值为disable,warnings时不报错。对了,我用的数据库是mysql

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.