octokit / octokit.net

A GitHub API client library for .NET
https://octokitnet.readthedocs.io/en/latest/
MIT License
2.68k stars 1.07k forks source link

[BUG]: System.NullReferenceException in Repository.GetAllLanguages() #2947

Open anrouxel opened 3 months ago

anrouxel commented 3 months ago

What happened?

When calling Repository.GetAllLanguages() on anrouxel/MedicApp. I'm getting a System.NullReferenceException: Object reference not set to an instance of an object.

Versions

Octokit.Reactive : 13.0.0

Relevant log output

System.NullReferenceException: Object reference not set to an instance of an object. blazor.webassembly.js:1:46936
   at Octokit.PocoJsonSerializerStrategy.DeserializeObject(Object value, Type type) in /_/Octokit/SimpleJson.cs:line 1486 blazor.webassembly.js:1:46936
   at Octokit.Internal.SimpleJsonSerializer.GitHubSerializerStrategy.DeserializeObject(Object value, Type type) in /_/Octokit/Http/SimpleJsonSerializer.cs:line 205 blazor.webassembly.js:1:46936
   at Octokit.PocoJsonSerializerStrategy.DeserializeObject(Object value, Type type) in /_/Octokit/SimpleJson.cs:line 1519 blazor.webassembly.js:1:46936
   at Octokit.Internal.SimpleJsonSerializer.GitHubSerializerStrategy.DeserializeObject(Object value, Type type) in /_/Octokit/Http/SimpleJsonSerializer.cs:line 205 blazor.webassembly.js:1:46936
   at Octokit.SimpleJson.DeserializeObject(String json, Type type, IJsonSerializerStrategy jsonSerializerStrategy) in /_/Octokit/SimpleJson.cs:line 584 blazor.webassembly.js:1:46936
   at Octokit.SimpleJson.DeserializeObject[List`1](String json, IJsonSerializerStrategy jsonSerializerStrategy) in /_/Octokit/SimpleJson.cs:line 596 blazor.webassembly.js:1:46936
   at Octokit.Internal.SimpleJsonSerializer.Deserialize[List`1](String json) in /_/Octokit/Http/SimpleJsonSerializer.cs:line 22 blazor.webassembly.js:1:46936
   at Octokit.Internal.JsonHttpPipeline.DeserializeResponse[List`1](IResponse response) in /_/Octokit/Http/JsonHttpPipeline.cs:line 62 blazor.webassembly.js:1:46936
   at Octokit.Connection.<Run>d__69`1[[System.Collections.Generic.List`1[[System.Tuple`2[[System.String, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Int64, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext() in /_/Octokit/Http/Connection.cs:line 784

Code of Conduct

kfcampbell commented 3 months ago

Are you actually calling Repository.GetAllLanguages() without giving any arguments for the repository? I'm unable to reproduce this with the following code on the latest main branch release:

var client = new GitHubClient(new ProductHeaderValue("MyApp"));
var languages = await client.Repository.GetAllLanguages("octokit", "octokit.net");
foreach (var language in languages)
{
  Console.WriteLine($"{language.Name}: {language.NumberOfBytes}");
}

This prints the following:

C#: 10195466
PowerShell: 8539
Dockerfile: 637
Shell: 442
anrouxel commented 3 months ago

Hi @kfcampbell , I use Octokit.Reactive and not Octokit.

using Octokit;
using Octokit.Reactive;

class Program
{
    static string owner = "anrouxel";
    static string name = "MedicApp";

    static ObservableGitHubClient client = new ObservableGitHubClient(new ProductHeaderValue("ophion"));

    static void Main(string[] args)
    {
        // fetch all open pull requests
        client.Repository.GetAllLanguages(owner, name)
            .Subscribe(data =>
                {
                    Console.WriteLine("Language: ", data.Name);
                },
                ex =>
                {
                    Console.WriteLine("Exception found: " + ex.ToString());
                });

        // this will take a while, let's wait for user input before exiting
        Console.ReadLine();
    }
}
kfcampbell commented 3 months ago

Can you please reduce the snippet to something similar to what I gave above? As presented, it's not runnable for me.

anrouxel commented 3 months ago

I've reduced the snippet.