[GH-ISSUE #525] Exception when loading the system tray icon #441

Open
opened 2026-02-26 09:31:25 +03:00 by kerem · 10 comments
Owner

Originally created by @KIRIZAMERAN on GitHub (Oct 3, 2019).
Original GitHub issue: https://github.com/NickeManarin/ScreenToGif/issues/525

Net.Framework: 4.8.0
System: Windows 10 1903
Language: Simplified Chinese

Stack trace:

Set property 'ScreenToGif.Controls.NotifyIcon.IconSource' threw an exception.

at System.Windows.Markup.XamlReader.RewrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri)
   at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
   at System.Windows.ResourceDictionary.CreateObject(KeyRecord key)
   at System.Windows.ResourceDictionary.OnGettingValue(Object key, Object& value, Boolean& canCache)
   at System.Windows.ResourceDictionary.OnGettingValuePrivate(Object key, Object& value, Boolean& canCache)
   at System.Windows.ResourceDictionary.GetValueWithoutLock(Object key, Boolean& canCache)
   at System.Windows.ResourceDictionary.GetValue(Object key, Boolean& canCache)
   at System.Windows.Application.FindResource(Object resourceKey)
   at ScreenToGif.App.Application_Startup(Object sender, StartupEventArgs e)
   at System.Windows.Application.OnStartup(StartupEventArgs e)
   at System.Windows.Application.<.ctor>b__1_0(Object unused)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
Originally created by @KIRIZAMERAN on GitHub (Oct 3, 2019). Original GitHub issue: https://github.com/NickeManarin/ScreenToGif/issues/525 **Net.Framework:** 4.8.0 **System:** Windows 10 1903 **Language:** Simplified Chinese Stack trace: ``` Set property 'ScreenToGif.Controls.NotifyIcon.IconSource' threw an exception. at System.Windows.Markup.XamlReader.RewrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri) at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri) at System.Windows.ResourceDictionary.CreateObject(KeyRecord key) at System.Windows.ResourceDictionary.OnGettingValue(Object key, Object& value, Boolean& canCache) at System.Windows.ResourceDictionary.OnGettingValuePrivate(Object key, Object& value, Boolean& canCache) at System.Windows.ResourceDictionary.GetValueWithoutLock(Object key, Boolean& canCache) at System.Windows.ResourceDictionary.GetValue(Object key, Boolean& canCache) at System.Windows.Application.FindResource(Object resourceKey) at ScreenToGif.App.Application_Startup(Object sender, StartupEventArgs e) at System.Windows.Application.OnStartup(StartupEventArgs e) at System.Windows.Application.<.ctor>b__1_0(Object unused) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler) ```
Author
Owner

@mrfearless commented on GitHub (Oct 3, 2019):

same as #388

<!-- gh-comment-id:537809415 --> @mrfearless commented on GitHub (Oct 3, 2019): same as #388
Author
Owner

@NickeManarin commented on GitHub (Oct 3, 2019):

Strange, the only place where I change the icon is right at the beginning of the app:

Like this: IconSource="/Resources/Logo.ico"

Are you running your Windows at a different color space than 32bits?
I'm going to add some checks to avoid the crash, at least.

<!-- gh-comment-id:538031900 --> @NickeManarin commented on GitHub (Oct 3, 2019): Strange, the only place where I change the icon is right at the beginning of the app: Like this: `IconSource="/Resources/Logo.ico"` Are you running your Windows at a different color space than 32bits? I'm going to add some checks to avoid the crash, at least.
Author
Owner

@NickeManarin commented on GitHub (Oct 3, 2019):

Can you test if it opens? This version is just for testing if it opens or not, there's some other broken features, so ignore it.
If it's opening, check if the icon is appearing on your notification area.

cc @mrfearless and @KIRIZAMERAN

ScreenToGif_Test.zip

