Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Null Exception on AddAspNet #1875

Closed
lucas-zimerman opened this issue Aug 26, 2022 · 6 comments
Closed

Null Exception on AddAspNet #1875

lucas-zimerman opened this issue Aug 26, 2022 · 6 comments
Assignees
Labels
Bug Something isn't working

Comments

@lucas-zimerman
Copy link
Collaborator

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)
@lucas-zimerman lucas-zimerman added Bug Something isn't working Platform: .NET labels Aug 26, 2022
@SimonCropp
Copy link
Contributor

can u share a repro?

@SimonCropp SimonCropp self-assigned this Aug 29, 2022
@SimonCropp
Copy link
Contributor

@lucas-zimerman or can you re-run with break on all exception enabled to see what line it occurred on

@SimonCropp
Copy link
Contributor

SimonCropp commented 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?

@mattjohnsonpint
Copy link
Contributor

@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.

@lucas-zimerman
Copy link
Collaborator Author

lucas-zimerman commented Sep 1, 2022

Sure I'll validate it.
EDIT2: Yes it was fixed.

@lucas-zimerman
Copy link
Collaborator Author

Closing as fixed, thanks for the fix :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
Archived in project
Development

No branches or pull requests

3 participants