{"record":{"id":"8c3e3d5ac4ccc542","repo":"dotnet/wpf","slug":"sr-format-sr-filenotfoundexceptionwithfilename-profileuri","errorCode":null,"errorMessage":"SR.Format(SR.FileNotFoundExceptionWithFileName, profileUri.AbsolutePath)","messagePattern":"SR\\.Format\\(SR\\.FileNotFoundExceptionWithFileName, profileUri\\.AbsolutePath\\)","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/ColorContext.cs","lineNumber":541,"sourceCode":"            }\n\n            if (profileStream == null)\n            {\n                if (tryProfileFromResource)\n                {\n                    ResourceManager resourceManager = new ResourceManager(_colorProfileResources, Assembly.GetAssembly(typeof(ColorContext)));\n                    byte[] sRGBProfile = (byte[])resourceManager.GetObject(_sRGBProfileName);\n\n                    profileStream = new MemoryStream(sRGBProfile);\n                }\n                else\n                {\n                    //\n                    // SECURITY WARNING: This exception includes the profile URI which may contain sensitive information. However, as of right now,\n                    // this is safe because it can only happen when the URI is given to us by the user.\n                    //\n                    Invariant.Assert(!isStandardProfileUriNotFromUser);\n                    throw new FileNotFoundException(SR.Format(SR.FileNotFoundExceptionWithFileName, profileUri.AbsolutePath), profileUri.AbsolutePath);\n                }\n            }\n\n            FromStream(profileStream, profileUri.AbsolutePath);\n        }\n\n        /// <summary>\n        /// Obtains the system color profile path\n        /// </summary>\n        private static Uri GetStandardColorSpaceProfile()\n        {\n            const int SIZE = NativeMethods.MAX_PATH;\n            \n            uint dwProfileID = (uint)NativeMethods.ColorSpace.SPACE_sRGB;\n            uint bufferSize = SIZE;\n            StringBuilder buffer = new StringBuilder(SIZE);\n\n            HRESULT.Check(UnsafeNativeMethodsMilCoreApi.Mscms.GetStandardColorSpaceProfile(IntPtr.Zero, dwProfileID, buffer, out bufferSize));","sourceCodeStart":523,"sourceCodeEnd":559,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/ColorContext.cs#L523-L559","documentation":"ColorContext.Initialize throws FileNotFoundException with FileNotFoundExceptionWithFileName when the color profile stream for the given URI could not be obtained. The URI was user-supplied (not a standard profile) and no profile data exists at profileUri, so the file/embbeded resource is missing. The exception message includes the profile URI path for diagnostics.","triggerScenarios":"new ColorContext(Uri) with a user-provided URI whose AbsolutePath does not resolve to an existing profile file or embedded package part; Initialize reaches profileStream == null after the boundary check passed.","commonSituations":"Typo in profile file path; profile file deleted or not deployed with the app; URI pointing to a resource not embedded in the assembly/XPS package; case-sensitivity or path-format mistakes in pack URIs.","solutions":["Verify the profile file exists at the URI's AbsolutePath before constructing the ColorContext","Use pack/application URIs for resources embedded in assemblies and confirm the file's Build Action is Resource","Correct the path spelling/casing and deploy the .icc/.icm file alongside the app","Catch FileNotFoundException and fall back to the standard sRGB ColorContext"],"exampleFix":"// before\nvar ctx = new ColorContext(new Uri(\"C:\\\\Profiles\\\\missing.icc\"));\n// after\nif (File.Exists(profilePath)) { var ctx = new ColorContext(new Uri(profilePath)); } else { var ctx = new ColorContext(PixelFormats.Pbgra32); }","handlingStrategy":"validation","validationCode":"if (profileUri == null || !File.Exists(profileUri.AbsolutePath) && !Application.GetResourceStream(profileUri).Stream.CanRead) throw new FileNotFoundException(profileUri.AbsolutePath);","typeGuard":null,"tryCatchPattern":"try { var ctx = new ColorContext(profileUri); } catch (FileNotFoundException ex) { log.Warn($\"Profile missing: {ex.FileName}\"); ctx = new ColorContext(PixelFormats.Srgb); }","preventionTips":["Verify profile files exist/deployed before constructing ColorContext","Use pack URIs with Build Action = Resource for embedded profiles","Catch FileNotFoundException and fall back to standard sRGB"],"tags":["wpf","color-context","file-not-found"],"backgroundTag":"file-not-found","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"}