<!-- gh-comment-id:538073126 --> @NickeManarin commented on GitHub (Oct 3, 2019): Can you test if it opens? This version is just for testing if it opens or not, there's some other broken features, so ignore it. If it's opening, check if the icon is appearing on your notification area. cc @mrfearless and @KIRIZAMERAN [ScreenToGif_Test.zip](https://github.com/NickeManarin/ScreenToGif/files/3687557/ScreenToGif_Test.zip)
Author
Owner

@mrfearless commented on GitHub (Oct 3, 2019):

It opens without any errors or messages displayed. Goes straight to the startup screen. The notification icon is blank - as in, it appears along side other icons (i noticed the shuffle as it added itself) in the tray notification area, but no icon is showing - just a fully transparent icon or space for where an icon would be.

Running Win7 x64 with full 32bit desktop colors

<!-- gh-comment-id:538104408 --> @mrfearless commented on GitHub (Oct 3, 2019): It opens without any errors or messages displayed. Goes straight to the startup screen. The notification icon is blank - as in, it appears along side other icons (i noticed the shuffle as it added itself) in the tray notification area, but no icon is showing - just a fully transparent icon or space for where an icon would be. Running Win7 x64 with full 32bit desktop colors
Author
Owner

@NickeManarin commented on GitHub (Oct 3, 2019):

Thank you. At least it opens now.

Now I need to understand why my icon is not loading.
It's strange because the file is attached to the executable and is the same that appears in the taskbar and in the executable file in the Windows Explorer. I'm assuming that you can see the ScreenToGif icon on your taskbar and in the executable file.

ScreenToGif_Test_2.zip
Here's another with a slightly changed initialization behavior.
If it still does not work, I'll have to export the icon again, exporting as 256 colors too.

<!-- gh-comment-id:538109191 --> @NickeManarin commented on GitHub (Oct 3, 2019): Thank you. At least it opens now. Now I need to understand why my icon is not loading. It's strange because the file is attached to the executable and is the same that appears in the taskbar and in the executable file in the Windows Explorer. I'm assuming that you can see the ScreenToGif icon on your taskbar and in the executable file. [ScreenToGif_Test_2.zip](https://github.com/NickeManarin/ScreenToGif/files/3687872/ScreenToGif_Test_2.zip) Here's another with a slightly changed initialization behavior. If it still does not work, I'll have to export the icon again, exporting as 256 colors too.
Author
Owner

@KIRIZAMERAN commented on GitHub (Oct 3, 2019):

test 1 open without error but icon problem same as mrfearless
test 2 open with error message:
the app crashed

System.Drawing.Initialize
at System.Drawing.Icon.Initialize(Int32 width, Int32 height)
at ScreenToGif.App.Application_Startup(Object sender, StartupEventArgs e)
at System.Windows.Application.OnStartup(StartupEventArgs e)
at System.Windows.Application.<.ctor>b__1_0(Object unused)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

Running Win10 x64 with full 32bit desktop colors

<!-- gh-comment-id:538110197 --> @KIRIZAMERAN commented on GitHub (Oct 3, 2019): test 1 open without error but icon problem same as mrfearless test 2 open with error message: the app crashed System.Drawing.Initialize at System.Drawing.Icon.Initialize(Int32 width, Int32 height) at ScreenToGif.App.Application_Startup(Object sender, StartupEventArgs e) at System.Windows.Application.OnStartup(StartupEventArgs e) at System.Windows.Application.<.ctor>b__1_0(Object unused) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler) Running Win10 x64 with full 32bit desktop colors
Author
Owner

@NickeManarin commented on GitHub (Oct 3, 2019):

Thank you. Same crash, looks like it's the same reason.
It's hard to know exactly what's wrong, specially without having a computer having the same crash.
I added the icon with 256 colors too.

ScreenToGif_Test_3.zip

<!-- gh-comment-id:538124334 --> @NickeManarin commented on GitHub (Oct 3, 2019): Thank you. Same crash, looks like it's the same reason. It's hard to know exactly what's wrong, specially without having a computer having the same crash. I added the icon with 256 colors too. [ScreenToGif_Test_3.zip](https://github.com/NickeManarin/ScreenToGif/files/3688042/ScreenToGif_Test_3.zip)
Author
Owner

@mrfearless commented on GitHub (Oct 4, 2019):

Test 2 crashed, Test 3 works, but icon is blank in tray - same as Test 1

<!-- gh-comment-id:538182095 --> @mrfearless commented on GitHub (Oct 4, 2019): Test 2 crashed, Test 3 works, but icon is blank in tray - same as Test 1
Author
Owner

@NickeManarin commented on GitHub (Nov 18, 2019):

Stack trace from @mrfearless

► Title - 
	On Dispacher Unhandled Exception - Unknown
▬ Message - 
	Set property 'ScreenToGif.Controls.NotifyIcon.IconSource' threw an exception.
○ Type - 
	System.Windows.Markup.XamlParseException
♦ [Version] Date/Hour - 
	[2.13.3] 10/16/2018 10:55:46
▲ Source - 
	PresentationFramework
▼ TargetSite - 
	Void RewrapException(System.Exception, System.Xaml.IXamlLineInfo, System.Uri)
♠ StackTrace - 
   at System.Windows.Markup.XamlReader.RewrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri)
   at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
   at System.Windows.ResourceDictionary.CreateObject(KeyRecord key)
   at System.Windows.ResourceDictionary.OnGettingValue(Object key, Object& value, Boolean& canCache)
   at System.Windows.ResourceDictionary.OnGettingValuePrivate(Object key, Object& value, Boolean& canCache)
   at System.Windows.ResourceDictionary.GetValueWithoutLock(Object key, Boolean& canCache)
   at System.Windows.ResourceDictionary.GetValue(Object key, Boolean& canCache)
   at System.Windows.Application.FindResource(Object resourceKey)
   at ScreenToGif.App.Application_Startup(Object sender, StartupEventArgs e)
   at System.Windows.Application.OnStartup(StartupEventArgs e)
   at System.Windows.Application.<.ctor>b__1_0(Object unused)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

▬▬ Message - 
	The operation completed successfully
○○ Type - 
	System.ComponentModel.Win32Exception
▲▲ Source - 
	System.Drawing
▼▼ TargetSite - 
	Void Initialize(Int32, Int32)
♠♠ StackTrace - 
   at System.Drawing.Icon.Initialize(Int32 width, Int32 height)
   at ScreenToGif.ImageUtil.ImageMethods.ToIcon(ImageSource imageSource)
   at ScreenToGif.Controls.NotifyIcon.IconSourcePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
   at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
   at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
   at System.Windows.Baml2006.WpfMemberInvoker.SetValue(Object instance, Object value)
   at MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(Object inst, XamlMember property, Object value)
<!-- gh-comment-id:555023610 --> @NickeManarin commented on GitHub (Nov 18, 2019): Stack trace from @mrfearless ``` ► Title - On Dispacher Unhandled Exception - Unknown ▬ Message - Set property 'ScreenToGif.Controls.NotifyIcon.IconSource' threw an exception. ○ Type - System.Windows.Markup.XamlParseException ♦ [Version] Date/Hour - [2.13.3] 10/16/2018 10:55:46 ▲ Source - PresentationFramework ▼ TargetSite - Void RewrapException(System.Exception, System.Xaml.IXamlLineInfo, System.Uri) ♠ StackTrace - at System.Windows.Markup.XamlReader.RewrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri) at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri) at System.Windows.ResourceDictionary.CreateObject(KeyRecord key) at System.Windows.ResourceDictionary.OnGettingValue(Object key, Object& value, Boolean& canCache) at System.Windows.ResourceDictionary.OnGettingValuePrivate(Object key, Object& value, Boolean& canCache) at System.Windows.ResourceDictionary.GetValueWithoutLock(Object key, Boolean& canCache) at System.Windows.ResourceDictionary.GetValue(Object key, Boolean& canCache) at System.Windows.Application.FindResource(Object resourceKey) at ScreenToGif.App.Application_Startup(Object sender, StartupEventArgs e) at System.Windows.Application.OnStartup(StartupEventArgs e) at System.Windows.Application.<.ctor>b__1_0(Object unused) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler) ▬▬ Message - The operation completed successfully ○○ Type - System.ComponentModel.Win32Exception ▲▲ Source - System.Drawing ▼▼ TargetSite - Void Initialize(Int32, Int32) ♠♠ StackTrace - at System.Drawing.Icon.Initialize(Int32 width, Int32 height) at ScreenToGif.ImageUtil.ImageMethods.ToIcon(ImageSource imageSource) at ScreenToGif.Controls.NotifyIcon.IconSourcePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e) at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e) at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args) at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType) at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal) at System.Windows.Baml2006.WpfMemberInvoker.SetValue(Object instance, Object value) at MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(Object inst, XamlMember property, Object value) ```
Author
Owner

@NickeManarin commented on GitHub (Nov 18, 2019):

From what I know about this error, it's Windows telling the user that it can't load anything else.
Too many GDI objects were already loaded.

If this issue happens again with you people, can you open Task Manager and go to Details, and right click on the header of the data grid, enable GDI objects and see if there's a process eating too much GDI objects.

image

<!-- gh-comment-id:555048498 --> @NickeManarin commented on GitHub (Nov 18, 2019): From what I know about this error, it's Windows telling the user that it can't load anything else. Too many GDI objects were already loaded. If this issue happens again with you people, can you open Task Manager and go to Details, and right click on the header of the data grid, enable GDI objects and see if there's a process eating too much GDI objects. ![image](https://user-images.githubusercontent.com/14798947/69062746-24143700-09fa-11ea-9cbb-c459b7fc1aeb.png)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/ScreenToGif#441
No description provided.