BUG: EnvDTE.CodeElement.GetStartPoint(vsCMPartBody) / GetEndPoint(vsCMPartBody) throw COMException for expression-bodied methods and properties

Some days ago I got a bug report from a user that was using the new expression-bodied methods and properties introduced by C# 6.0, which have the following form:

public class Class1
{
   public int Function1() => 0;
   public int Property1 => 0;
}

After some investigation, it turned out that the problem was in the calls to get the start/end points of the body of the EnvDTE.CodeElement representing them:

codeElement.GetStartPoint(vsCMPartBody)
codeElement.GetEndPoint(vsCMPartBody)

For those kind of code elements, the code model throws COMException (not even NotImplementedException), when it should return valid values since those expression-bodied members have…well, a body.

Today I have reported the bug on the GitHub project for Roslyn, since Microsoft changed the implementation of the automation code model (EnvDTE.Project.CodeModel, EnvDTE.ProjectItem.FileCodeModel) for Visual Studio 2015 to be based on the underlying .NET Compiler Platform (“Roslyn”).

EnvDTE.CodeElement.GetStartPoint(vsCMPartBody)/GetEndPoint(vsCMPartBody) throw COMException for expression-bodied methods and properties

This implementation change caused some bugs in Visual Studio 2015 betas that fortunately were fixed after I reported them, and some calls to GetStartPoint / GetEndPoint are not implemented as I reported two years ago:

EnvDTE.CodeElement.GetStartPoint(part)/GetEndPoint(part) not implemented for many parts

As a workaround for this bug, I assumed that the expression-bodied member expands to a single line, and I searched the string “=>” to find the start of the body.