-
Notifications
You must be signed in to change notification settings - Fork 24
Open
Description
Summary
When using Region.FromRegionId() in the OCI .NET SDK, the runtime throws a CultureNotFoundException because the SDK internally calls:
new CultureInfo("en-US", useUserOverride: false)In Docker (Alpine-based images), .NET defaults to Globalization Invariant Mode, where only the invariant culture is available. As a result, "en-US" cannot be created, and the OCI SDK fails to initialize the region registry, throwing this error:
System.TypeInitializationException: The type initializer for 'Oci.Common.Region' threw an exception.
---> System.Globalization.CultureNotFoundException: Only the invariant culture is supported in globalization-invariant mode.
en-US is an invalid culture identifier.
at System.Globalization.CultureInfo..ctor(String name, Boolean useUserOverride)
at Oci.Common.Region.Register(...)
at Oci.Common.Region..cctor()
--- End of inner exception stack trace ---
at Oci.Common.Region.FromRegionId(String regionId)
Environment
- OCI .NET SDK: v85.0.0
- .NET Runtime: .NET 9
- OS: Linux (Alpine base image)
- Environment: Docker container
- Globalization mode: Invariant mode
Use Case
Creating an OCI Object Storage client using:
var provider = new SimpleAuthenticationDetailsProvider
{
TenantId = credentials.Tenancy,
UserId = credentials.UserId,
Fingerprint = credentials.Fingerprint,
Region = Region.FromRegionId(credentials.RegionEndpoint),
PrivateKeySupplier = new StringBasedPrivateKeySupplier(credentials.PrivateKey)
};
var client = new ObjectStorageClient(provider);Reproducible Example (Default Single-Project Setup)
Dockerfile
This Dockerfile represents a standard minimal C# project built and run in Docker
FROM mcr.microsoft.com/dotnet/sdk:9.0-alpine AS build
WORKDIR /src
COPY . .
RUN dotnet restore
RUN dotnet publish -c Release -o /app/publish
FROM mcr.microsoft.com/dotnet/aspnet:9.0-alpine
WORKDIR /app
COPY --from=build /app/publish .
ENTRYPOINT ["dotnet", "OciIntegrationTest.dll"]Program.cs (Minimal Repro)
using Oci.Common;
using Oci.ObjectstorageService;
var region = Region.FromRegionId("eu-frankfurt-1"); // <-- exception here
Console.WriteLine(region.RegionId);This reproduces the crash on every Alpine-based .NET image unless the user manually installs ICU and disables invariant mode.
Expected Behavior
- Should work in Docker without requiring ICU libraries
- Or fallback to CultureInfo.InvariantCulture when running under invariant mode
Suggested Fix
Consider replacing:
regionId.Trim().ToLower(new CultureInfo("en-US", useUserOverride: false));with:
regionId.Trim().ToLower(CultureInfo.InvariantCulture);alin-opswatnickolasdanielschesa and aling93
Metadata
Metadata
Assignees
Labels
No labels