Menu

#8 No coverage for nested generic classes

closed-fixed
None
5
2010-07-07
2009-07-22
Anonymous
No

It seems that if a class contains another class that is generic, then no coverage data is recorded for the nested class. Non-generic nested classes seem to work fine.

For example:

public class Test
{
public class InnerTest<T>
{
private int _i;

public InnerTest(int i)
{
_i = i;
}
}
}

This will show up in the List as TestInnerTest`1 (with no period between the parent and nested class names) and it will report 0% coverage even if the code is executed. Also, clicking on any method does not make the code show up in the coverage details view.

Discussion

  • Nobody/Anonymous

    Actually, it seems like it is any generic class, not just nested ones.

     
  • Daniel P.

    Daniel P. - 2010-01-02

    I looked at the code and found the following:
    In 'PartCover.CorDriver\il_instrumentator.cpp' in Line 262 the following method is called:
    if(FAILED(info->GetClassIDInfo(funcClass, NULL, &typeDef))) {

    This method does not work for generic types. Instead you have to use ICorProfilerInfo2::GetClassIDInfo2.
    See http://msdn.microsoft.com/en-us/library/ms231902.aspx for details.

     
  • Shaun Wilde

    Shaun Wilde - 2010-06-18
    • assigned_to: nobody --> sawilde
     
  • Shaun Wilde

    Shaun Wilde - 2010-06-18

    This may have been fixed as part of the git for merge - will create a test for this scenario

     
  • Shaun Wilde

    Shaun Wilde - 2010-06-18
    • status: open --> open-accepted
     
  • Shaun Wilde

    Shaun Wilde - 2010-06-20

    The new code that has been released now resolves this issue (coverage)

    public class NestedGeneric
    {
    public class InnerTest<T>
    {
    private T _Val;

    public InnerTest(T val)
    {
    _Val = val;
    }

    }
    }

    called using

    new NestedGeneric.InnerTest<string>("xxx");
    new NestedGeneric.InnerTest<int>(1);

    returned the following coverage

    <Type asmref="1" name="PartCover.StressTest.Classes.NestedGenericInnerTest`1" flags="0">
    <Method name=".ctor" sig="void ()" bodysize="18" flags="0" iflags="0">
    <pt visit="2" pos="0" len="7" fid="2" sl="14" sc="13" el="14" ec="36" />
    <pt visit="2" pos="7" len="1" fid="2" sl="15" sc="13" el="15" ec="14" />
    <pt visit="2" pos="8" len="7" fid="2" sl="16" sc="17" el="16" ec="28" />
    <pt visit="2" pos="15" len="2" fid="2" sl="17" sc="13" el="17" ec="14" />
    </Method>
    </Type>

    The reported missing . (period) doesn't appear to be affecting the coverage viewer - however using ildasm the class appears as

    PartCover.StressTest.Classes.NestedGeneric/InnerTest`1<string>::.ctor(int32) when being called

    I am going to consider this issue fixed and raise another issue regarding the name (minor though as it does not appear to affect the coverage or reporting at this moment in time)

     
  • Shaun Wilde

    Shaun Wilde - 2010-06-20
    • status: open-accepted --> open-fixed
     
  • Shaun Wilde

    Shaun Wilde - 2010-06-26
    • status: open-fixed --> pending-fixed
     
  • Shaun Wilde

    Shaun Wilde - 2010-07-07
    • status: pending-fixed --> closed-fixed
     

Log in to post a comment.