9

I'm dealing with a very weird problem in WPF which only happens on ONE computer so far. The app in question has been installed hundreds of times, so I suspect missing dependencies of some sort, although this is a .NET Core 3.1 app.

So the app downloads icon images and the view binds to the icon via an exposed property in the ViewModel:

IconImage = new BitmapImage();
IconImage.BeginInit();
IconImage.UriSource = new Uri("LocalFilePath");
IconImage.DecodePixelWidth = 50;
IconImage.EndInit();

Where LocalFilePath is the path to the cached icon image. The image is a PNG file, it's size is 50x50 px.

The code above failes with an exception:

Message -> The image data generated an overflow during processing.
Source ->PresentationCore
 Trace ->    at System.Windows.Media.Imaging.ColorConvertedBitmap.FinalizeCreation()
   at System.Windows.Media.Imaging.ColorConvertedBitmap..ctor(BitmapSource source, ColorContext sourceColorContext, ColorContext destinationColorContext, PixelFormat format)
   at System.Windows.Media.Imaging.BitmapImage.FinalizeCreation()
   at System.Windows.Media.Imaging.BitmapImage.EndInit()
InnerException -> Overflow or underflow in the arithmetic operation

What baffles me is that this only happens on one computer, running Windows 10 Home Edition with the latest updates. Has anyone seen this error before? Might there be a better, alternative way for exposing PNG images for the view?

6
  • You don't need to set the decode pixel width property if it's indeed a 50x50 png file. Commented Aug 20, 2020 at 17:50
  • That's true, the original code didn't have this piece set. I thought I'd add it anyway to prevent some sort of calculation which leads to the overflow. But both versions cause the same exception: csharp IconImage = new BitmapImage("LocalFilePath"); Commented Aug 20, 2020 at 17:56
  • UriSource is not string , and should be like this : IconImage.UriSource = new Uri(path) Commented Aug 20, 2020 at 18:16
  • Thanks, it was meant to be an Uri, I have edited the question accordingly Commented Aug 20, 2020 at 18:42
  • Does the image contains an embedded color profile? Commented Aug 27, 2020 at 1:29

2 Answers 2

15

A few of our customers got the same error message recently. To fix this, we made sure that all settings in the color management window are "system default". In one instance, "device profile" was set to "virtual SRGB" which caused this issue.

It may also help to set IgnoreColorProfile in BitmapImage.CreateOptions.

Windows Color Management

Sign up to request clarification or add additional context in comments.

3 Comments

Just had a customer who was facing the described error, setting image.CreateOptions = BitmapCreateOptions.IgnoreColorProfile solved the issue. Thank you!
Thank you! This solved an issue a customer of mine was facing. If it wasn't for this post, I would still have been in the dark.
Thank you! This exact issue happened with one of our customers too. The WPF app would continue running, just not display line items in some windows. It was very confusing trying to troubleshoot what could be going on.
1

Binding directly to the Uri Property instead of the BitmapImage solved the problem. Although this is not really a fix and does not explain why the Exception was thrown in the first place, it is at least a work around.

2 Comments

Can you please share a code example for this? I ran into the exact same issue here. For me it looks like it has something to do with the latest Windows 10 Updates (Build 2004)
To answer myself here are 2 code snippets I ended up using: <Image Source="pack://application:,,,/MyApp;component/Assets/MyImage.png" /> for XAML code and image.Source = new ImageSourceConverter().ConvertFromString("pack://application:,,,/MyApp;component/Assets/MyImage.png") as ImageSource; for code behind / viewmodels.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.