microsoft/semantic-kernel · error · InvalidDataException
Request failed: {nameof(GetIssueDetailAsync)}
Error message
Request failed: {nameof(GetIssueDetailAsync)} What it means
An InvalidDataException thrown by GetIssueDetailAsync when the /repos/{org}/{repo}/issues/{id} response deserializes to a null GitHubModels.IssueDetail. Indicates the body did not map to the expected issue-detail object.
Source
Thrown at dotnet/samples/LearnResources/Plugins/GitHub/GitHubPlugin.cs:68
path = BuildQuery(path, "assignee", assignee);
path = BuildQuery(path, "labels", label);
path = BuildQuery(path, "per_page", maxResults?.ToString() ?? string.Empty);
JsonDocument response = await MakeRequestAsync(client, path);
return response.Deserialize<GitHubModels.Issue[]>() ?? throw new InvalidDataException($"Request failed: {nameof(GetIssuesAsync)}");
}
[KernelFunction]
public async Task<GitHubModels.IssueDetail> GetIssueDetailAsync(string organization, string repo, int issueId)
{
using HttpClient client = this.CreateClient();
string path = $"/repos/{organization}/{repo}/issues/{issueId}";
JsonDocument response = await MakeRequestAsync(client, path);
return response.Deserialize<GitHubModels.IssueDetail>() ?? throw new InvalidDataException($"Request failed: {nameof(GetIssueDetailAsync)}");
}
private HttpClient CreateClient()
{
HttpClient client = new()
{
BaseAddress = new Uri(settings.BaseUrl)
};
client.DefaultRequestHeaders.Clear();
client.DefaultRequestHeaders.Add("User-Agent", "request");
client.DefaultRequestHeaders.Add("Accept", "application/vnd.github+json");
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {settings.Token}");
client.DefaultRequestHeaders.Add("X-GitHub-Api-Version", "2022-11-28");
return client;
}
View on GitHub (pinned to c028a0c7dc)
Solutions
- Verify the issueId exists in org/repo and is accessible with the configured token.
- Inspect the raw response to distinguish a 404 error body from a real IssueDetail payload.
- Ensure MakeRequestAsync surfaces non-2xx status as exceptions before deserialization.
Example fix
// before
return response.Deserialize<GitHubModels.IssueDetail>() ?? throw new InvalidDataException($"Request failed: {nameof(GetIssueDetailAsync)}");
// after
var detail = response.Deserialize<GitHubModels.IssueDetail>();
if (detail is null) throw new InvalidDataException($"{nameof(GetIssueDetailAsync)}: issue {issueId} in {organization}/{repo} not found or unexpected body.");
return detail; Defensive patterns
Strategy: validation
Validate before calling
if (issueId <= 0) throw new ArgumentOutOfRangeException(nameof(issueId));
if (string.IsNullOrWhiteSpace(organization) || string.IsNullOrWhiteSpace(repo)) throw new ArgumentException("org/repo required"); Type guard
bool IsValidIssueId(int id) => id > 0;
Try / catch
try { return await plugin.GetIssueDetailAsync(org, repo, issueId); }
catch (InvalidDataException ex) when (ex.Message.Contains(nameof(GitHubPlugin.GetIssueDetailAsync))) { /* verify issueId exists and token access */ } Prevention
- Validate issueId is a positive integer.
- Ensure the HTTP layer surfaces 404 before deserialization.
- Confirm token scopes for the target repository.
When it happens
Trigger: Calling GetIssueDetailAsync(org, repo, issueId) where the endpoint returns a body that yields null on deserialization (404 error JSON, empty body, schema mismatch).
Common situations: Nonexistent issueId (GitHub returns a JSON error object); token without access; API schema drift; issueId is a PR number returning a different shape.
Related errors
- Request failed: {nameof(GetUserProfileAsync)}
- Request failed: {nameof(GetRepositoryAsync)}
- Request failed: {nameof(GetIssuesAsync)}
- Response is not available.
- Failed to parse response: {responseText}
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/880b86dfbb2fb949.
Report an issue: GitHub.