Link to home
Start Free TrialLog in
Avatar of virtualblackfox
virtualblackfox

asked on

Assembly Icon

I need to know the icon of my assembly, i know that he is in my assembly as a resource but i can't find how to use it.

Stream st = Assembly.GetExecutingAssembly().GetManifestResourceStream("MyNameSpace.MyApp.1");

I have tryed that because the icon in the assembly as no name and ResHacker show it as the icon n°1...
ASKER CERTIFIED SOLUTION
Avatar of eric_duncan
eric_duncan

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
To use the embedded file use the following code:

Assembly thisAssembly = Assembly.GetAssembly(this.GetType());
Stream imageStream = thisAssembly.GetManifestResourceStream("ASSEMBLY.FILENAME");
Bitmap image = new Bitmap(imageStream);

You have to be very careful getting the ASSEMBLY and FILENAME correct when loading resources. For example if you created an assembly called "EmbeddedIcon" and you put your icon (Test.ico) in a "Resources" folder then your string should be "EmbeddedIcon.Resources.Test.ico".

If you are having trouble determining the exact string for loading your resource then use the GetManifestResourceNames() method to see all the resources available in your assembly.
Avatar of eric_duncan
eric_duncan

Thanks for the points! Let me know if you have any more questions.

Eric
Avatar of virtualblackfox

ASKER

"A request has been made to change the grade"

Accepted, the grade was set because the answer wasen't realy one for my exact problem.
But i haven't stated it correctly.

Using Windows API function is impossible, because i want that my code run both with mono and microsoft frameworks on all platforms (BSD and Windows for Microsoft, Windows and Unixes for Mono)

The only solution is writing my own class who read PE executable format and extract the resource, maybe re-using class Mono/Microsoft use for disasembling / Reflection if they are complete enough to list resource.

Including the icon in both managed and PE Standard resource is still possible but don't seem "pretty" to me.

Again, sorry for not following the Guidelines / Asking badly formulated questions.