I opened our solution in Visual Studio 2015 yesterday and a few of our unit tests (which ran fine in Visual Studio 2013) starting failing. Digger deeper I discovered it was because calling GetTypes()
on an assembly was returning different results. I've been able to create a very simple test case to illustrate it.
In both Visual Studio 2013 and 2015 I created a new console application using .NET Framework 4.5.2. I put the following code in both projects.
class Program
{
static void Main(string[] args)
{
var types = typeof(Program).Assembly.GetTypes()
.Where(t => !t.IsAbstract && t.IsClass);
foreach (var type in types)
{
Console.WriteLine(type.FullName);
}
Console.ReadKey();
}
}
When I run in Visual Studio 2013 I get the following output (as expected).
VS2013Example.Program
When I run in Visual Studio 2015 I get the following output (not as expected).
VS2015Example.Program
VS2015Example.Program+<>c
So what is that VS2015Example.Program+<>c
type? Turns out it's the lambda inside the .Where()
method. Yes, that's right, somehow that local lambda is being exposed as a type. If I comment out the .Where()
in VS2015 then I no longer get that second line.
I've used Beyond Compare to compare the two .csproj files but the only differences are the VS version number, the project GUID, names of the default namespace and assembly, and the VS2015 one had a reference to System.Net.Http that the VS2013 one didn't.
Has anyone else seen this?
Does anyone have an explanation as to why a local variable would be being exposed as a type at the assembly level?