[FxCop] error on analysis in 1.35

Error on Analysis run of DoNotCallOverridableMethodsInConstructors in 1.35
Index was outside the bounds of the array.
at Microsoft.FxCop.Sdk.Introspection.RuleUtilities.GetInstancePointer(Method caller, Int32 offsetToCall)
at Microsoft.FxCop.Rules.Usage.DoNotCallOverridableMethodsInConstructors.CheckCallees(Method method, Boolean isCallVirt)
at Microsoft.FxCop.Rules.Usage.DoNotCallOverridableMethodsInConstructors.CheckCallees(Method method, Boolean isCallVirt)
at Microsoft.FxCop.Rules.Usage.DoNotCallOverridableMethodsInConstructors.Check(Member member)
at Microsoft.FxCop.Engines.Introspection.AnalysisVisitor.CheckMember(Member member, NodeBase target)

example:
class one
{
one(bool init){ if (init) { init (new List<int>())};
protected void init (List<int> a) { a.add(1);}
public virtual foo() {}
}
class two : one
{
two(bool init){ if (init) { init (new List<int>())};
}
class three : two
{
three(bool init){ if (init) { init (new List<int>())};

void new init(List<int> a) { a.add(3); base.init (a);}
public override foo() {}
}

I know the List is another issue - but it is in the code that produced the error so I thought I should include it in case it is the cause. There is no virtual functions being called anywhere in the constructor chain, though there is one virtual method in the "one" class that is overridden in the "three" class.

[1604 byte] By [BryanDonaldson] at [2007-12-20]
# 1

Hi Bryan,

after making a couple of changes I got your code to compile, but didn't see the exception above. Does the exception happen on the sample code you sent, or only on your production code?

That said, we'll take a look if we can improve this code path to be more robust against unexpected code.

Thanks,

Jeffrey van Gogh
Code Analysis Development Team

JeffreyvanGogh-MSFT at 2007-9-9 > top of Msdn Tech,Visual Studio Team System,Visual Studio Code Analysis and Code Metrics...
# 2
The error occurs on my production code - not the sample, sorry. I was hoping that the sample would produce the error.
BryanDonaldson at 2007-9-9 > top of Msdn Tech,Visual Studio Team System,Visual Studio Code Analysis and Code Metrics...
# 3
I'm getting this exception when running the rule on production code, too. Looking forward to a more robust rule...
GraemeFoster at 2007-9-9 > top of Msdn Tech,Visual Studio Team System,Visual Studio Code Analysis and Code Metrics...
# 4

Graeme,

Can you post a code sample that is able to to reproduce the problem? We can't fix the problem, if we can't reproduce it. ;)

Regards

David

DavidM.Kean-MSFT at 2007-9-9 > top of Msdn Tech,Visual Studio Team System,Visual Studio Code Analysis and Code Metrics...
# 5

I've reproduced this based on this other thread: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=971658&SiteID=1&mode=1 and confirmed that this has been fixed in the latest builds.

Regards

David

DavidM.Kean-MSFT at 2007-9-9 > top of Msdn Tech,Visual Studio Team System,Visual Studio Code Analysis and Code Metrics...

Visual Studio Team System

Site Classified