{"record":{"id":"7d43bfcfc39393fb","repo":"dotnet/wpf","slug":"sr-parsers-illegaltoken-cachemode","errorCode":null,"errorMessage":"SR.Parsers_IllegalToken","messagePattern":"SR\\.Parsers_IllegalToken","errorType":"exception","errorClass":"FormatException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/CacheMode.cs","lineNumber":29,"sourceCode":"        \n        /// <summary>\n        /// Parse - this method is called by the type converter to parse a CacheMode's string \n        /// (provided in \"value\").\n        /// </summary>\n        /// <returns>\n        /// A CacheMode which was created by parsing the \"value\" argument.\n        /// </returns>\n        /// <param name=\"value\"> String representation of a CacheMode. Cannot be null/empty. </param>\n        internal static CacheMode Parse(string value)\n        {\n            CacheMode cacheMode = null;\n            if (value == \"BitmapCache\")\n            {\n                cacheMode = new BitmapCache();\n            }\n            else\n            {\n                throw new FormatException(SR.Parsers_IllegalToken);\n            }\n    \n            return cacheMode;\n        }\n\n        /// <summary>\n        /// Can serialze \"this\" to a string\n        /// </summary>\n        internal virtual bool CanSerializeToString()\n        {\n            return false;\n        }\n\n        internal virtual string ConvertToString(string format, IFormatProvider provider)\n        {\n            return base.ToString();\n        }\n    }","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/CacheMode.cs#L11-L47","documentation":"CacheMode.FromParseString only recognizes the literal string \"BitmapCache\". Any other token (including \"null\" or misspellings) throws FormatException with SR.Parsers_IllegalToken because no other CacheMode has a parser token.","triggerScenarios":"Parsing XAML or string values for a CacheMode-typed property with a value other than exactly \"BitmapCache\" (case-sensitive).","commonSituations":"Typing CacheMode=\"bitmapcache\" (wrong case) or \"NoCache\" in XAML; binding a string from config/settings into a CacheMode converter.","solutions":["Use exactly the string \"BitmapCache\" (case-sensitive) or omit the attribute for the default.","Remove the CacheMode attribute entirely if caching is not desired.","If the value comes from user input, validate/normalize it before parsing."],"exampleFix":"// before\n<Rectangle CacheMode=\"bitmapcache\" ... />\n\n// after\n<Rectangle CacheMode=\"BitmapCache\" ... />","handlingStrategy":"try-catch","validationCode":"bool isValid = value == null || string.Equals(value, \"BitmapCache\", StringComparison.Ordinal);","typeGuard":"static bool IsBitmapCacheToken(string s) => string.Equals(s, \"BitmapCache\", StringComparison.Ordinal);","tryCatchPattern":"try { cacheMode = (CacheMode)parser(value); }\ncatch (FormatException) { cacheMode = null; /* or default to BitmapCache */ }","preventionTips":["Only use the exact case-sensitive token \"BitmapCache\" for CacheMode parsing.","Validate user/config-supplied CacheMode strings before assignment.","Remember only BitmapCache has a parser token; other values must be set via typed objects."],"tags":["wpf","parsing","xaml","format-exception"],"backgroundTag":"invalid-argument-format","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}