NullReferenceException

12 views
Skip to first unread message

MarkusSchaber

unread,
Nov 26, 2009, 4:11:48 AM11/26/09
to Gendarme
Hello,

We're currently experimenting with Code Analysis tools, and I tried
Gendarme on one of our DLLs (proprietary code, so I'm not sure whether
I get permission to disclose that dll). I Installed the Gendarme
Package and started the "wizard" via start menu, using Vista64.

After some seconds of analyzing, Gendarme seems to get a
NullReferenceException.

Beschreibung:
Stopped working

Problemsignatur:
Problemereignisname: CLR20r3
Problemsignatur 01: gendarmewizard.exe
Problemsignatur 02: 2.4.0.0
Problemsignatur 03: 49d8bcae
Problemsignatur 04: mscorlib
Problemsignatur 05: 2.0.0.0
Problemsignatur 06: 4a9ee411
Problemsignatur 07: 4211
Problemsignatur 08: a9
Problemsignatur 09: System.NullReferenceException
Betriebsystemversion: 6.0.6002.2.2.0.256.6
Gebietsschema-ID: 1031

When I click on visual studio, I get an exception popup with the
following call stack:

System.NullReferenceException was unhandled
Message="Der Objektverweis wurde nicht auf eine Objektinstanz
festgelegt."
Source="mscorlib"
StackTrace:
Server stack trace:
bei
Gendarme.Rules.Correctness.ReviewInconsistentIdentityRule.ProcessMethod
(TypeDefinition type, MethodDefinition method, MethodInfo info)
bei
Gendarme.Rules.Correctness.ReviewInconsistentIdentityRule.CheckType
(TypeDefinition type)
bei Gendarme.Framework.Runner.OnType(RunnerEventArgs e)
bei Gendarme.GuiRunner.OnType(RunnerEventArgs e)
bei Gendarme.Framework.Runner.Run()
bei Gendarme.Wizard.Analyze()
bei
System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage
(IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean
fExecuteInContext, Object[]& outArgs)
bei
System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage
(IMessage msg, IMessageSink replySink)
Exception rethrown at [0]:
bei System.Runtime.Remoting.Proxies.RealProxy.EndInvokeHelper
(Message reqMsg, Boolean bProxyCase)
bei System.Runtime.Remoting.Proxies.RemotingProxy.Invoke(Object
NotUsed, MessageData& msgData)
bei Gendarme.Wizard.MethodInvoker.EndInvoke(IAsyncResult
result)
bei
System.Runtime.Remoting.Messaging.AsyncResult.SyncProcessMessage
(IMessage msg)
bei
System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage
(IMessage msg, IMessageSink replySink)
bei
System.Runtime.Remoting.Proxies.AgileAsyncWorkerItem.ThreadPoolCallBack
(Object o)
bei System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
bei
System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal
(_ThreadPoolWaitCallback tpWaitCallBack)
bei System.Threading._ThreadPoolWaitCallback.PerformWaitCallback
(Object state)
InnerException:


The "Call Stack" window of Visual Studio displays the following:
> mscorlib.dll!System.Runtime.Remoting.Proxies.RealProxy.EndInvokeHelper(System.Runtime.Remoting.Messaging.Message reqMsg, bool bProxyCase) + 0x15b bytes
mscorlib.dll!System.Runtime.Remoting.Proxies.RemotingProxy.Invoke
(object NotUsed, ref System.Runtime.Remoting.Proxies.MessageData
msgData) + 0x295 bytes
[Native to Managed Transition]
[Managed to Native Transition]
mscorlib.dll!
System.Runtime.Remoting.Messaging.AsyncResult.SyncProcessMessage
(System.Runtime.Remoting.Messaging.IMessage msg) + 0x168 bytes
mscorlib.dll!
System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage
(System.Runtime.Remoting.Messaging.IMessage msg,
System.Runtime.Remoting.Messaging.IMessageSink replySink) + 0x33e
bytes
mscorlib.dll!
System.Runtime.Remoting.Proxies.AgileAsyncWorkerItem.ThreadPoolCallBack
(object o) + 0x58 bytes
mscorlib.dll!System.Threading.ExecutionContext.Run
(System.Threading.ExecutionContext executionContext,
System.Threading.ContextCallback callback, object state) + 0x9b bytes
mscorlib.dll!
System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal
(System.Threading._ThreadPoolWaitCallback tpWaitCallBack) + 0x61
bytes
mscorlib.dll!
System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(object
state) + 0x4f bytes

