External Annotations for ReSharper

Most ReSharper information comes from code inspection and analysis, but not all details can be inferred from the source code alone. For example, code called by reflection (e.g. Activator.CreateInstance) looks like dead code to static analysis. R# offers a solution in the form of External Annotations, XML files supplying extra information.

If you use a test framework other than NUnit, e.g. MbUnit, you may find that your tests are marked as unused by R# even though they can be run. This can fixed by supplying some annotations, the XML needs to go in “%SystemDrive%\Program Files\JetBrains\ReSharper\[Build#]\Bin\ExternalAnnotations\[DllName]\[DllName].xml”. So for MbUnit, it would be ExternalAnnotations\MbUnit\MbUnit.xml. The file needs a list of types, associated with the appropriate R# attribute. The MeansImplicitUseAttribute:

<assembly name="MbUnit">
  <member name="T:MbUnit.Framework.TestAttribute">
    <attribute ctor="M:JetBrains.Annotations.MeansImplicitUseAttribute.#ctor" />

states that any code tagged with the TestAttribute will not be considered unused. Other useful attributes are the AssertionMethodAttribute:

  <member name="M:MbUnit.Framework.Assert.IsNotNull(System.Object)">
    <attribute ctor="M:JetBrains.Annotations.AssertionMethodAttribute.#ctor"/>
    <parameter name="anObject">
      <attribute ctor="M:JetBrains.Annotations.AssertionConditionAttribute.#ctor(JetBrains.Annotations.AssertionConditionType)">

the TerminatesProgramAttribute:

  <member name="M:MbUnit.Framework.Assert.Fail">
    <attribute ctor="M:JetBrains.Annotations.TerminatesProgramAttribute.#ctor"/>

and the NotNullAttribute. An external annotation file is shipped with the more recent versions of MbUnit.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s