Skip to content

exception on binding WPF BitmapImage and german umlauts are used in file names (dotnet 9.0.0 / windows 11) #111355

Closed

Description

@wd72

Description

when using filenames on an UNC network share with german umlauts (ü,ö,ä) an Exception is thrown.

Reproduction Steps

use 2 files on unc network path:

\\ps-nas\Temp\products\TestU\testImage.jpg
\\ps-nas\Temp\products\TestÜ\testImage.jpg

WPF Code: (Windows Platform)

<Image Stretch="Uniform" StretchDirection="DownOnly" HorizontalAlignment="Center" Width="300" Height="300">
    <Image.Source >
       <BitmapImage UriSource="{Binding FullFileName2}" CacheOption="OnLoad" />
    </Image.Source>
</Image>

ViewModel/Model Code:

    public string FullFileName2 { get { return @"\\ps-nas\Temp\products\TestU\testImage.jpg"; } }   // --> this works
    public string FullFileName2 { get { return @"\\ps-nas\Temp\products\TestÜ\testImage.jpg"; } }   // --> this does not work 

Expected behavior

german umlauts in filenames should work like in dotnet 8.

Actual behavior

Inner Exception 1:
DirectoryNotFoundException: Could not find a part of the path '\\ps-nas\temp\products\testü\testimage.jpg\Temp\products\TestÜ\testImage.jpg'.

the Image class does not use the provided path an appends something weird. --> the modified file name does not exist --> Exception.

wrong filename:
\\ps-nas\temp\products\testü\testimage.jpg\Temp\products\TestÜ\testImage.jpg
should be:
\\ps-nas\temp\products\testü\testimage.jpg

Regression?

this bug does not occur in dotnet 8

Known Workarounds

No response

Configuration

dotnet 9.0.0, Windows 11 24H2,

   <TargetFramework>net9.0-windows</TargetFramework>
   <Nullable>enable</Nullable>
   <UseWPF>true</UseWPF>
   <UseWindowsForms>true</UseWindowsForms>
   <PlatformTarget>x64</PlatformTarget>

Other information

No response

Activity

  1. added
    untriaged
    on Dec 19, 2024
  2. dotnet-policy-service commented on Dec 19, 2024

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/area-system-io
    See info in area-owners.md if you want to be subscribed.

  3. transferred this issue fromdotnet/runtimeon Jan 13, 2025
  4. adamsitnik commented on Jan 13, 2025

    @adamsitnik
    Member

    the Image class does not use the provided path an appends something weird

    Because of that I've moved the issue to WPF.

  5. miloush commented on Jan 13, 2025

    @miloush
    Contributor

    @adamsitnik I am afraid that was a bit premature. Here is a repro not involving WPF:

    Uri bse = new Uri("http://microsoft.com");
    Uri rel = new Uri(@"\\ps-nas\Temp\products\TestÜ\testImage.jpg");
    Uri u = new Uri(bse, rel); // {file://ps-nas\temp\products\testü\testimage.jpg/Temp/products/TestÜ/testImage.jpg}
  6. transferred this issue fromdotnet/wpfon Jan 13, 2025
  7. ghost added
    needs-area-label
    on Jan 13, 2025
  8. added and removed
    needs-area-label
    on Jan 13, 2025
  9. dotnet-policy-service commented on Jan 13, 2025

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/ncl
    See info in area-owners.md if you want to be subscribed.

  10. adamsitnik commented on Jan 13, 2025

    @adamsitnik
    Member

    @miloush big thanks for catching that!

    I've moved it back to dotnet/runtime and added to System.Net area.

    The repro:

    Uri bse = new Uri("http://microsoft.com");
    Uri rel = new Uri(@"\\ps-nas\Temp\products\TestÜ\testImage.jpg");
    Uri u = new Uri(bse, rel); // {file://ps-nas\temp\products\testü\testimage.jpg/Temp/products/TestÜ/testImage.jpg}
    Console.WriteLine(u.ToString());
    > dotnet run -c Release -f net8.0
    file://ps-nas/Temp/products/TestÜ/testImage.jpg
    > dotnet run -c Release -f net9.0
    file://ps-nas\temp\products\testü\testimage.jpg/Temp/products/TestÜ/testImage.jpg
    
  11. added this to the 10.0.0 milestone on Jan 13, 2025
  12. removed
    untriaged
    on Jan 13, 2025
  13. MihaZupan commented on Jan 13, 2025

    @MihaZupan
    Member

    The test case asserts in debug :/
    This is a regression from #97579, looks like we have no test coverage for this case:

    • calling new Uri(base, relative)
    • relative uri is actually an absolute uri
    • the "relative" uri has non-ascii chars

    In #97579 I stated

    RestUnicodeNormalized is both checked and set only in ParseRemaining. But this method will be called exactly once if HasUnicode is set, so it will always be false for the one time it's checked.

    What I missed is that this helper exists where we will create a partial?? copy of the existing instance:

    private void CreateThisFromUri(Uri otherUri)
    {
    DebugAssertInCtor();
    // Clone the other URI but develop own UriInfo member
    _info = null!;
    _flags = otherUri._flags;
    if (InFact(Flags.MinimalUriInfoSet))
    {
    _flags &= ~(Flags.MinimalUriInfoSet | Flags.AllUriInfoSet | Flags.IndexMask);

    In this case that means that we've created an instance where the internal strings have already been transformed, but we'll transform them again since we didn't copy the part of the state that tells use we've already done so (hence the duplication). We'll hit debug asserts that assume those code paths are only reachable while in the ctor.
    The partial copy could also end up reading flags in a torn state on 32-bit if the existing instnace is being used by other threads.

  14. wd72 commented on Jan 13, 2025

    @wd72
    Author

    I added a unittest for this bug to my project and that showed another bug in Visual Studio:
    the string is colored incorrect , when a german umlaut is used (brown color instead of blue color).
    See red boxes in picture.

    Maybe the same bug, but i am not sure.....

        [Theory]
        [InlineData(@"c:\temp", "file:///c:/temp")]
        [InlineData(@"\\ps-nas\Temp\products\TestU\testImage.jpg", "file://ps-nas/Temp/products/TestU/testImage.jpg")]
        [InlineData(@"\\ps-nas\Temp\products\TestÜ\testImage.jpg", "file://ps-nas/Temp/products/TestÜ/testImage.jpg")]
        [InlineData(@"\\ps-nas\Temp\testÜmage.jpg", "file://ps-nas/Temp/testÜmage.jpg")]
        public void RunTest(string param, string expected)
        {
            Uri bse = new Uri("http://microsoft.com");
            Uri rel = new Uri(param);
            Uri u = new Uri(bse, rel);
    
            Assert.Equal(rel.ToString(), expected);
            Assert.Equal(u.ToString(), expected);
        }
    

    Image

  15. miloush commented on Jan 13, 2025

    @miloush
    Contributor

    @wd72 that is an unrelated issue, you should file that one through Visual Studio.

  16. MihaZupan commented on Jan 14, 2025

    @MihaZupan
    Member

    As a possible workaround, you can avoid this issue by ensuring that BitmapImage.BaseUri is null (e.g. via a custom IValueConverter). If the base isn't set, your full path won't get mangled.

  17. self-assigned this
    on Jan 21, 2025
  18. added
    in-pr
    on Jan 22, 2025
  19. locked and limited conversation to collaborators on Feb 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-System.Netbugin-prregression-from-last-release

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions