"Possible 'System.NullReferenceException'" is not working anymore.

Hello!

I was getting the warning as expected, and it would go away using Debug.Assert() before accessing a variable.

Then I defined the custom null checking statement to use my own assertion method, and replaced the call to Debug.Assert() to a call to my method.

Since the warning wouldn't go away, I searched and found a support post and did what was
suggested there, adding this attribute to my assertion method:
[JetBrains.Annotations.ContractAnnotation("obj:null => halt")]

And the warning when accessing the variable went away, as expected.

So, just to make sure everything was working fine, I removed the call to my
assertion method, and the warning doesn't come back.

I've even tried to entirely remove my method from the code, changed assertion check
patterns to what they were before, and make it use Debug.Assert as the first one,
still nothing changes, the warning won't come back.

Tried restarting Rider, removing the .idea folder, even removing bin and debug folders just
to be sure, but nothing changed.

Tried writing some code on purpose to make sure that I hadn't done something that
screwed up that particular field or method, and I get no warning anywhere I try.

Tried with a new project and just enough code to trigger it, nothing.

class Program
{
    private static System.EventArgs someInstance;

    static void Main(string[] args)
    {
        var _ = someInstance.ToString();
    }
}

 

Checked settings to make sure I hadn't changed them by misclicking something, but
it's still active.

I have been using Rider for just a few days so I can't be sure wether this is a bug or not.

Thank you!

0
4 comments

Hi @Vad85!

Sorry for the delay. What Rider version do you use and do you have the same issue on the latest version? 

Also, I've tried your code and I have the following warning in Rider, ReSharper and also Visual Studio. Do you also have it?  Could you please double-check the example?

 

Thank you in advance! 

0

Similar problem on 2024.3.6

VS catches the null reference as expected.  Rider seems to catch all other exception, but a System.NullReferenceException just causes the app to exit.

1

rjs What's your application type? User-unhandled exceptions could not be handled in the Mono process (Unity). You could share a sample application shows the debugger issue, and I will try to investigate further.

0

It's a medium sized .net9 project.  No mono involved.  I don't have a simple repro case currently.  If I had to guess we use a lot of threads and it's likely related to the exception happening in a worker thread.

0

Please sign in to leave a comment.