Skip to content

Wrap tray identicon in an ICO container so System.Drawing.Icon accepts it#16

Merged
StuartMeeks merged 1 commit into
masterfrom
fix/tray-icon-ico-format
May 30, 2026
Merged

Wrap tray identicon in an ICO container so System.Drawing.Icon accepts it#16
StuartMeeks merged 1 commit into
masterfrom
fix/tray-icon-ico-format

Conversation

@StuartMeeks

@StuartMeeks StuartMeeks commented May 30, 2026

Copy link
Copy Markdown
Owner

Summary

  • Next exception captured by the log: ArgumentException: Argument 'picture' must be a picture that can be used as a Icon. from System.Drawing.Icon.Initialize, called by H.NotifyIcon.StreamExtensions.ToSmallIcon.
  • H.NotifyIcon now successfully reads our file (PR Fix tray icon NRE: load BitmapImage from a file URI #15 fixed the URI path), but new Icon(stream, size) only accepts ICO format — and we were writing raw PNG bytes.
  • Fix: wrap the identicon PNG in a minimal ICO container (6-byte ICONDIR header + 16-byte ICONDIRENTRY pointing at the PNG payload — modern Windows accepts PNG-in-ICO). ~20 lines of pure byte layout, no native code, no extra packages. File extension changes from .png to .ico; pixels unchanged.

Test plan

  • Core builds clean.
  • Windows CI green.
  • Manual: launch on Windows; tray icon renders the identicon with no entries in unhandled.log; right-click context menu works; left-click brings the window forward.

🤖 Generated with Claude Code

The new log surfaced the next exception in the chain: once H.NotifyIcon
could read our PNG file (PR #15), it handed the bytes to
new System.Drawing.Icon(stream, size) — which only accepts ICO-format
input and throws ArgumentException on PNG.

Modern Windows accepts a PNG payload embedded inside an ICO container:
a 6-byte ICONDIR header plus a 16-byte ICONDIRENTRY pointing at the PNG
bytes. WrapPngAsIco builds that header in-place; no native code, no
extra dependencies, ~20 lines.

The tray icon file changes extension from .png to .ico; pixels are
unchanged.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@StuartMeeks StuartMeeks merged commit 896ad5b into master May 30, 2026
4 checks passed
@StuartMeeks StuartMeeks deleted the fix/tray-icon-ico-format branch May 30, 2026 01:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant