JosefNemec/Playnite · warning · NotSupportedException
Cannot convert {value} to AspectRatio.
Error message
Cannot convert {value} to AspectRatio. What it means
Thrown by AspectRatioTypeConverter.ConvertFrom when the supplied value cannot be parsed into an AspectRatio. The converter accepts a 'W:H' or 'WxH' style string (regex groups) and falls back to a default for designer previews; any other shape/value reaches the throw as NotSupportedException.
Source
Thrown at source/Playnite/Common/Sizes.cs:34
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
if (value is string ratio)
{
var regex = Regex.Match(ratio, @"(\d+):(\d+)");
if (regex.Success)
{
return new AspectRatio(
Convert.ToInt32(regex.Groups[1].Value),
Convert.ToInt32(regex.Groups[2].Value));
}
else
{
// For cases where this is called from designer element preview via binding expression
return new AspectRatio();
}
}
throw new NotSupportedException($"Cannot convert {value} to AspectRatio.");
}
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
return sourceType == typeof(string);
}
}
[TypeConverter(typeof(AspectRatioTypeConverter))]
public class AspectRatio : IEquatable<AspectRatio>
{
public int Width { get; set; }
public int Height { get; set; }
public AspectRatio()
{
}
View on GitHub (pinned to 5911f4e964)
Solutions
- Provide the ratio in the supported 'W:H' format (e.g. '16:9', '4:3').
- Validate the string against the converter's regex before binding.
- Ensure the bound value is a string and not null or a numeric type.
Example fix
// before
var ar = (AspectRatio)new AspectRatioTypeConverter().ConvertFrom(input);
// after — validate the ratio string first
static bool TryRatio(string s, out int w, out int h)
{
w = h = 0;
var m = System.Text.RegularExpressions.Regex.Match(s ?? "", @"^(\d+)\s*[:xX]\s*(\d+)$");
return m.Success && int.TryParse(m.Groups[1].Value, out w) && int.TryParse(m.Groups[2].Value, out h);
}
if (!TryRatio(input, out var w, out var h)) { ar = new AspectRatio(); }
else { ar = new AspectRatio(w, h); } Defensive patterns
Strategy: validation
Validate before calling
static bool TryParseRatio(string s, out int w, out int h)
{
w = h = 0;
var m = System.Text.RegularExpressions.Regex.Match(s ?? "", @"^(\d+)\s*[:xX]\s*(\d+)$");
return m.Success && int.TryParse(m.Groups[1].Value, out w) && int.TryParse(m.Groups[2].Value, out h);
} Type guard
static bool IsValidRatioString(string s, out int w, out int h) => TryParseRatio(s, out w, out h);
Try / catch
try { return (AspectRatio)new AspectRatioTypeConverter().ConvertFrom(input); }
catch (NotSupportedException) { return new AspectRatio(); /* default */ } Prevention
- Always format ratios as 'W:H' (e.g. '16:9').
- Validate the string with the converter's regex before binding.
- Ensure the bound value is a non-null string.
When it happens
Trigger: Binding a non-string value, or a string that does not match the expected W:H regex (e.g. '16/9', '1.77', 'wide', empty, or a decimal ratio); passing a null outside the designer path.
Common situations: User/theme config with a malformed aspect ratio string; a plugin/theme binding the wrong type; localized config using a different separator; designer hitting the converter with an unexpected value.
Related errors
- Backup output path not specified!
- No URL was given.
- Source directory does not exist or could not be found: {sour
- The icon is corrupt. Couldn't read the header.
- Non empty process name must be specified.
AI-assisted analysis of JosefNemec/Playnite@5911f4e964 (2026-08-13).
Data as JSON: /api/errors/ce62ff7b3baf403f.
Report an issue: GitHub.