question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Null Exception on AddAspNet

See original GitHub issue

Package

Sentry.AspNet

.NET Flavor

.NET

.NET Version

4.7

OS

Windows

SDK Version

3.20.1

Self-Hosted Sentry Version

No response

Steps to Reproduce

I was trying to figure out how to support Transactions for a OWIN application but it seems like when adding the AddAspNet to the code it throws a nullexception error. The only plausible cause is the HttpContext being null here: https://github.com/getsentry/sentry-dotnet/blob/main/src/Sentry.AspNet/Internal/SystemWebVersionLocator.cs#L20

Expected Result

AddAspNet to not throw a null Exception

Actual Result

image There are no line numbers :\

   at Sentry.AspNet.Internal.SystemWebVersionLocator.Resolve(HttpContext context)
   at Sentry.AspNet.SentryAspNetOptionsExtensions.AddAspNet(SentryOptions options, RequestSize maxRequestBodySize)

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
mattjohnsonpintcommented, Aug 31, 2022

@lucas-zimerman - Once this gets released (or if you want to do a custom build now), please let us know if Simon’s change in #1881 solved the issue. I’ll leave this open until you can check. Thanks.

1reaction
SimonCroppcommented, Aug 29, 2022

looking at the code in question

    internal static string? Resolve(HttpContext context)
    {
        if (context.ApplicationInstance?.GetType() is { } type)
        {
            // Usually the type is ASP.global_asax and the BaseType is the Web Application.
            while (type is { Namespace: "ASP" })
            {
                type = type.BaseType;
            }

            if (type?.Assembly is { } assembly)
            {
                return ApplicationVersionLocator.GetCurrent(assembly);
            }
        }

        return null;
    }

the only way i can see a null ref is if HttpContext is null. googling around there seems to be many scenario where HttpContext.Current can be null. given SystemWebVersionLocator.Resolve seems to be “best effort” at finding version. do we add a null check and return null?

Read more comments on GitHub >

github_iconTop Results From Across the Web

I am getting null pointer exception in asp.net application
It works flawlessly in test environment, however, I am getting null reference exception in real server. I am using ninject.
Read more >
Why am I getting a null reference exception for ASP.NET ...
Because houseNo is null in this case, the value from the database is not retrun a value (null). When binding the model (@默...
Read more >
NullReferenceException Class (System)
The exception that is thrown when there is an attempt to dereference a null object reference.
Read more >
Rotativa Cannot perform runtime binding on a null reference ...
Answer. The error indicates that you haven't configured Rotativa. Configuration your application like this: public void Configure(IApplicationBuilder app, ...
Read more >
Migration Guide for .NET
Upgrading includes both breaking changes and new features. Migrating to 3.12.0. NuGet Changes. If you're using the Sentry.EntityFramework NuGet package ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found