Trying to get bugsnag working in a C# Asp.Net core 3.1 console application. We have added Bugsnag.AspNet.Core version 2.2.1 to the application. We have added Microsoft.Extensions.DependancyInjection version 3.1.15 to the application.
We made a simpler console application to get it down to just the basic application trying to use bugsnag. Here is our code.
class Program
{
static void Main(string[] args)
{
IServiceCollection services = new ServiceCollection();
services.AddBugsnag(configuration =>
{
configuration.ApiKey = "";
configuration.ReleaseStage = "Development";
});
var serviceProvider = services.BuildServiceProvider();
serviceProvider.GetService<DurationService>().SetCallSummary();
}
}
And the service.
public interface IDurationService
{
void SetCallSummary();
}
public class DurationService : IDurationService
{
private readonly Bugsnag.IClient _bugsnag;
public DurationService(Bugsnag.IClient client)
{
_bugsnag = client;
}
public void SetCallSummary()
{
try
{
throw new NotImplementedException();
} catch (Exception ex)
{
_bugsnag.Notify(ex);
}
}
}
It keeps failing to initialize saying that there is a null object reference when hitting the service. The null reference is to the bugsnag object that is being injected.
Please help!
Bugsnag's ASP.NET Core library supports both AP.NET Core 1.x and 2.x, running on either .NET Core (1.0+) or the full .Net framework (4.6+). It looks like you are using version 3.1, which isn't yet supported.