{"record":{"id":"e25daf4a62aa21fd","repo":"2dust/v2rayN","slug":"rasenumentries-failed-with-error-code-result","errorCode":null,"errorMessage":"RasEnumEntries failed with error code: {result}","messagePattern":"RasEnumEntries failed with error code: (.+?)","errorType":"exception","errorClass":"ApplicationException","httpStatus":null,"severity":"warning","filePath":"v2rayN/ServiceLib/Handler/SysProxy/ProxySettingWindows.cs","lineNumber":235,"sourceCode":"            rasEntryNames = new RASENTRYNAME[bufferSize / Marshal.SizeOf(typeof(RASENTRYNAME))];\n            for (var i = 0; i < rasEntryNames.Length; i++)\n            {\n                rasEntryNames[i].dwSize = Marshal.SizeOf(typeof(RASENTRYNAME));\n            }\n\n            result = NativeMethods.RasEnumEntries(null, null, rasEntryNames, ref bufferSize, ref entries);\n        }\n        if (result == 0)\n        {\n            var entryNames = new List<string>();\n            for (var i = 0; i < entries; i++)\n            {\n                entryNames.Add(rasEntryNames[i].szEntryName);\n            }\n\n            return entryNames;\n        }\n        throw new ApplicationException($\"RasEnumEntries failed with error code: {result}\");\n    }\n\n    #region WinInet structures\n\n    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]\n    public struct InternetPerConnOptionList\n    {\n        public int dwSize;               // size of the INTERNET_PER_CONN_OPTION_LIST struct\n        public nint szConnection;         // connection name to set/query options\n        public int dwOptionCount;        // number of options to set/query\n        public int dwOptionError;           // on error, which option failed\n\n        //[MarshalAs(UnmanagedType.)]\n        public nint options;\n    }\n\n    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]\n    public struct InternetConnectionOption","sourceCodeStart":217,"sourceCodeEnd":253,"githubUrl":"https://github.com/2dust/v2rayN/blob/e01717d8326a4f5060b335523590c5fda943fe03/v2rayN/ServiceLib/Handler/SysProxy/ProxySettingWindows.cs#L217-L253","documentation":"Thrown when the RAS (Remote Access Service) RasEnumEntries call still returns a non-zero result after the buffer-retry loop. The loop grows the buffer on ERROR_BUFFER_TOO_SMALL/insufficient-buffer, but any other non-zero RAS result is treated as a hard failure.","triggerScenarios":"EnumerateRasEntries calls RasEnumEntries; after resizing the buffer for the too-small case, result is still != 0 (not success and not a buffer-too-small retry signal).","commonSituations":"RAS service not running or unavailable on the machine; non-Windows or a Windows edition without RAS; corrupt telephony/RAS configuration; insufficient privileges to enumerate dial-up/PPPoE entries.","solutions":["Decode the RAS result code (RAS error constants) to identify the cause; common non-zero values map to specific RAS errors.","Ensure the Telephony/RAS services are running (services.msc) on the machine.","Run with sufficient privileges to enumerate RAS entries.","If RAS is unavailable, guard the caller to skip PPPoE enumeration (this method supports PPPoE; absence of RAS is acceptable on many systems).","Catch ApplicationException at the call site and degrade gracefully (return empty list) when RAS is not present."],"exampleFix":"// before - any non-zero RAS result throws\nthrow new ApplicationException($\"RasEnumEntries failed with error code: {result}\");\n\n// after - tolerate 'no RAS / no entries' and surface actionable error otherwise\nif (result == 0)\n    return entryNames;\n// ERROR_NO_MORE_ITEMS / RAS service absent -> no dial-up entries\nreturn Enumerable.Empty<string>();","handlingStrategy":"try-catch","validationCode":"// Only attempt RAS enumeration on Windows where RAS is available\nif (!OperatingSystem.IsWindows()) return Enumerable.Empty<string>();\n// then call EnumerateRasEntries inside a try-catch","typeGuard":"static bool RasLikelyAvailable() => OperatingSystem.IsWindows();","tryCatchPattern":"try\n{\n    var entries = ProxySettingWindows.EnumerateRasEntries();\n}\ncatch (ApplicationException ex) when (ex.Message.Contains(\"RasEnumEntries\"))\n{\n    // RAS service absent/unavailable; PPPoE enumeration not possible, degrade to empty\n    return Enumerable.Empty<string>();\n}","preventionTips":["Treat RAS absence as non-fatal (return empty list) since many systems have no dial-up entries.","Decode the RAS result code to identify the specific failure.","Ensure Telephony/RAS services are running if PPPoE support is required.","Run with sufficient privileges to enumerate RAS entries."],"tags":["windows","ras","pppoe","interop","pinvoke"],"backgroundTag":null,"analyzedSha":"e01717d8326a4f5060b335523590c5fda943fe03","analyzedAt":"2026-08-13T10:10:23.416Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}