10.0 PostgreSql InvalidCastException with DateTime
See original GitHub issueI encountered the following error when trying to launch a brand new project with v10.0 and PostgreSql :
InvalidCastException : Cannot write DateTime with Kind=Local to PostgreSQL type ‘timestamp with time zone’, only UTC is supported.
To resolve it I needed to add the following line of code in the ConfigureServices method :
System.AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
I don’t know if it’s a good way to resolve this but at least it work’s for now.
Resources I’ve found about it : https://github.com/npgsql/efcore.pg/issues/2000 https://www.npgsql.org/efcore/release-notes/6.0.html
Hope it helps.
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Cannot write DateTime with Kind=UTC to PostgreSQL type ...
A. Solved by adding. AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); to the Startup Configure method.
Read more >Datetime error with .NET 6 and PostgreSQL - Duong's Blog
It says that you've asked Npgsql to send an Unspecified DateTime as a PG timestamptz type, e.g. by setting NpgsqlDbType.
Read more >15: B.2. Handling of Invalid or Ambiguous Timestamps
Ordinarily, if a date/time string is syntactically valid but contains out-of-range field values, an error will be thrown. For example, input specifying the ......
Read more >5.5. Date/Time Types
Table 5-10 shows some possible inputs for the date type. ... Note: If an invalid time zone is specified, the time zone becomes...
Read more >PostgreSQL: Documentation: 8.1: Date/Time Key Words
The key word ABSTIME is ignored for historical reasons: In very old releases of PostgreSQL, invalid values of type abstime were emitted as...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I had the same problem on empty database. Before legacy timestamp behavior applied
: base(options)
is called And the base class constructor seeds the default data and throws the exceptionWe’ll take a look if we can add default configuration in our extension methods to avoid this problem!