{"record":{"id":"98bc54cad8df22b0","repo":"nopSolutions/nopCommerce","slug":"incorrect-file-format","errorCode":null,"errorMessage":"Incorrect file format","messagePattern":"Incorrect file format","errorType":"validation","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/Libraries/Nop.Services/Helpers/BrowscapXmlParser.cs","lineNumber":107,"sourceCode":"            //try to load crawler list from crawlers only file\n            using var sr = new StreamReader(crawlerOnlyUserAgentStringsPath);\n            crawlerItems = XDocument.Load(sr).Root?.Elements(\"browscapitem\").ToList();\n        }\n\n        if (crawlerItems == null || !crawlerItems.Any())\n        {\n            //try to load crawler list from full user agents file\n            using var sr = new StreamReader(userAgentStringsPath);\n            var rootElement = XDocument.Load(sr).Root;\n            crawlerItems = rootElement?.Element(\"browsercapitems\")?.Elements(\"browscapitem\")\n                //only crawlers\n                .Where(IsBrowscapItemIsCrawler).ToList();\n            needSaveCrawlerOnly = true;\n            comments = rootElement?.Element(\"comments\");\n        }\n\n        if (crawlerItems == null || !crawlerItems.Any())\n            throw new Exception(\"Incorrect file format\");\n\n        if (_fileProvider.FileExists(additionalCrawlersFilePath))\n            crawlerItems.AddRange(GetAdditionalCrawlerItems(additionalCrawlersFilePath));\n\n        var crawlerRegexpPattern = string.Join(\"|\", crawlerItems\n            //get only user agent names\n            .Select(e => e.Attribute(\"name\"))\n            .Where(e => !string.IsNullOrEmpty(e?.Value))\n            .Select(e => e.Value)\n            .Select(attributeValue =>\n            {\n                var sb = new StringBuilder(Regex.Escape(attributeValue));\n                sb.Replace(\"&amp;\", \"&\").Replace(\"\\\\?\", \".\").Replace(\"\\\\*\", \".*?\");\n\n                return $\"^{sb}$\";\n            }));\n\n        _crawlerUserAgentsRegexp = new Regex(crawlerRegexpPattern);","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/nopSolutions/nopCommerce/blob/64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2/src/Libraries/Nop.Services/Helpers/BrowscapXmlParser.cs#L89-L125","documentation":"Thrown by the browscap (browser capabilities) XML parser Initialize method when, after trying both the crawlers-only file and the full user-agent file, no crawler items could be loaded. nopCommerce needs at least one browscapitem to build the crawler-detection regex, so an empty/unparseable source is rejected with a generic Exception('Incorrect file format').","triggerScenarios":"Calling Initialize when both the crawler-only file (browscap.crawlersonly.xml) and the full browscap.xml yield no <browscapitem> crawler elements — e.g. the file is missing, corrupt, an unsupported browscap schema version, or an HTML error page saved as XML.","commonSituations":"The browscap.xml in App_Data is outdated/empty/corrupt; an automatic browscap download returned an HTML error page; the file uses a newer browscap schema where crawler items are structured differently; file permissions block reading so parsing yields nothing.","solutions":["Download a fresh, valid browscap.xml from browscap.org and place it in App_Data, then delete browscap.crawlersonly.xml so it is regenerated.","Verify the file is well-formed XML with a <browsercapitems> root containing <browscapitem> elements.","Check file read permissions and that the path configured in BrowscapXmlParser settings is correct.","If the schema changed (crawler detection filter), confirm IsBrowscapItemIsCrawler still matches items in the new browscap version."],"exampleFix":"// before — App_Data/browscap.xml missing or HTML error page saved as XML\n\n// after\n// 1. Download the full PHP_BrowsCapINI.xml from https://browscap.org/\n// 2. Save as App_Data/browscap.xml\n// 3. Delete App_Data/browscap.crawlersonly.xml\n// 4. Restart the application so Initialize regenerates the crawlers-only file","handlingStrategy":"validation","validationCode":"// Validate the browscap file before parsing\nif (!_fileProvider.FileExists(browscapPath))\n    throw new FileNotFoundException(\"browscap.xml not found in App_Data.\", browscapPath);\nXDocument doc;\ntry { doc = XDocument.Load(browscapPath); }\ncatch (Exception) { throw new InvalidOperationException(\"browscap.xml is not valid XML; re-download from browscap.org.\"); }\nif (doc.Root == null || !doc.Root.Descendants(\"browscapitem\").Any())\n    throw new InvalidOperationException(\"browscap.xml contains no browscapitem elements; re-download a valid file.\");","typeGuard":"static bool IsValidBrowscapXml(XDocument doc)\n    => doc?.Root?.Descendants(\"browscapitem\").Any() == true;","tryCatchPattern":"try { _browscapParser.Initialize(userAgentPath, crawlerOnlyPath, additionalPath); }\ncatch (Exception ex) when (ex.Message == \"Incorrect file format\")\n{ /* delete browscap.crawlersonly.xml, re-download browscap.xml from browscap.org, restart */ }","preventionTips":["Keep App_Data/browscap.xml fresh from browscap.org; delete browscap.crawlersonly.xml to force regeneration.","Verify the downloaded file is XML, not an HTML error page.","Confirm read permissions on the App_Data folder."],"tags":["browscap","crawler","xml","configuration","nopcommerce"],"backgroundTag":null,"analyzedSha":"64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2","analyzedAt":"2026-08-13T21:19:38.062Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}