Why does this code crash Visual Studio 2015?

C#Visual StudioVisual Studio-2015Roslyn

C# Problem Overview


For some reason, even so much as typing this into a C# file in Visual Studio is enough to cause it to instantly crash. Why?

unsafe struct node {
    node*[] child;
}

It seems to occur when the IDE would start coloring keywords and the like.

Trying it in TIO spits out csc.exe exited with code 1 which isn't very helpful.

While array declarations in C# are different than in C/C++, the above seems like it should be perfectly valid. Why isn't it, and why does it crash Visual Studio?

My Visual Studio version is 14.0.23107.

C# Solutions


Solution 1 - C#

This is a known bug in Roslyn. This bug will affect any version of Visual Studio that uses Roslyn.

If I am interpreting VersionOf.net correctly, the first version of Visual Studio with Roslyn built-in is 2015. Before then, I think it was available only as an extension. So, Visual Studio 2013 and prior should be unaffected.

It's due to be fixed in the milestone 16 release. At this time, that release is not scheduled.

Because this is a bug in Roslyn, you can "get around" it by editing and compiling the code containing the unsafe struct in an older version of Visual Studio, one that predates Roslyn. Visual Studio 2012 should work. You can then use the resultant .DLL in your current software.

An unverified fix is available if you build Roslyn yourself from this branch. The fix was made in this commit.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionOrionView Question on Stackoverflow
Solution 1 - C#user47589View Answer on Stackoverflow