{"record":{"id":"9e5cc247f1b00f43","repo":"babalae/better-genshin-impact","slug":"error-9e5cc2","errorCode":null,"errorMessage":"无效的推理设备","messagePattern":"无效的推理设备","errorType":"exception","errorClass":"InvalidEnumArgumentException","httpStatus":null,"severity":"error","filePath":"BetterGenshinImpact/Core/Recognition/ONNX/BgiOnnxFactory.cs","lineNumber":201,"sourceCode":"                    testSession = new SessionOptions();\n                    testSession.AppendExecutionProvider(\"OpenVINO\", GetOpenVinoProviderConfig(null));\n                    testSession.GraphOptimizationLevel = GraphOptimizationLevel.ORT_DISABLE_ALL;\n                    list.Add(ProviderType.OpenVino);\n                }\n                catch (Exception e)\n                {\n                    _logger.LogDebug(\"[init]无法加载OpenVino。可能不支持，跳过。({Err})\", e.Message);\n                }\n                finally\n                {\n                    testSession?.Dispose();\n                }\n\n                list.Add(ProviderType.Cpu);\n                return list.ToArray();\n            }\n            default:\n                throw new InvalidEnumArgumentException(\"无效的推理设备\");\n        }\n    }\n\n    /// <summary>\n    ///     自动嗅探并修改path以加载cuda\n    /// </summary>\n    private void AppendCudaPath()\n    {\n        var cudaVersion =\n            Registry.GetValue(@\"HKEY_LOCAL_MACHINE\\SOFTWARE\\NVIDIA Corporation\\GPU Computing Toolkit\\CUDA\",\n                \"FirstVersionInstalled\", null)?.ToString() ?? \"v12.8\";\n        string[] filePrefix = [\"cudnn\", \"nvrtc\", \"cudart\", \"nvinfer\", \"cublas\", \"onnx\"];\n        string[] environmentVariableNames = [\"PATH\", \"CUDA_PATH\", \"CUDNN_PATH\", \"LD_LIBRARY_PATH\"];\n\n        // 例如: CUDNN\\v9.8\\lib\\12.8\\x64\n        var validPaths = environmentVariableNames.SelectMany(s => Environment\n                // 获取所有可能包含CUDA/cuDNN路径的环境变量\n                .GetEnvironmentVariable(s, EnvironmentVariableTarget.Process)?","sourceCodeStart":183,"sourceCodeEnd":219,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/Core/Recognition/ONNX/BgiOnnxFactory.cs#L183-L219","documentation":"BgiOnnxFactory.GetProviders switches on InferenceDeviceType (Cpu, Dml, Gpu, OpenVino). Any other value reaches the default arm and throws InvalidEnumArgumentException('无效的推理设备'). This is the device-selection stage that decides which ONNX Runtime execution providers to try; an unknown device type means no providers can be chosen.","triggerScenarios":"An InferenceDeviceType value outside the handled set; default(InferenceDeviceType) when 0 is not a valid device; a config value referencing a removed device.","commonSituations":"New device enum member added without a case; config file with a typo or stale device name; settings from a different app version.","solutions":["Set the inference device config to a supported value (Cpu, Dml, Gpu, or OpenVino).","Validate InferenceDeviceType at startup and default to Cpu if invalid.","Update the switch when adding a new device type."],"exampleFix":"// before\nvar providers = factory.GetProviders(config.Device); // unknown device\n\n// after\nvar device = Enum.IsDefined(config.Device) ? config.Device : InferenceDeviceType.Cpu;\nvar providers = factory.GetProviders(device);","handlingStrategy":"validation","validationCode":"var device = config.Device is InferenceDeviceType.Cpu or InferenceDeviceType.Dml\n    or InferenceDeviceType.Gpu or InferenceDeviceType.OpenVino\n        ? config.Device\n        : InferenceDeviceType.Cpu;\nvar providers = factory.GetProviders(device);","typeGuard":"static bool IsSupportedDevice(InferenceDeviceType d) => d is InferenceDeviceType.Cpu or InferenceDeviceType.Dml or InferenceDeviceType.Gpu or InferenceDeviceType.OpenVino;","tryCatchPattern":null,"preventionTips":["Default inference device to Cpu in config.","Validate the enum at config load.","Add a case when introducing a new device type."],"tags":["onnx","inference","device","enum","config","argument-validation"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}