Image Source fails to load an image if application path has hash sign in it
See original GitHub issue- .NET Core Version: 6.0.4
- Windows version: Windows 11 21H2
- Does the bug reproduce also in WPF for .NET Framework 4.8?: Yes
Problem description:
It is possible to specify Image source with relative path in XAML definition:
Icon="Images/app.dark.png"
However, this definition fails to load image if the path containing application has #
symbol.
Actual behavior:
In .Net 6
Fails in BitmapDecoder.SetupDecoderFromUriOrStream
with System.IO.DirectoryNotFoundException
which transforms to exception going out:
System.Windows.Markup.XamlParseException: "System.Windows.Baml2006.TypeConverterMarkupExtension" throws an exception."
Expected behavior: We should load image with relative path without crash.
Minimal repro:
- Create a WPF application
- Add image in subfolder and specify its Build Action as Content and Copy to Output Directory as Copy or Copy if newer
- Specify main window Icon image with relative path
<Window x:Class="WpfApp1.MainWindow" Icon="Images/app.dark.png">
- Start an application and check everything is okay
- Rename the project path into
#WpfApp1
- Start an application
- Get an exception shown above
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:5 (2 by maintainers)
Top Results From Across the Web
HTML <img src> wont load my images
Try to work with the full path as: <img src="http://www.yourdomain.com/images/me.jpg" width="200" height="267" alt="me">.
Read more ><img>: The Image Embed element - HTML - MDN Web Docs
The above example shows usage of the <img> element: The src attribute is required, and contains the path to the image you want...
Read more >Components: <Image>
A loader is a function returning a URL string for the image, given the following parameters: src; width; quality. Here is an example...
Read more >Lazy Loading Images – The Complete Guide
Everything about Image Lazy loading - what is it, why is it important, how to implement lazy loading of images and the best...
Read more >Image - Expo Documentation
A cross-platform and performant React component that loads and renders images.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@lncubus Thank you.
Duplicate of https://github.com/dotnet/wpf/issues/4781
And I fixed it in https://github.com/dotnet/wpf/pull/5066
Yeah, as @lindexi mentioned this is a duplicate of #4781, hence we are marking it closed as of now and will keep tracking the bug from the original issue. Also, we will take a look at the PR #5066 from @lindexi, to get to a resolution.