Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entity Framework Core 8: CultureNotFoundException #2237

Closed
patr543a opened this issue Nov 22, 2023 · 6 comments
Closed

Entity Framework Core 8: CultureNotFoundException #2237

patr543a opened this issue Nov 22, 2023 · 6 comments

Comments

@patr543a
Copy link

patr543a commented Nov 22, 2023

I have a solution with and API when i call the Get method on my BookingController it goes all the way through my method without issues but somewhere during the returning from the database the error occurs. I was unsure what to include and not to include so i have included a .zip file with all the projects that are used for the API, other files that wasn't strictly needed is not included if anything else is require i can give it as well so i hope this is enough.

TurboCart.zip

The resulting error in Swagger

System.Globalization.CultureNotFoundException: Only the invariant culture is supported in globalization-invariant mode. See https://aka.ms/GlobalizationInvariantMode for more information. (Parameter 'name')
en-us is an invalid culture identifier.
   at System.Globalization.CultureInfo.GetCultureInfo(String name)
   at Microsoft.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry, SqlConnectionOverrides overrides)
   at Microsoft.Data.SqlClient.SqlConnection.InternalOpenAsync(CancellationToken cancellationToken)
--- End of stack trace from previous location ---
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenInternalAsync(Boolean errorsExpected, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenInternalAsync(Boolean errorsExpected, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenAsync(CancellationToken cancellationToken, Boolean errorsExpected)
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.InitializeReaderAsync(AsyncEnumerator enumerator, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func`4 operation, Func`4 verifySucceeded, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()
   at System.Text.Json.Serialization.Converters.IAsyncEnumerableOfTConverter`2.OnWriteResume(Utf8JsonWriter writer, TAsyncEnumerable value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonCollectionConverter`2.OnTryWrite(Utf8JsonWriter writer, TCollection value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonConverter`1.TryWrite(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonConverter`1.WriteCore(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.SerializeAsync(Stream utf8Json, T rootValue, CancellationToken cancellationToken, Object rootValueBoxed)
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.SerializeAsync(Stream utf8Json, T rootValue, CancellationToken cancellationToken, Object rootValueBoxed)
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.SerializeAsync(Stream utf8Json, T rootValue, CancellationToken cancellationToken, Object rootValueBoxed)
   at Microsoft.AspNetCore.Mvc.Formatters.SystemTextJsonOutputFormatter.WriteResponseBodyAsync(OutputFormatterWriteContext context, Encoding selectedEncoding)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeResultAsync>g__Logged|22_0(ResourceInvoker invoker, IActionResult result)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResultFilterAsync>g__Awaited|30_0[TFilter,TFilterAsync](ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
   at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)
Finding DbContext classes in the project...
Found DbContext 'TurboCartContext'.
TurboCart.Infrastructure.Persistance.Contexts.TurboCartContext

EF Core version: 8.0.0
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 8.0
Operating system: Windows 10
IDE: Visual Studio 2022 17.9 Preview 1.0

EDIT: As @roji said i have now made a new post on the documentation missing. Here

@ajcvickers ajcvickers transferred this issue from dotnet/efcore Nov 22, 2023
@patr543a
Copy link
Author

The issue appears to be caused by an undocumented breaking change in .NET 8. The ASP.NET Core WebAPI now includes the true in the .csproj file which seams like a mistake.

@roji
Copy link
Member

roji commented Nov 24, 2023

@patr543a if you believe there's an undocumented breaking change in .NET 8, can you please open an issue for that and reference it here?

@roji roji closed this as not planned Won't fix, can't repro, duplicate, stale Nov 24, 2023
@eerhardt
Copy link
Member

@patr543a - what version of Microsoft.Data.SqlClient are you using? #1917 made this a better error experience. Instead of getting the above exception, you should get:

"Globalization Invariant Mode is not supported."

<data name="SQL_GlobalizationInvariantModeNotSupported" xml:space="preserve">
<value>Globalization Invariant Mode is not supported.</value>
</data>

@ff-ils
Copy link

ff-ils commented Nov 29, 2023

In addition to having a better error message, there should be the possibility to make InvariantGlobalization work in new projects. The old behavior should be the default to avoid causing issues in existing projects, but for new projects, it represents a problem not being able to use invariant globalization. Especially in large projects with many developers, it is essential to have a default and not have to specify "InvariantCulture" or "StringComparison.Ordinal" in every method that requires it, because it's possible to make mistakes.

@patr543a
Copy link
Author

@patr543a - what version of Microsoft.Data.SqlClient are you using? #1917 made this a better error experience. Instead of getting the above exception, you should get:

"Globalization Invariant Mode is not supported."

<data name="SQL_GlobalizationInvariantModeNotSupported" xml:space="preserve">
<value>Globalization Invariant Mode is not supported.</value>
</data>

Pretty sure i am using the newest since i am using .NET 8

@patr543a
Copy link
Author

In addition to having a better error message, there should be the possibility to make InvariantGlobalization work in new projects. The old behavior should be the default to avoid causing issues in existing projects, but for new projects, it represents a problem not being able to use invariant globalization. Especially in large projects with many developers, it is essential to have a default and not have to specify "InvariantCulture" or "StringComparison.Ordinal" in every method that requires it, because it's possible to make mistakes.

It does work in new project and old projects it only breaks when code tries to use methods that it disables

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants