{"record":{"id":"f793378fa0e43e53","repo":"microsoft/semantic-kernel","slug":"request-failed-nameof-getrepositoryasync","errorCode":null,"errorMessage":"Request failed: {nameof(GetRepositoryAsync)}","messagePattern":"Request failed: (.+?)","errorType":"exception","errorClass":"InvalidDataException","httpStatus":null,"severity":"error","filePath":"dotnet/samples/LearnResources/Plugins/GitHub/GitHubPlugin.cs","lineNumber":32,"sourceCode":"}\n\ninternal sealed class GitHubPlugin(GitHubSettings settings)\n{\n    [KernelFunction]\n    public async Task<GitHubModels.User> GetUserProfileAsync()\n    {\n        using HttpClient client = this.CreateClient();\n        JsonDocument response = await MakeRequestAsync(client, \"/user\");\n        return response.Deserialize<GitHubModels.User>() ?? throw new InvalidDataException($\"Request failed: {nameof(GetUserProfileAsync)}\");\n    }\n\n    [KernelFunction]\n    public async Task<GitHubModels.Repo> GetRepositoryAsync(string organization, string repo)\n    {\n        using HttpClient client = this.CreateClient();\n        JsonDocument response = await MakeRequestAsync(client, $\"/repos/{organization}/{repo}\");\n\n        return response.Deserialize<GitHubModels.Repo>() ?? throw new InvalidDataException($\"Request failed: {nameof(GetRepositoryAsync)}\");\n    }\n\n    [KernelFunction]\n    public async Task<GitHubModels.Issue[]> GetIssuesAsync(\n        string organization,\n        string repo,\n        [Description(\"default count is 30\")]\n        int? maxResults = null,\n        [Description(\"open, closed, or all\")]\n        string state = \"\",\n        string label = \"\",\n        string assignee = \"\")\n    {\n        using HttpClient client = this.CreateClient();\n\n        string path = $\"/repos/{organization}/{repo}/issues?\";\n        path = BuildQuery(path, \"state\", state);\n        path = BuildQuery(path, \"assignee\", assignee);","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/samples/LearnResources/Plugins/GitHub/GitHubPlugin.cs#L14-L50","documentation":"An InvalidDataException thrown by GetRepositoryAsync when the /repos/{org}/{repo} response deserializes to a null GitHubModels.Repo. Indicates the JSON shape did not map to the expected Repo object.","triggerScenarios":"Calling GetRepositoryAsync(org, repo) where the repos endpoint returns a body that yields null on deserialization (404 JSON error object, empty body, schema mismatch).","commonSituations":"Wrong organization/repo name (GitHub returns a JSON error, not a Repo); token without repo access; API/schema drift.","solutions":["Verify organization and repo names are correct and accessible with the configured token.","Inspect the raw response to distinguish a 404 error body from a real Repo payload.","Ensure MakeRequestAsync surfaces non-2xx status as exceptions rather than passing error JSON to the deserializer."],"exampleFix":"// before\nreturn response.Deserialize<GitHubModels.Repo>() ?? throw new InvalidDataException($\"Request failed: {nameof(GetRepositoryAsync)}\");\n// after - guard against 404 error JSON shapes\nvar repo = response.Deserialize<GitHubModels.Repo>();\nif (repo is null) throw new InvalidDataException($\"{nameof(GetRepositoryAsync)}: '{organization}/{repo}' not found or unexpected body.\");\nreturn repo;","handlingStrategy":"try-catch","validationCode":"if (string.IsNullOrWhiteSpace(organization) || string.IsNullOrWhiteSpace(repo))\n    throw new ArgumentException(\"Organization and repo are required.\");\nif (string.IsNullOrWhiteSpace(settings.Token)) throw new InvalidOperationException(\"GitHub token is not configured.\");","typeGuard":null,"tryCatchPattern":"try { return await plugin.GetRepositoryAsync(org, repo); }\ncatch (InvalidDataException ex) when (ex.Message.Contains(nameof(GitHubPlugin.GetRepositoryAsync))) { /* verify org/repo names and token access */ }","preventionTips":["Validate org/repo names before calling.","Ensure the HTTP layer rejects 404 error JSON before deserialization.","Confirm token scopes cover the target repository."],"tags":["github","plugin","deserialization","network"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}