C# program crash (.ico file)

The program crashes if there's no .ico file inside the same folder. I have:

  1. Added the MyIcon.ico file in the Application section, also 'embed manifest with default settings' is checked.
  2. Made the .ico file as Embedded Resource (Build Action) in the .ico file properties.
  3. Added this.Icon = new Icon("plat.ico"); in the Public form.

So... why is the application not booting? What gives?


The constructor for Icon you are using tries to read "plat.ico" as a filename, not from embedded resources.

If you want to load the Icon from resources, you will need to explicitly get a Stream from the resource, then pass that into the Icon's constructor.

This will likely be something similar to:

// Add using System.Reflection; at the top of your file...

this.Icon = new Icon(

Alternatively, you can use the constructor overload that pulls directly from a resource, by name, instead of a filename:

this.Icon = new Icon(this.GetType(), "plat.ico");

I had the same problem in a windows form, where the icon could not be found even though it was in the same directory as the form.

notifyIcon1.Icon = new Icon("enabled.ico");

I looked at the .ico file's properties in VS2010 and saw that Copy to Output Directory was set to Do not copy. I changed it to Copy always and that did the trick.

Sometimes the simplest solution is the best solution.

You need to set the icon file's "Copy to Output" to "Copy Always" or "Copy if Newer".

You are invoking wrong constructor. Just use this:

this.Icon = new Icon(this.GetType(), "plat.ico");

Need Your Help

Transforming an element inside an SVG in Microsoft Edge Doesn't Work

css svg transform microsoft-edge

For some reason Microsoft Edge doesn't allow you to do transforms on elements inside of an SVG. Fills work fine (so I know the element targeting is working) but transforms are entirely ignored. This

what are the parameters for fire select event in openui5 tree?

javascript jquery sapui5

Hi i am using openui5 tree.by default first my first node to be selected.