Thanks for your patience,
Markus Schaber

MarkusSchaber

unread,
Nov 26, 2009, 8:26:46 AM11/26/09
to Gendarme
Hi,

On 26 Nov., 10:11, MarkusSchaber <m...@soloplan.de> wrote:
> We're currently experimenting with Code Analysis tools, and I tried
> Gendarme on one of our DLLs (proprietary code, so I'm not sure whether
> I get permission to disclose that dll). I Installed the Gendarme
> Package and started the "wizard" via start menu, using Vista64.
>
> After some seconds of analyzing, Gendarme seems to get a
> NullReferenceException.
[...]

Additional information: Running GendarmeWizard in Mono seems to freeze
the UI without any interaction after finding of 90 problems. Running
gendarme from command line via mono (Mono 2.4 on the same windows
vista) produces the following output:

C:\Program Files (x86)\Novell\Gendarme>gendarme c:\Path\to\MyDll.dll
Gendarme v2.4.0.0
Copyright (C) 2005-2009 Novell, Inc. and contributors

Initialization: 0,7 seconds
Soloplan.Map.Drawing.dll
An uncaught exception occured. Please fill a bug report at
https://bugzilla.novell.com/
Rule: Gendarme.Rules.Correctness.ReviewInconsistentIdentityRule
Target: Soloplan.Map.Drawing.Geometrie.Geometry
Stack trace: System.NullReferenceException: Der Objektverweis wurde
nicht auf eine Objektinstanz festgelegt.
bei
Gendarme.Rules.Correctness.ReviewInconsistentIdentityRule.ProcessMethod
(TypeDefinition type, MethodDefinition method, MethodInfo info)
bei
Gendarme.Rules.Correctness.ReviewInconsistentIdentityRule.CheckType
(TypeDefinition type)
bei Gendarme.Framework.Runner.OnType(RunnerEventArgs e)
bei Gendarme.Framework.Runner.Run()
bei Gendarme.ConsoleRunner.Run()
bei Gendarme.ConsoleRunner.Execute(String[] args)

C:\Program Files (x86)\Novell\Gendarme>

Sebastien Pouliot

unread,
Nov 26, 2009, 8:29:43 AM11/26/09
to gend...@googlegroups.com
Hello Markus,

Could you try the gendarme console runner ? i.e. gendarme.exe in a
console window. This should give us a few more details including, iirc,
the method where the NRE occurred.

If you can identity the method then it should be simple to extract a
test case (without disclosing the DLL or the IP within).

Thanks
Sebastien
> --
>
> You received this message because you are subscribed to the Google Groups "Gendarme" group.
> To post to this group, send email to gend...@googlegroups.com.
> To unsubscribe from this group, send email to gendarme+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/gendarme?hl=en.
>
>


Sebastien Pouliot

unread,
Nov 26, 2009, 8:35:25 AM11/26/09
to gend...@googlegroups.com
On Thu, 2009-11-26 at 05:26 -0800, MarkusSchaber wrote:
> Hi,
>
> On 26 Nov., 10:11, MarkusSchaber <m...@soloplan.de> wrote:
> > We're currently experimenting with Code Analysis tools, and I tried
> > Gendarme on one of our DLLs (proprietary code, so I'm not sure whether
> > I get permission to disclose that dll). I Installed the Gendarme
> > Package and started the "wizard" via start menu, using Vista64.
> >
> > After some seconds of analyzing, Gendarme seems to get a
> > NullReferenceException.
> [...]
>
> Additional information: Running GendarmeWizard in Mono seems to freeze
> the UI without any interaction after finding of 90 problems. Running
> gendarme from command line via mono (Mono 2.4 on the same windows
> vista) produces the following output:
>
> C:\Program Files (x86)\Novell\Gendarme>gendarme c:\Path\to\MyDll.dll
> Gendarme v2.4.0.0
> Copyright (C) 2005-2009 Novell, Inc. and contributors
>
> Initialization: 0,7 seconds
> Soloplan.Map.Drawing.dll
> An uncaught exception occured. Please fill a bug report at
> https://bugzilla.novell.com/
> Rule: Gendarme.Rules.Correctness.ReviewInconsistentIdentityRule
> Target: Soloplan.Map.Drawing.Geometrie.Geometry

A quick guess: could this type has abstract (or pinvoke) methods ?

In particular methods like Equals, CompareTo, operators, Clone and
GetHashCode.

I think the NRE comes from:
foreach (Instruction ins in method.Body.Instructions) {
when a method is found without a body (hence the abstract/pinvoke
guess ;-)

Thanks for the details
Sebastien

> Stack trace: System.NullReferenceException: Der Objektverweis wurde
> nicht auf eine Objektinstanz festgelegt.
> bei
> Gendarme.Rules.Correctness.ReviewInconsistentIdentityRule.ProcessMethod
> (TypeDefinition type, MethodDefinition method, MethodInfo info)
> bei
> Gendarme.Rules.Correctness.ReviewInconsistentIdentityRule.CheckType
> (TypeDefinition type)
> bei Gendarme.Framework.Runner.OnType(RunnerEventArgs e)
> bei Gendarme.Framework.Runner.Run()
> bei Gendarme.ConsoleRunner.Run()
> bei Gendarme.ConsoleRunner.Execute(String[] args)
>
> C:\Program Files (x86)\Novell\Gendarme>
>

MarkusSchaber

unread,
Nov 27, 2009, 2:38:22 AM11/27/09
to Gendarme
Hi,

On 26 Nov., 14:35, Sebastien Pouliot <sebastien.poul...@gmail.com>
wrote:
> A quick guess: could this type has abstract (or pinvoke) methods ?

AFAICs, we don't use p/Invoke anywhere in this dll, but I'm sure that
we use abstract methods.

> I think the NRE comes from:
>         foreach (Instruction ins in method.Body.Instructions) {
> when a method is found without a body (hence the abstract/pinvoke
> guess ;-)

So you think that the foreach uses a method from an abstract type
which is only actually implemented in subclasses. I'll try to extract
a small test case.

Thanks,
markus

MarkusSchaber

unread,
Nov 27, 2009, 4:26:57 AM11/27/09
to Gendarme
Hi,

This is the smallest test case I could come up with. Surprisingly, the
foreach loop involving abstract methods was not the cause, it seems. I
compiled it with Visual Studio 2008 debug build, and can send you the
dll or solution via email if necessary.

Thanks,
Markus

-- snip --
namespace GendarmeTest
{
using System;

public class AttributeA { }

public class AttributeB { }

public abstract class Testclass : IEquatable<Testclass>
{
public AttributeA AttributeA
{
get;
protected set;
}

public abstract AttributeB AttB
{
get;
}

public abstract bool Equals(Testclass other);

public override bool Equals(object obj)
{
Testclass geom = obj as Testclass;
if (geom == null || geom.GetType() != this.GetType())
return false;
return Equals(geom);
}
}
}

Sebastien Pouliot

unread,
Nov 27, 2009, 8:18:39 PM11/27/09
to gend...@googlegroups.com
Hello Markus,

On Fri, 2009-11-27 at 01:26 -0800, MarkusSchaber wrote:
> Hi,
>
> This is the smallest test case I could come up with. Surprisingly, the
> foreach loop involving abstract methods was not the cause, it seems. I
> compiled it with Visual Studio 2008 debug build, and can send you the
> dll or solution via email if necessary.
>
> Thanks,
> Markus
>
> -- snip --
> namespace GendarmeTest
> {
> using System;
>
> public class AttributeA { }
>
> public class AttributeB { }
>
> public abstract class Testclass : IEquatable<Testclass>
> {
> public AttributeA AttributeA
> {
> get;
> protected set;
> }
>
> public abstract AttributeB AttB
> {
> get;
> }
>
> public abstract bool Equals(Testclass other);

^ that's the 'abstract method' I was talking about (95% certain ;-). The
rule code tries to look at the method body (and there's none) to compare
it with other equality-like methods (for fields and properties used).

I hope to have some time this weekend (or else in the next weekends :-)
and I'll fix this and make sure it's available (with other fixes) in
2.6.

Thanks for your report and test case!
Sebastien

>
> public override bool Equals(object obj)
> {
> Testclass geom = obj as Testclass;
> if (geom == null || geom.GetType() != this.GetType())
> return false;
> return Equals(geom);
> }
> }
> }
>

Sebastien Pouliot

unread,
Nov 28, 2009, 11:05:45 AM11/28/09
to Gendarme
Fixed in HEAD (r147054) and 2-6 (r147055)
Thanks

On Nov 27, 8:18 pm, Sebastien Pouliot <sebastien.poul...@gmail.com>
wrote:
Reply all
Reply to author
Forward
0 new messages