The Problem:
An error message "System.Globalization.CultureNotFoundException: Only the invariant culture is supported in globalization-invariant mode." is being encountered when running the "update-database" command in the package manager console for database creation using EF Core 7.0.11. This seems to be due to the globalization-invariant mode being enabled.
The Solutions:
Solution 1: Check runtime options for globalization
The error is caused by the globalization-invariant mode being enabled. In this mode, only the invariant culture is supported. To fix the issue, you need to disable the globalization-invariant mode by setting the “System.Globalization.Invariant” property to false in the project’s runtime options.
- Open the project file (.csproj) in a text editor.
- Find the
runtimeOptions
section. - Set the
System.Globalization.Invariant
property tofalse
.
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RuntimeOptions>
<ConfigProperties>
<System.Globalization.Invariant>false</System.Globalization.Invariant>
</ConfigProperties>
</RuntimeOptions>
</PropertyGroup>
</Project>
-
Save the project file.
-
Rebuild the project.
The error should now be gone.
Solution 2: Update InvariantGlobalization to false
You need to change `InvariantGlobalization` to `false` in your project file. This setting controls whether or not the globalization-invariant mode is enabled. In globalization-invariant mode, only the invariant culture is supported. This setting must be set to `false` in order for EF Core to create the database correctly.
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<InvariantGlobalization>false</InvariantGlobalization>
</PropertyGroup>
Q&A
What exception occurs when using update-database
in package manager console?
System.Globalization.CultureNotFoundException is thrown.
What setting to change to resolve the error?
Set InvariantGlobalization
to false
in project file.
Where to find InvariantGlobalization
?
In PropertyGroup
of the project file.
Video Explanation:
The following video, titled "EF Core 8: Only the invariant culture is supported in globalization ...", provides additional insights and in-depth exploration related to the topics discussed in this post.
An unhandled exception has occurred while executing the request. System.Globalization.CultureNotFoundException: Only the invariant culture ...
The following video, titled "EF Core 8: Only the invariant culture is supported in globalization ...", provides additional insights and in-depth exploration related to the topics discussed in this post.
An unhandled exception has occurred while executing the request. System.Globalization.CultureNotFoundException: Only the invariant culture ...