Skip to content

IfcXml reading fails under Turkish culture (culture-sensitive ToUpper() in type lookup) #670

Description

@oguzozshn

Summary

The IfcXml readers resolve Express type names by upper-casing the XML element name with the
culture-sensitive string.ToUpper(), while the metadata dictionary is keyed on invariant upper
case. Under the Turkish (and Azeri) casing rules i maps to İ (U+0130), so the lookup never
matches:

tr-TR      "IfcOrganization".ToUpper()          => "IFCORGANİZATİON"
invariant  "IfcOrganization".ToUpperInvariant() => "IFCORGANIZATION"

Every IFC type name contains an i, so on a machine whose current culture is Turkish, reading
IfcXml fails completely.

Reproduction

[Theory]
[InlineData("en-US")]
[InlineData("tr-TR")]
public void Can_read_ifcxml_regardless_of_current_culture(string culture)
{
    var previous = CultureInfo.CurrentCulture;
    try
    {
        CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo(culture);

        using var model = new MemoryModel(new EntityFactoryIfc4());
        model.LoadXml(@"TestFiles\Dimensions.ifcxml");

        Assert.True(model.Instances.Count > 0);
    }
    finally
    {
        CultureInfo.CurrentCulture = previous;
    }
}

en-US passes. tr-TR fails with:

Xbim.Common.Exceptions.XbimParserException : IfcProjectLibraryis not an IPersistEntity type

Running the whole Xbim.Essentials.Tests suite on a tr-TR machine gives 30 failures on current
master (e3c8777), for both net48 and net10.0. A typical message is:

Error reading XML, Line=14, Position=6, Tag='IfcOrganization'
 ---> System.Exception: Illegal XML element tag

CI does not catch this because it runs under an English culture.

Affected call sites

Reading (the cause of the failures above):

  • Xbim.IO.MemoryModel/Xml/XbimXmlReader4.cs - GetExpresType (2 calls)
  • Xbim.IO.MemoryModel/Xml/XbimXmlReader3.cs - IsIfcProperty, IsIfcType (2 calls), IsIfcEntity

Writing (same class of problem, surfaced by the round-trip and serialization tests):

  • Xbim.IO.MemoryModel/Xml/XbimXmlWriter4.cs - enum values
  • Xbim.IO.MemoryModel/Xml/IfcXmlWriter3.cs - enum values
  • Xbim.Common/Step21/Part21Writer.cs - select type names and enum values
  • Xbim.Common/Step21/StepFileHeader.cs - schema name
  • Xbim.IO.Esent/IPersistEntityExtensions.cs - select type names

Suggested fix

Use ToUpperInvariant() / ToLowerInvariant() on these paths. With that change the suites are
green on a tr-TR machine: 497/497 in Xbim.Essentials.Tests and 95/95 in
Xbim.Essentials.NetCore.Tests.

I have the fix and the culture-parameterised regression test working locally. Happy to open a PR
against develop if you would like it.

Environment

  • XbimEssentials master @ e3c8777
  • .NET SDK 10.0.302, targets net10.0 and net48
  • Windows 11, CurrentCulture = tr-TR

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions