-
Notifications
You must be signed in to change notification settings - Fork 748
NullReferenceException in ExceptionHelper.BuildMessage on Mono #2450
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
Comments
Digging a bit more, if (ex is NUnitException || ex is TargetInvocationException)
ex = ex.InnerException; I have no idea if that's actually possible, but it might be worth changing the if ((ex is NUnitException || ex is TargetInvocationException) && ex.InnerException != null) |
Could you use the --labels=Before option to pinpoint the test which is crashing the runner, and then recreate the situation as a unit test in the NUnit tests? I think we should definitely have a unit test for this, if there's a specific mono oddity. |
What I usually do is open the NUnit assembly in dotPeek with the 'Show IL code in comments' option and find the line with the offset from the stack trace (in this case, I like your suggested fix, but we should also throw ArgumentNullException for null |
@ChrisMaddock, @jnm2: Thanks for the tips, I'll try to get my hands dirty with this tomorrow. |
We should do a null check in |
@ChrisMaddock: This is the failing test. Given the amount of code required to reproduce that, I'm not sure how to do it, to be honest. If you can spot anything weird going on there, please let me know and I'll try to extract just the weird bits into a unit test for NUnit. @jnm2: With IL code comments on, dotPeek did not give me the // IL_0008: call class [mscorlib]System.Globalization.CultureInfo [mscorlib]System.Globalization.CultureInfo::get_CurrentCulture()
// IL_000d: ldstr "{0} : {1}" Given that the decompiled code looks like this: stringBuilder.AppendFormat((IFormatProvider) CultureInfo.CurrentCulture, "{0} : {1}", new object[2]
{
(object) exception.GetType().ToString(),
(object) exception.Message
}); It seems plausible to me that instruction Would you accept a PR just performing some more rigorous |
@asbjornu Weird. I pulled the net45 DLL from the 3.8.1 NuGet package, which it looked like your project was referencing when I read your csproj, and I do get this for the first three lines: // IL_0000: newobj instance void [mscorlib]System.Text.StringBuilder::.ctor()
// IL_0005: stloc.0 // 'stringBuilder [Range(Instruction(IL_0005 stloc.0)-Instruction(IL_0091 ldloc.0))]'
// IL_0006: ldarg.1 // excludeExceptionNames
// IL_0007: brtrue.s IL_001b
// IL_0009: ldloc.0 // 'stringBuilder [Range(Instruction(IL_0005 stloc.0)-Instruction(IL_0091 ldloc.0))]'
// IL_000a: ldstr "{0} : "
// IL_000f: ldarg.0 // exception
// IL_0010: callvirt instance class [mscorlib]System.Type [mscorlib]System.Exception::GetType()
// IL_0015: callvirt instance class [mscorlib]System.Text.StringBuilder [mscorlib]System.Text.StringBuilder::AppendFormat(string, object)
// IL_001a: pop But we come to the same conclusion, so no matter. =) Provoking the problem would be preferred unless it is too involved. |
I think placing a guard clause on entry to a method that doesn't handle null args is common sense. Adding an if clause where an arg is used, so that null is silently ignored could hide a coding error in the caller. It makes sense to look at all the callers in that case. I think complex cases where an arg or other value is sometimes null and sometimes not calls for a test. Simple cases (null not alowed) don't seem to need a test. |
Is there a workaround for this issue? I'm getting this exception when using nunit-console 3.8 |
Implementation finished. @hoihoi8 Do you still have a repro? I apologize that so much time has passed, but if I could make sure I actually covered your scenario, that would be great! |
When executing the tests in this project with NUnit.ConsoleRunner version 3.7 (and NUnit version 3.8.1), it currently fails in Mono with a
NullReferenceException
:I've tried to do a custom build of NUnit locally and drop in the
.pdb
, but I don't get line numbers out so I'm probably not twisting the right knobs. Looking at the method, it's not very complicated:Since
BuildMessage
is at the top of the stack, the problem can't be withinGetExceptionMessage()
orFlattenExceptionHierarchy()
, sot he only obvious problem here is ifexception
isnull
andexcludeExceptionNames
isfalse
, which will causeexception.GetType()
to blow up.I can submit a PR that preforms some
null
checks on the code, but would like some advice from you guys first.The text was updated successfully, but these errors were encountered: