C# – resources.GetObject(“$this.Icon”) crashes application on Windows XP

cexceptionresourceswindows-xp

I've made this program which works fine in Windows 7, but it doesn't seem to work in Windows XP, as it crashed right away with a 'Program has closed bla bla send error report' message from Windows.
After some googling I found a solution to get myself an exceptionlog in the Event Log.
This is the result:

Edit: new exception log (with unhandled exception filter)

Exception: Het doel van een aanroep heeft een uitzondering veroorzaakt.
bij System.RuntimeMethodHandle._SerializationInvoke(Object target,
SignatureStruct& declaringTypeSig, SerializationInfo info,
StreamingContext context) bij
System.RuntimeMethodHandle.SerializationInvoke(Object target,
SignatureStruct declaringTypeSig, SerializationInfo info,
StreamingContext context) bij
System.Reflection.RuntimeConstructorInfo.SerializationInvoke(Object
target, SerializationInfo info, StreamingContext context) bij
System.Runtime.Serialization.ObjectManager.CompleteISerializableObject(Object
obj, SerializationInfo info, StreamingContext context) bij
System.Runtime.Serialization.ObjectManager.FixupSpecialObject(ObjectHolder
holder) bij System.Runtime.Serialization.ObjectManager.DoFixups()
bij
System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler
handler, __BinaryParser serParser, Boolean fCheck, Boolean
isCrossAppDomain, IMethodCallMessage methodCallMessage) bij
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream
serializationStream, HeaderHandler handler, Boolean fCheck, Boolean
isCrossAppDomain, IMethodCallMessage methodCallMessage) bij
System.Resources.ResourceReader.DeserializeObject(Int32 typeIndex)
bij System.Resources.ResourceReader.LoadObjectV2(Int32 pos,
ResourceTypeCode& typeCode) bij
System.Resources.ResourceReader.LoadObject(Int32 pos,
ResourceTypeCode& typeCode) bij
System.Resources.RuntimeResourceSet.GetObject(String key, Boolean
ignoreCase, Boolean isString) bij
System.Resources.RuntimeResourceSet.GetObject(String key, Boolean
ignoreCase) bij System.Resources.ResourceManager.GetObject(String
name, CultureInfo culture, Boolean wrapUnmanagedMemStream) bij
System.Resources.ResourceManager.GetObject(String name) bij
STREDIT.frmMain.InitializeComponent() bij STREDIT.frmMain..ctor()
bij STREDIT.Program.Main()

I've found the place where it crashed:

this.Controls.Add(this.statusStrip1);
this.Controls.Add(this.menuStrip1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); // Here
this.MainMenuStrip = this.menuStrip1;
this.MinimumSize = new System.Drawing.Size(726, 220);

Does anyone have an idea why this happens?

Thanks in advance

Best Answer

Icon type correct or not, there is a solution to handle it correctly:

  • put the icons into Assembly's resource file (if you haven't)
  • access the icon like this:

    this.Icon = global::AEM.UI.Properties.Resources.your_icon_name;
    
Related Topic