Why does this code crash Visual Studio 2015?

  • A+
Category:Languages

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.

 


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.

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: