dotnet/wpf · error · ArgumentException
SR.Cursor_UnsupportedFormat (cursorFile)
Error message
SR.Cursor_UnsupportedFormat (cursorFile)
What it means
The Cursor(string cursorFile) constructor requires the file to have a .cur or .ani extension (checked before LoadFromFile); any other extension throws ArgumentException (SR.Cursor_UnsupportedFormat) with the offending file name.
Solutions
- Convert the image to a genuine .cur or .ani file and pass that path.
- Validate the extension with Path.GetExtension before constructing and show a clear user-facing message.
- Ship known-good .cur/.ani assets as resources and load via Application.GetResourceStream instead of arbitrary files.
Example fix
// before
var cursor = new Cursor(cursorPath); // cursorPath = "spinner.png"
// after
if (Path.GetExtension(cursorPath) is ".cur" or ".ani")
var cursor = new Cursor(cursorPath);
else
throw new InvalidOperationException($"Cursor file must be .cur or .ani: {cursorPath}"); Defensive patterns
Strategy: validation
Validate before calling
var ext = Path.GetExtension(cursorFile);
if (ext.Equals(".cur", StringComparison.OrdinalIgnoreCase) || ext.Equals(".ani", StringComparison.OrdinalIgnoreCase))
this.Cursor = new Cursor(cursorFile); Type guard
static bool IsCursorFile(string p) => ".cur".Equals(Path.GetExtension(p), StringComparison.OrdinalIgnoreCase) || ".ani".Equals(Path.GetExtension(p), StringComparison.OrdinalIgnoreCase);
Try / catch
try { this.Cursor = new Cursor(cursorFile); } catch (ArgumentException ex) { /* fallback to Cursors.Arrow and report unsupported format */ } Prevention
- Check the extension is .cur or .ani before constructing
- Convert PNG/SVG assets to .cur/.ani at build time
- Verify File.Exists in addition to extension to avoid downstream file errors
When it happens
Trigger: new Cursor(@"C:\icons\spinner.png"), new Cursor("pointer.svg"), or a path with no extension — anything not ending in .cur or .ani.
Common situations: Pointing the app at downloaded or design-team cursor assets in PNG/SVG/GIF format, or paths whose extension was stripped by a config transform.
Related errors
- Document does not contain a package.
- Document does not contain any rights management-protected…
- FileFormatException
- Image_CantDealWithStream
- Image_CantDealWithUri
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/415481503921f154.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Cursor.cs:63
/// Cursor from .ani or .cur file
/// </summary>
/// <param name="cursorFile"></param>
/// <param name="scaleWithDpi"></param>
public Cursor(string cursorFile, bool scaleWithDpi)
{
_scaleWithDpi = scaleWithDpi;
ArgumentNullException.ThrowIfNull(cursorFile);
if ((cursorFile != String.Empty) &&
(cursorFile.EndsWith(".cur", StringComparison.OrdinalIgnoreCase) ||
cursorFile.EndsWith(".ani", StringComparison.OrdinalIgnoreCase)))
{
LoadFromFile(cursorFile);
_fileName = cursorFile;
}
else
{
throw new ArgumentException(SR.Format(SR.Cursor_UnsupportedFormat , cursorFile));
}
}
/// <summary>
/// Cursor from Stream
/// </summary>
/// <param name="cursorStream"></param>
public Cursor(Stream cursorStream):this(cursorStream, false)
{
}
/// <summary>
/// Cursor from Stream
/// </summary>
/// <param name="cursorStream"></param>
/// <param name="scaleWithDpi"></param>
public Cursor(Stream cursorStream, bool scaleWithDpi)
{View on GitHub (pinned to 81131a70a4)