"Field is never used" classification despite XmlSerializer usage

In the following example code, field public String TestElement of class Test is grayed by ReSharper and marked as "Field 'TestElement' is only assigned but its value is never used".
But it is used by XmlSerializer() in Main(). So this might be misleading during code cleanup. This field must not be removed.

Are there any settings in ReSharper to suppress this?

    static class Program
    {
        static void Main()
        {
            var test        = new Test {TestElement = "Hello, world!"};
            var serializer  = new XmlSerializer( typeof( Test ) );
            using (TextWriter fs = new StreamWriter("testfile.xml"))
                serializer.Serialize(fs, test);
        }
    }


    [Serializable]
    public class Test
    {
        [XmlElement( "testelement" )]
        public String TestElement;
    }

4 comments
Comment actions Permalink

Hello Bernhard
     In order to fix this problem please add the following text:

  <member name="T:System.Xml.Serialization.XmlElementAttribute">
    <attribute ctor="M:JetBrains.Annotations.MeansImplicitUseAttribute.#ctor()"/>
  </member>



to <ReSharper installation folder>\System.Xml\System.Xml.Attributes.xml file

Let me know if this helps. Thank you!

Andrey Serebryansky

Senior Support Engineer

JetBrains, Inc

http://www.jetbrains.com

"Develop with pleasure!"

0
Comment actions Permalink

Hi Andrey - where's that?

BR/
Bernhard

0
Comment actions Permalink

On Windows 7 64 Bit it locatet in
C:\Program Files (x86)\JetBrains\ReSharper\v6.1\Bin\ExternalAnnotations\System.Xml

If you have 32 Bit just remove (x86) part

0
Comment actions Permalink

it works - thanks, Andrey and Sven

I came across this subject while looking for a solution to remove unused code (semi)automatically from a giant C# source file:

http://devnet.jetbrains.net/message/5227802
http://devnet.jetbrains.net/message/5230262

but it turned out R# does not (yet) provide this.

NDepend is not an option.

Question: did I overlook this feature in the current R# version or is it planned in the near future?

BR/
Bernhard

0

Please sign in to leave a comment.