{"record":{"id":"b4bc5b4203137af2","repo":"dotnet/wpf","slug":"sr-pathtoolongexceptionwithfilename","errorCode":null,"errorMessage":"SR.PathTooLongExceptionWithFileName","messagePattern":"SR\\.PathTooLongExceptionWithFileName","errorType":"exception","errorClass":"PathTooLongException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/FontCache/FontCacheUtil.cs","lineNumber":757,"sourceCode":"        internal static void ThrowWin32Exception(int errorCode, string fileName)\n        {\n            switch (errorCode)\n            {\n                case NativeMethods.ERROR_FILE_NOT_FOUND:\n                    throw new FileNotFoundException(SR.Format(SR.FileNotFoundExceptionWithFileName, fileName), fileName);\n\n                case NativeMethods.ERROR_PATH_NOT_FOUND:\n                    throw new DirectoryNotFoundException(SR.Format(SR.DirectoryNotFoundExceptionWithFileName, fileName));\n\n                case NativeMethods.ERROR_ACCESS_DENIED:\n                    throw new UnauthorizedAccessException(SR.Format(SR.UnauthorizedAccessExceptionWithFileName, fileName));\n\n                case NativeMethods.ERROR_FILENAME_EXCED_RANGE:\n                    throw new PathTooLongException(SR.Format(SR.PathTooLongExceptionWithFileName, fileName));\n\n                default:\n                    throw new IOException(SR.Format(SR.IOExceptionWithFileName, fileName), NativeMethods.MakeHRFromErrorCode(errorCode));\n            }\n        }","sourceCodeStart":739,"sourceCodeEnd":775,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/FontCache/FontCacheUtil.cs#L739-L775","documentation":"Thrown by ThrowWin32Exception when the Win32 error ERROR_FILENAME_EXCED_RANGE is returned while opening a font file for reading: the combined path (or a component of it) exceeds the MAX_PATH limit, so the font cache cannot open the file at the given fileName.","triggerScenarios":"Opening a font source whose fully qualified path exceeds the Win32 path length limit, producing error 206 which maps to PathTooLongException.","commonSituations":"Deeply nested build/checkout directories (node_modules-like trees), long temp paths, long network share names combined with a long font file name.","solutions":["Shorten the font file path (move the font closer to the drive root or shorten folder names).","Use a long-path aware configuration (longPathsEnabled registry key and longPathAware manifest) on .NET versions that support it.","Use the \\\\?\\ prefix for extended-length paths where the API supports it.","For pack:// Uris, shorten the application/resource path."],"exampleFix":"// before\nvar uri = new Uri(@\"D:\\Very\\Long\\Build\\...\\DeeplyNested\\Output\\Fonts\\MyVeryLongFontFileName-Regular.ttf\");\n// after — ship fonts at a short stable location\nvar uri = new Uri(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, \"Fonts\", \"MyFont.ttf\"));","handlingStrategy":"validation","validationCode":"if (fontUri.IsFile && fontUri.LocalPath.Length >= 260)\n    throw new InvalidOperationException(\"Font path exceeds MAX_PATH; shorten it.\");","typeGuard":"static bool FontPathIsShortEnough(Uri fontUri, int max = 260) =>\n    !fontUri.IsFile || fontUri.LocalPath.Length < max;","tryCatchPattern":"try\n{\n    var gt = new GlyphTypeface(fontUri);\n}\ncatch (PathTooLongException)\n{\n    // relocate font to a short path and retry\n}","preventionTips":["Keep font assets near the root of the drive or in short app-relative folders.","Avoid long CI/build output paths for font deployment.","Enable Windows long-path support where available."],"tags":["path-too-long","font","io","wpf"],"backgroundTag":"path-too-long","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}