Bug 12694 - False positive 'UseStringEmptyRule' when using anonymous type
Summary: False positive 'UseStringEmptyRule' when using anonymous type
Status: NEW
Alias: None
Product: Tools
Classification: Mono
Component: Gendarme ()
Version: unspecified
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2013-06-14 12:49 UTC by Craig Fowler
Modified: 2013-06-14 13:02 UTC (History)
1 user (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 12694 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
NEW

Description Craig Fowler 2013-06-14 12:49:33 UTC
Using Gendarme v2.10 (as distributed in Debian 7.0/Wheezy's apt repo) a false-positive is triggered when using an anonymous type.

FYI I am compiling using MonoDevelop 3.0.3.2 on Mono 2.10.8 (again, from the Debian 7.0/Wheezy apt repo).

Code to reproduce
=================
public class MyClass
{
  public MyClass ()
  {
    Console.WriteLine(new { foo = "bar" });
  }
}

Expected result
===============
The Gendarme.Rules.Performance » UseStringEmptyRule rule should not report a failure.

Actual Result
=============
1 defect(s) found:

Target: System.String <>__AnonType0`1::ToString()
Assembly: GendarmeTest, Version=1.0.4913.31770, Culture=neutral, PublicKeyToken=null

Severity: Medium  Confidence: High
Source: /path/to/project/GendarmeTest/GendarmeTest/MyClass.cs(≈9)
Comment 1 Craig Fowler 2013-06-14 13:02:33 UTC
As a note - I have also seen the same error occur inside a LINQ statement, again with the 'Target' pointing to an anonymous type.  The code for that is somewhat more complex though and harder to create a simple POC.  Here's where the failure is (apparently) triggered though:

public Member GetByEmailAddress (string emailAddress)
{
  return (from member in _session.Query<Member>()
          join address in _session.Query<MemberEmailAddress>()
            on member equals address.Member
          where
            address.IsPrimary == true
            && address.Address == emailAddress
          select member)
    .FetchMany(x => x.EmailAddresses)
    .FirstOrDefault();
}

… where _session is a private instance field (an NHibernate ISession).

address.IsPrimary is bool and address.Address is a string.  What's peculiar about this is that there aren't any string literals in sight, yet I still see:

Target: System.String <>__AnonType0`2::ToString()
Assembly: MyAssembly, Version=0.0.1.0, Culture=neutral, PublicKeyToken=null

Severity: Medium  Confidence: High
Source: /path/to/file/NHibernateMemberAuthenticationQuery.cs(≈59)

Severity: Medium  Confidence: High
Source: /path/to/file/NHibernateMemberAuthenticationQuery.cs(≈59)