wailsapp/wails · error
IconType is invalid
Error message
IconType is invalid
What it means
Form.SetIcon maps iconType to WM_SETICON's wParam, which accepts only 0 (ICON_SMALL) or 1 (ICON_BIG); any value above 1 panics with 'IconType is invalid'. This is pure input validation before the SendMessage — nothing Windows-related can fail here. The panic is always a caller bug: passing an icon index, size, or enum from another API.
Source
Thrown at v2/internal/frontend/desktop/windows/winc/form.go:222
if !fm.isFullscreen {
return
}
w32.SetWindowLong(fm.hwnd, w32.GWL_STYLE, fm.previousWindowStyle)
w32.SetWindowLong(fm.hwnd, w32.GWL_EXSTYLE, fm.previousWindowExStyle)
w32.SetWindowPlacement(fm.hwnd, &fm.previousWindowPlacement)
fm.isFullscreen = false
w32.SetWindowPos(fm.hwnd, 0, 0, 0, 0, 0,
w32.SWP_NOMOVE|w32.SWP_NOSIZE|w32.SWP_NOZORDER|w32.SWP_NOOWNERZORDER|w32.SWP_FRAMECHANGED)
}
func (fm *Form) IsFullScreen() bool {
return fm.isFullscreen
}
// IconType: 1 - ICON_BIG; 0 - ICON_SMALL
func (fm *Form) SetIcon(iconType int, icon *Icon) {
if iconType > 1 {
panic("IconType is invalid")
}
w32.SendMessage(fm.hwnd, w32.WM_SETICON, uintptr(iconType), uintptr(icon.Handle()))
}
func (fm *Form) EnableMaxButton(b bool) {
SetStyle(fm.hwnd, b, w32.WS_MAXIMIZEBOX)
}
func (fm *Form) EnableMinButton(b bool) {
SetStyle(fm.hwnd, b, w32.WS_MINIMIZEBOX)
}
func (fm *Form) EnableSizable(b bool) {
SetStyle(fm.hwnd, b, w32.WS_THICKFRAME)
}
func (fm *Form) EnableDragMove(_ bool) {
//fm.isDragMove = bView on GitHub (pinned to 0e754b1b40)
Solutions
- Use only the two documented constants: w32.ICON_BIG (1) for the alt-tab/taskbar icon and w32.ICON_SMALL (0) for the title-bar icon
- Set both: SetIcon(w32.ICON_BIG, icoBig) and SetIcon(w32.ICON_SMALL, icoSmall) — for other sizes register icons in the window class or via the exe resource
- If multiple resolutions are needed, embed them as a single multi-size .ico resource instead of extra SetIcon calls
Example fix
// before form.SetIcon(32, icon) // 32 > 1 -> panic // after form.SetIcon(w32.ICON_BIG, icon) form.SetIcon(w32.ICON_SMALL, icon)
Defensive patterns
Strategy: type-guard
Validate before calling
func validIconType(t int) bool { return t == 0 || t == 1 } // ICON_SMALL / ICON_BIG Type guard
func iconTypeValid(t int) bool { return t == int(w32.ICON_SMALL) || t == int(w32.ICON_BIG) } Prevention
- Always use w32.ICON_BIG / w32.ICON_SMALL constants, never literals
- Set both icons right after form creation
When it happens
Trigger: Calling form.SetIcon(2, ico) or higher; passing an icon dimension like 32/256 as iconType; confusing this API with per-DPI icon setting (WM_SETICON has no DPI variants).
Common situations: Wrapping SetIcon in a loop over icon sizes; porting code from frameworks where icon 'type' enums have more members.
Related errors
- GetSysColorBrush failed
- missing icon with icon ID: %d
- Cannot create canvas from invalid HDC.
- cannot create window for " + className
- Invalid font style
AI-assisted analysis of wailsapp/wails@0e754b1b40 (2026-08-15).
Data as JSON: /api/errors/f7fc4d9716a90a33.
Report an issue: GitHub.