• 0

[C#] Icon resource is duplicate in the built executable


Question

Hi,

When my application doesn't have any icon resources, all other resources and code produce a 121kb exe file. Then, I manually add the application icon resource to the "Resources.resx" file under the "Icons" category. After that, I compile the application again and since my icon has 66kb, the exe becomes 187kb. Then I open my application project settings and set the application icon by selecting it from the dropdown. After compiling the application again, the exe is now 253kb (187 + 66).

How is that possible? I'm using the same resource, why does the exe size increases like this?

Anyway to workaround the problem?

17 answers to this question

Recommended Posts

  • 0

^ It's actually a good idea. These days, programmers tend to not care about memory usage; after all, 66kb isn't much memory at all. But neither is 1MB or even 10MB. But wasted memory is wasted memory. The smaller the size, the better. :)

  • 0

i guess wad u could do is either just by choosing the application icon from the browse button.. which will not end up in the resources or by adding it into the resources but not compiling the resources as a embedded content so it will not get embedded twice.. u can do that by clicking on resources.resx in the solution explorer and changing the build action to none..

either way it doesnt hurt does it >.>

  • 0
I'm not sure what you mean...

first way: (not adding icon to resources)

under project properties > application (the tab where u select your icon) > browse to the icon in your drive

second way: (add icon to resources but dont embed the resources)

add the icon to the project resources then click on Resources.resx under the solution explorer and change the build action property from Embedded Resource to None

either way so the icon will not get embedded twice =.= zzz

  • 0

I can't do either of that...

I want my icon to be the icon for the .exe file and for the main application window. For the application window, I have to add it to the resources file (or to the form resources, but it will be the same thing). And since I need to add the icon to the resources file to use it as the form icon, why can't I just select "use the same icon" for the .exe?

  • 0

Looks that way mate, I can't really provide a real solution. I know how annoying things like this can be, especially if you are a perfectionist like me. And by the sound of most of your posts, you are.

Will keep an eye out for solutions, but at the moment, I cant find any.

  • 0

Hi guys,

I was just wondering if any of you had figured out a solution to this problem? I am having the same issue in VS2008 c#. I add the icon on the properties page which causes it to be embedded but I cannot then get access to it from the:

System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("resource_file_name");

It does not appear to exist in the assembly, I use the GetManifestNames function to read all the resources and it is not listed.

To make it work I must also add the icon file in solution explorer and set it as an embedded resource, then I am able to reference it in this fashion. Each form can then reference this resource without it being embedded even more times which is what happens if you just choose the icon file from the form properties menu (rubbish).

Oh and also with my method of loading the resource file by hand at form startup it does not get displayed in the design window, also rubbish.

So I have limited it to a single duplicate for my application but it would be nice to cut this down to one, surely it is possible.

Can the .exe be specified from the code/by hand without using the properties page? Then you could use a single .ico resource.

cheers

ed

  • 0

I think you'd need to access the resource in a different way. The actual program icon would be stored within a specific .rsrc section of the PE format of the file. An executable .NET assembly is a normal Windows PE file with .NET headers. The main icon resource for the program would be stored according to the PE file format, so would not be accessible through the ManifestResourceStream method.

  • 0

i have skim read this thread, so excuse me if i have the wrong end of the stick..

but there is a bug(?) in visual studio that does not show the icon you select in your project properties screen on the windows forms during debug mode..

have you tried building installer packages for your applications and installing them to your local system?

the icons *should* appear in your app window at the top left

  • 0

hey,

I haven't tried that. I'm hoping my application will be a single executable and not need too much installing but it is a good suggestion. Maybe we just have to accept two copies of the icon file, I suppose it's not too bad, it would be nice to see a fix tho.

ed

  • 0

I came across this thread through Google some time ago when writing an application because I had the same problem as the OP. I just lived with the fact that I would have to have the icon in the executable twice. I had the same problem again, today, and a light bulb went off. This still isn't as clean as it should be, but you can do it like this:

In your application's properties (Project -> Properties), set the icon to the file you want it to use. Leave the icon for the form as the default. In the form's constructor (under InitializeComponent()) or in the form's Load event, add this:

this.Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath);

This get's the application's icon that you set in the properties (and the one that is seen by Explorer, etc) and sets it as your form's icon at run-time. Hope this helps anyone Googling in the future.

Edit: It's worth noting, however, that this doesn't seem to work when running the application from anything other than the local machine (i.e. from a Windows share).

Edited by todd
  • 0
Edit: It's worth noting, however, that this doesn't seem to work when running the application from anything other than the local machine (i.e. from a Windows share).

It'd be more efficient to PInvoke the LoadIcon API function, and this will prevent you from being snagged by the file location security checks. This will get you an HICON that you can then use Icon.FromHandle on.

Google PInvoke+LoadIcon

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Millions of users to benefit from Windows 11's new performance boost on Adobe Photoshop by Sayan Sen Despite the advent of AI-generated imagery, Adobe's Photoshop remains one of the most popular tools on this planet. Adobe does not have a publicly reported total user count but it's probably not wrong to assume there are millions. As of 2025, Adobe Creative Cloud has had approximately 41 million paid subscribers, many of whom likely use Photoshop. In addition, more than 166,000 companies worldwide are apparently also using the app. These figures are according to a very recent report by SQ Magazine. Out of them, it is fair to assume that many are probably running Windows. As such, there is good news for these users as Microsoft has announced Photoshop is getting a big 20% performance boost on x86-64 (AMD64) systems and a 13% bump-up on Arm devices. This is definitely great news for them as many have complained about the slow performance and general sluggishness of Photoshop on Windows 11 ever since the advent of the latter back in 2021. If you are wondering how Microsoft managed to do this, the answer lies in a combination of compiler-level optimizations and a technology called Sample Profile Guided Optimization (SPGO). According to Microsoft, Adobe worked closely with the company’s Visual C++ team and adopted the latest MSVC toolchain enhancements together with SPGO to squeeze more performance out of Photoshop’s CPU-bound workloads. Unlike traditional Profile Guided Optimization (PGO), which requires developers to create special instrumented builds and run lengthy training workloads, SPGO gathers performance data directly from optimized release binaries. This means Adobe could collect real-world usage information which gives a major advantage to this technique, as companies could leverage data collected from actual customer workloads rather than only relying on synthetic benchmark runs. In theory, this should allow optimizations to better reflect how users interact with software in the real world. Thanks to this, there are improvements to code layout, function inlining, hot-and-cold code separation, and other low-level tweaks that help processors execute instructions more efficiently. Essentially the compiler is better able to identify “hot” code paths, those which are most frequently executed, and optimize them accordingly.
    • "The 2TB Samsung 990 PRO NVMe SSD hits lowest price in over three months¨ I'd prefer to see the lowest price in over a year
    • Glad these prices are starting to come down, but that is still crazy. I bought the 2TB 9100 Pro (slightly more expensive version with PCIe 5.0) last year for $240.
    • The 2TB Samsung 990 PRO NVMe SSD hits lowest price in over three months by Sayan Sen Yesterday, we covered a really good deal wherein you can get a 4TB TeamGroup T-FORCE G50 NVMe PCIe Gen4 SSD for a low price of just $400 with a special discount coupon. That's just $100 per TB, making it a very good offer during these hard times. The deal is still live, so you can check it out in its dedicated article here if you do not want to miss out. Meanwhile, if you don't have that kind of budget but still wish to buy an SSD for a good price, the 2TB variant of the TeamGroup SSD at $280 its lowest price in over three months. Meanwhile, those seeking 2TB but faster performance can check out Samsung's 990 PRO, which has hit the lowest price also in the last quarter or so, as it's on sale for $370 (purchase links under the specs table down below). Thus, you want a faster drive, get the 990 Pro, or you want more capacity, grab the TeamGroup 4TB linked in the first para. The 990 PRO is a PCIe Gen4 NVMe SSD and still one of the fastest drives available today for under $500. Speaking of fast, sequential reads and writes are rated at 7450 MB/s and 6900 MB/s, respectively. The random throughputs for reads and writes are 1400K IOPS and 1550K IOPS, respectively. The 990 PRO is based on Samsung's 7th Gen V-NAND flash, and it too is TLC. It packs 2 gigs of LPDDR4 DRAM cache, which helps the random performance. The endurance rating for this is 1200 TBW (terabytes written), which should be sufficient for most users. The Samsung 990 PRO is compatible with the PlayStation 5, but if you are going to use the 990 PRO on a PC, check out the Samsung Magician app that lets you track your drive's health, update its firmware, customize various settings, and more. The tech specs are given below: Specification TeamGroup T-FORCE G50 2TB Samsung 990 PRO 2TB Interface PCIe 4.0 x4, NVMe 1.4 PCIe Gen 4.0 x4, NVMe 2.0 Form Factor M.2 2280 M.2 2280 Controller InnoGrit Controller Samsung In-house Controller NAND Flash 3D TLC 3D TLC DRAM Cache None (HMB supported) 2GB LPDDR4 Sequential Read (Max) 5,000 MB/s 7,450 MB/s Sequential Write (Max) 4,500 MB/s 6,900 MB/s Random Read (4K) Up to 600,000 IOPS Up to 1,400,000 IOPS Random Write (4K) Up to 700,000 IOPS Up to 1,550,000 IOPS TBW (Endurance) 1,300 TBW 1,200 TBW MTBF 3,000,000 hours 1,500,000 hours Operating Temperature 0°C to 70°C 0°C to 70°C Storage Temperature -40°C to 85°C -40°C to 85°C Shock Resistance 1,500G / 0.5ms 1,500G / 0.5ms Heatsink Patented Graphene Heat Spreader No Get them at the links below: Samsung 990 PRO SSD 2TB (MZ-V9P2T0B/AM): $369.99 (Sold and Shipped by Amazon US) TEAMGROUP T-Force G50 2TB SSD (TM8FFE002T0C129): $279.99 (Sold by TeamGroup, Shipped by Amazon US) Good to know This Amazon deal is U.S. specific, and not available in other regions unless specified. We only use first-party seller links (at the time of article publishing); ensure that you purchase from a first-party seller link only. Check out Today's Deals on Amazon | or our recent tech deals. Become a Prime member (for Students or SNAP) via Neowin Get Prime Access - Prime for half price (for qualifying Medicaid, EBT, SNAP) Subscribe to Prime Video, Audible Plus, Music Unlimited or Kindle Unlimited via Neowin As an Amazon Associate, we earn from qualifying purchases.
    • If you can't spell a simple word that 2nd graders learn, your entire argument is suspect.
  • Recent Achievements

  • Popular Contributors

    1. 1
      +primortal
      520
    2. 2
      +Edouard
      174
    3. 3
      PsYcHoKiLLa
      90
    4. 4
      Steven P.
      81
    5. 5
      ATLien_0
      70
  • Tell a friend

    Love Neowin? Tell a friend!