WPF - Exception when load a image by URL

2

I have a problem with downloading a image by URL into a BitmapImage.

On some workstations this is not working. I dont know why ...

For example, on my own workstation, this works fine. Same OS, same network.

Well .. I have a little code which loads some images from a webserver and displays them in a ListView.

This code-part handles the download:

Application.Current.Dispatcher.Invoke((Action)(delegate
                   {
                       try
                       {
                           DTOBild dtoBild = new DTOBild();
                           BitmapImage small_image_bmp = new BitmapImage(new Uri( "http://our-own-server/images/99999999/" + bild));


                           dtoBild.bitmap = small_image_bmp;

                           this.listeBilder.Add(dtoBild);
                       }
                       catch (Exception ex)
                       {
                           log.schreibeFehler("Error at loading image. Stack is following ...");
                           log.schreibeFehler(ex.Message);
                           log.schreibeFehler(ex.StackTrace);

                       }
                   }));

It crashes in this line:

      BitmapImage small_image_bmp = new BitmapImage(new Uri( "http://our-own-server/images/99999999/" + bild));

This is the exception:

Ausnahme von HRESULT: 0x80072EE4 bei System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo) bei System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode) bei MS.Win32.WinInet.get_InternetCacheFolder() bei System.Windows.Media.Imaging.BitmapDownload.BeginDownload(BitmapDecoder decoder, Uri uri, RequestCachePolicy uriCachePolicy, Stream stream) bei System.Windows.Media.Imaging.LateBoundBitmapDecoder..ctor(Uri baseUri, Uri uri, Stream stream, BitmapCreateOptions createOptions, BitmapCacheOption cacheOption, RequestCachePolicy requestCachePolicy) bei System.Windows.Media.Imaging.BitmapDecoder.CreateFromUriOrStream(Uri baseUri, Uri uri, Stream stream, BitmapCreateOptions createOptions, BitmapCacheOption cacheOption, RequestCachePolicy uriCachePolicy, Boolean insertInDecoderCache) bei System.Windows.Media.Imaging.BitmapImage.FinalizeCreation() bei System.Windows.Media.Imaging.BitmapImage.EndInit()

Does anybody can help me?

c#
.net
wpf
image
bitmap
asked on Stack Overflow Apr 16, 2014 by Maximus1809

2 Answers

1

TL;DR: Check the registry key HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders and fix any non-existing/inaccessible/otherwise invalid paths - then log off and on again.

I hit this problem too. So first off, 0x2ee4 = 12004 = ERROR_INTERNET_INTERNAL_ERROR, so HRESULT 0x80072EE4 = HRESULT_FROM_WIN32(ERROR_INTERNET_INTERNAL_ERROR)

Now that doesn't tells you much, so I had to trace all the way through wininet.dll to figure it out. In my case the error turned out to originate from WININET!CCacheClientCounters::Initialize, and was actually caused by my Cache and Cookies shell folders somehow being set to invalid values. You can find the shell folder settings in the registry key HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders. Note that you will have to at least log out and in again for the changes to take effect.

This was what fixed it for me, but since that error can mean any sort of thing that could go wrong it might not be your problem. I did RE quite a bit of the initialization of the cache stuff in wininet.dll, and the only logging is a few ETW traces with what seems to be referring to linenumbers in the original source, so it really won't help much in debugging it for anyone outside of Microsoft.

answered on Stack Overflow Jun 19, 2018 by poizan42 • edited Jun 19, 2018 by poizan42
0

From what can be seen in the stack trace the problems seems to be caused by an attempt to access the system's downloaded image cache. You may try to bypass the cache while loading images, by setting the BitmapCreateOptions.IgnoreImageCache flag:

var small_image_bmp = new BitmapImage();
small_image_bmp.BeginInit();
small_image_bmp.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
small_image_bmp.UriSource = new Uri("http://our-own-server/images/99999999/" + bild);
small_image_bmp.EndInit();

This is however just a guess.

answered on Stack Overflow Apr 16, 2014 by Clemens

User contributions licensed under CC BY-SA 3.0