Hello All!
Here is a build matching our 5.4.0p4 patch release with the upgraded C# compiler included:
http://bit.ly/2cJtbaz
All of the notes below are exactly the same as the previous preview release based on 5.3.x that was posted here.
Please backup your project before trying this build.
Please post any issues you have to this forum.
The upgraded Mono C# compiler (corresponding to Mono 4.4) will be used to compile all your C# scripts.
Important Notes
-
The Mono runtime we use in our Editor and Players has not been upgraded.
-
The compiler still targets the C# 4 language. This is approximately what our old compiler supported.
-
The compiler still target the .Net 3.5 framework profile we previously supported.
This is the first step towards the mythical āMono/.Net Upgradeā.
FAQ
How will this affect me?
This upgrade should ājust workā; it does not expose any new features. It should not affect how you work today, other than a few benefits. The new Mono and C# compiler generally runs faster and has many years of bug fixes compared to our previous compiler.
What should I be testing/looking for?
In theory it could cause weird behavior at runtime. However, we have not seen that in any of our testing.
Most likely you will see an issue at compile time. So far, we have seen this if:
- you have invalid C# that the old compiler allowed and the new compiler properly errors on
- your code or a plugin assumes something specific about the compiler (install location, name, etc) and errors
One more thing, if you regularly debug C# using MonoDevelop or VSTU it would be good to hear any issues you encounter. The compiler output should be compatible, but the debugger may be sensitive to some generated code patterns.
Are there any breaking changes?
Yes, there is one known breaking change. The new compiler has a change to how a closure captures the foreach variable. This was a breaking change the C# language team made. This means that the following snippet of code will now print āb a rā rather than the current ār r rā.
var actions = new Action[3];
var j = 0;
foreach (var c in "bar")
actions[j++] = () => Console.WriteLine(c);
foreach (var a in actions)
a();
This is the behavior you would get using a modern version of VS or Mono, and is the behavior our current WSA platform exhibits.
Details here: Visual C# Breaking Changes in Visual Studio 2012 | Microsoft Learn
Does this fix the āforeachā allocates issue?
Yes, under certain circumstances. See an explanation of the issue .net - Memory allocation when using foreach loops in C# - Stack Overflow.
tl;dr; this generally means that doing āforeachā over an Array, List, Dictionary, or HashSet should not allocate.
Why donāt we target C# 5 or C# 6?
As a first step, we are just rolling out the new compiler. We may enable newer C# features in the future.
A few issues with supporting newer C#
-
Our ecosystem does not completely handle newer C# yet (script updater, debugger, certain MonoDevelop/VisualStudio versions)
-
We are still targeting the old 3.5 .Net profile. Itās somewhat confusing to support newer C# while still targeting an older framework. Writing code from scratch may work, but any existing code probably needs both new C# and new framework.