Unhandled exception: System.NullReferenceException: Object reference not set to an instance of an object.

Đang mở
#5,673 3 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
42/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
csharp
Lĩnh vực
devtools, observability

Hướng nghiên cứu

Bắt đầu tại dòng 200 của src/Tools/dotnet-counters/CounterMonitor.cs và tái hiện lời gọi dotnet-counters monitor -n ConsoleApp --counters HatCo.Store từ issue trong Visual Studio Package Manager Console. Sử dụng mẫu .NET 8 được cung cấp để theo dõi đường dẫn tham chiếu null, sau đó xác minh rằng việc giám sát bộ đếm HatCo.Store không còn thoát do một ngoại lệ chưa được xử lý.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

bug
Description

I followed the documentation on learn.microsoft.com:

and have trouble to use the dotnet-counters monitor tool in the visual studio package manger console.

I'm getting an Unhandled exception: System.NullReferenceException: Object reference not set to an instance of an object.

PM> dotnet-counters monitor -n ConsoleApp --counters HatCo.Store
dotnet-counters : Unhandled exception: System.NullReferenceException: Object reference not set to an instance of an object.
At line:1 char:1
+ dotnet-counters monitor -n ConsoleApp --counters HatCo.Store
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (Unhandled excep...e of an object.:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
 
   at Microsoft.Diagnostics.Tools.Counters.CounterMonitor.Monitor(CancellationToken ct, String counters, Int32 processId, Int32 
refreshInterval, String name, String diagnosticPort, Boolean resumeRuntime, Int32 maxHistograms, Int32 maxTimeSeries, TimeSpan duration, 
Boolean showDeltas, String dsrouter) in /_/src/Tools/dotnet-counters/CounterMonitor.cs:line 200
   at System.CommandLine.Command.<>c__DisplayClass32_0.<<SetAction>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Invocation.InvocationPipeline.InvokeAsync(ParseResult parseResult, CancellationToken cancellationToken)

PM> dotnet-counters --version
9.0.652701+240cb1ce5bc30594c515206764241d7982e384af

I appreciate any help.

Configuration

Start the following source code in .NET 8.0 and run dotnet-counters in Visual Studio 2022 package manager console

using System.Diagnostics.Metrics;
using Microsoft.Extensions.DependencyInjection;

class Program
{
    static void Main(string[] arguments)
    {
        Console.WriteLine("Press any key to exit");

        using ServiceProvider serviceProvider = CreateServiceProvider();

        var hatCoMetrics = serviceProvider.GetRequiredService<HatCoMetrics>();

        Random random = new();
        while (!Console.KeyAvailable)
        {
            // Pretend our store has a transaction, every 100ms, that sells two size 12 red hats, and one size 19 blue hat.
            Thread.Sleep(random.Next() % 5000);
            hatCoMetrics.HatsSold(random.Next() % 6, "red", 12);
            hatCoMetrics.HatsSold(random.Next() % 6, "blue", 19);
        }
    }

    // Setup a new service provider. This example creates the collection explicitly but you might leverage
    // a host or some other application setup code to do this as well.
    private static ServiceProvider CreateServiceProvider()
    {
        ServiceCollection serviceCollection = new();
        serviceCollection.AddMetrics();
        serviceCollection.AddSingleton<HatCoMetrics>();
        return serviceCollection.BuildServiceProvider();
    }
}

public class HatCoMetrics
{
    private readonly Counter<int> _hatsSold;

    public HatCoMetrics(IMeterFactory meterFactory)
    {
        Meter meter = meterFactory.Create("HatCo.Store");
        _hatsSold = meter.CreateCounter<int>("hatco.store.hats_sold");
    }

    public void HatsSold(int quantity, string color, ushort size)
    {
        if (quantity == 0) return;

        _hatsSold.Add(quantity,
            new KeyValuePair<string, object?>("product.color", color),
            new KeyValuePair<string, object?>("product.size", size)
        );
    }
}
Ngôn ngữ chính
C++
Star
1.3k
Fork
407
Merge trung bình
21 giờ 5 phút
Pull request đã merge (30 ngày)
78

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

  • Không có Dockerfile hay tệp Docker Compose
  • Không có mẫu pull request
  • Không có hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của dotnet/diagnostics

Tất cả issue của dotnet/diagnostics

Issue tương tự

Thêm issue về C++

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.