{"record":{"id":"4081507b4b19c809","repo":"git-ecosystem/git-credential-manager","slug":"a-host-provider-cannot-be-registered-with-the-id","errorCode":null,"errorMessage":"A host provider cannot be registered with the ID '{ProviderIdAuto}'","messagePattern":"A host provider cannot be registered with the ID '(.+?)'","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Core/HostProviderRegistry.cs","lineNumber":70,"sourceCode":"    {\n        private readonly ICommandContext _context;\n        private readonly IDictionary<HostProviderPriority, ICollection<IHostProvider>> _hostProviders;\n\n        public HostProviderRegistry(ICommandContext context)\n        {\n            EnsureArgument.NotNull(context, nameof(context));\n\n            _context = context;\n            _hostProviders = new Dictionary<HostProviderPriority, ICollection<IHostProvider>>();\n        }\n\n        public void Register(IHostProvider hostProvider, HostProviderPriority priority)\n        {\n            EnsureArgument.NotNull(hostProvider, nameof(hostProvider));\n\n            if (StringComparer.OrdinalIgnoreCase.Equals(hostProvider.Id, Constants.ProviderIdAuto))\n            {\n                throw new ArgumentException(\n                    $\"A host provider cannot be registered with the ID '{Constants.ProviderIdAuto}'\",\n                    nameof(hostProvider));\n            }\n\n            if (hostProvider.SupportedAuthorityIds.Any(y => StringComparer.OrdinalIgnoreCase.Equals(y, Constants.AuthorityIdAuto)))\n            {\n                throw new ArgumentException(\n                    $\"A host provider cannot be registered with the legacy authority ID '{Constants.AuthorityIdAuto}'\",\n                    nameof(hostProvider));\n            }\n\n            if (!_hostProviders.TryGetValue(priority, out ICollection<IHostProvider> providers))\n            {\n                providers = new List<IHostProvider>();\n                _hostProviders[priority] = providers;\n            }\n\n            providers.Add(hostProvider);","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/git-ecosystem/git-credential-manager/blob/e8ce762cd04b4100ae637b5fbf39ef9d0a96561e/src/Core/HostProviderRegistry.cs#L52-L88","documentation":"HostProviderRegistry.Register rejects any IHostProvider whose Id equals the reserved value 'auto' (Constants.ProviderIdAuto, compared OrdinalIgnoreCase). 'auto' is reserved for the automatic host-detection provider, so a custom provider claiming that ID would conflict with built-in detection. The library throws ArgumentException naming the offending parameter.","triggerScenarios":"Calling hostProviderRegistry.Register(provider, priority) where provider.Id == \"auto\" (any casing).","commonSituations":"Writing a custom host provider and forgetting to set a unique Id, copying sample code that leaves the default/placeholder ID 'auto', or programmatic provider injection in tests.","solutions":["Set the provider's Id property to a unique, non-'auto' constant (e.g. \"mycompany\")","Check provider.Id before registering and fail fast with a clear message","If the provider is meant to be chosen automatically, do not register it manually — rely on detection via SupportedAuthorityIds"],"exampleFix":"// before\nvar provider = new MyHostProvider { Id = Constants.ProviderIdAuto };\nregistry.Register(provider, HostProviderPriority.Normal); // throws\n// after\nvar provider = new MyHostProvider { Id = \"mycompany\" };\nregistry.Register(provider, HostProviderPriority.Normal);","handlingStrategy":"validation","validationCode":"if (string.Equals(provider.Id, \"auto\", StringComparison.OrdinalIgnoreCase))\n    throw new ArgumentException(\"Provider Id must not be the reserved value 'auto'\", nameof(provider));","typeGuard":"bool HasValidProviderId(IHostProvider p) => !string.IsNullOrWhiteSpace(p.Id) && !p.Id.Equals(\"auto\", StringComparison.OrdinalIgnoreCase);","tryCatchPattern":"try\n{\n    registry.Register(provider, HostProviderPriority.Normal);\n}\ncatch (ArgumentException ex)\n{\n    logger.LogError(ex, \"Provider registration rejected: {Message}\", ex.Message);\n}","preventionTips":["Always assign a unique, non-reserved Id constant to custom host providers","Add an assertion/unit test that provider.Id != Constants.ProviderIdAuto before registration","Never use built-in Constants.ProviderIdAuto/AuthorityIdAuto values for your own providers"],"tags":["host-provider","registration","reserved-identifier","csharp"],"backgroundTag":"invalid-argument-value","analyzedSha":"e8ce762cd04b4100ae637b5fbf39ef9d0a96561e","analyzedAt":"2026-09-11T17:15:08.753Z","contentChangedAt":"2026-09-11T17:15:08.753Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}