d2phap/ImageGlass Β· error Β· ArgumentException
Zoom factor '{factorStr}' is not a valid float. ----------
Error message
Zoom factor '{factorStr}' is not a valid float.
----------
ππΌ Method: IG_SetZoom What it means
Thrown by the string overload of IG_SetZoom when float.TryParse(factorStr) fails. The parse is culture-sensitive (no InvariantCulture supplied), so the accepted decimal separator depends on the current culture. A null, empty, or non-numeric string raises ArgumentException.
Source
Thrown at source/ImageGlass.Lib/Common/ServiceProviders/AppAPIs/AppAPIProvider.cs:1202
});
if (result.ExitCode != DialogExitCode.OK) return;
if (float.TryParse(result.InputValue.Trim(), out var newZoom))
{
Viewer.ZoomFactor = newZoom / 100f;
}
}
/// <summary>
/// Zoom to the current cursor location by the given factor.
/// </summary>
public void IG_SetZoom(string? factorStr)
{
if (!float.TryParse(factorStr, out var factor))
{
throw new ArgumentException($"""
Zoom factor '{factorStr}' is not a valid float.
----------
ππΌ Method: {nameof(IG_SetZoom)}
""",
nameof(factorStr));
}
IG_SetZoom(factor);
}
/// <summary>
/// Zoom to the current cursor location by the given factor.
/// </summary>
public static void IG_SetZoom(float factor)
{
_ = Viewer.ZoomToPoint(factor);
}View on GitHub (pinned to 4a3c4fecef)
Solutions
- Pass a plain numeric string matching the current culture's decimal separator, or normalize to the current culture before calling.
- Validate with float.TryParse (same overload the method uses) before invoking, and call the float overload directly.
- Strip '%', spaces, and quotes upstream before parsing.
Example fix
// before
api.IG_SetZoom(userInput);
// after
var cleaned = userInput?.Trim().TrimEnd('%');
if (float.TryParse(cleaned, out var factor))
{
api.IG_SetZoom(factor);
} Defensive patterns
Strategy: validation
Validate before calling
var cleaned = factorStr?.Trim().TrimEnd('%');
if (!float.TryParse(cleaned, out var factor))
throw new ArgumentException("Zoom factor must be numeric.");
api.IG_SetZoom(factor); Type guard
static bool IsValidZoomFactor(string? s, IFormatProvider? p = null)
=> float.TryParse(s?.Trim().TrimEnd('%'), out _); Try / catch
try { api.IG_SetZoom(factorStr); }
catch (ArgumentException ex) when (ex.ParamName == nameof(factorStr))
{ /* reject; note culture may be the cause */ } Prevention
- Strip '%', spaces, and quotes before parsing.
- Remember the parse is culture-sensitive; match the user locale's decimal separator.
- Validate with the same float.TryParse overload upstream.
When it happens
Trigger: Calling IG_SetZoom(string) with '1.5' in a comma-decimal locale (e.g., de-DE) where '.' is not accepted; '150%' with the percent sign; '' ; 'zoom'; a value with a thousands separator.
Common situations: Hard-coded '1.5' from an English-locale config breaks when the app runs under a European locale; user input copied with a percent sign; CLI argument with surrounding quotes/spaces.
Related errors
- '{modeStr}' is not a valid zoom mode. ---------- ππΌ Metho
- Step '{stepStr}' is not a valid integer. ---------- ππΌ Me
- Frame index '{frameIndexStr}' is not a valid integer. -----
- '{orderByStr}' is not a valid loading order. ---------- ποΏ½
- '{orderTypeStr}' is not a valid loading order. ---------- οΏ½
AI-assisted analysis of d2phap/ImageGlass@4a3c4fecef (2026-08-13).
Data as JSON: /api/errors/bf77ef6dd6f6afb9.
Report an issue: GitHub.