Created attachment 13890 [details]
The project.json file that is needed to run the program with dnx.
When using "stackalloc char[bufferSize]" and then passing bufferSize into another function, the Mono runtime will clear/zero out the bufferSize variable. This can be demonstrated with the following code:
public class Program
public unsafe static void Main(string args)
Program p = new Program();
string typeName = typeof(Program).Name;
int bufferSize = 45;
fixed (char* value = typeName)
char* buffer = stackalloc char[bufferSize];
p.EncodeIntoBuffer(value, typeName.Length, buffer, bufferSize);
private unsafe void EncodeIntoBuffer(char* value, int valueLength, char* buffer, int bufferLength)
Console.WriteLine("bufferLength is " + bufferLength);
I expect to get output that says "bufferLength is 45" which is what I get when running on the coreclr, but instead on the Mono runtime I get "bufferLength is 0".
I am using Mono version 188.8.131.52 on a MacBook Pro OS X El Capitan.
I am using 'dnx run' to run the program, not mcs/mono. (Although, the code doesn't work on mcs/mono either - I am getting an unexpected NullReferenceException when running it through mcs/mono.)
To set up a repro:
1. Install Mono on the Mac.
2. Install the ASP.NET 5 RC from http://get.asp.net
3. In a terminal, make sure you are using the mono runtime by running: dnvm use 1.0.0-rc1-final -r mono
4. Copy the attached project.json file into a folder. Also add the above code into the same folder, giving the file the name Program.cs.
5. In a terminal, navigate to the folder with Program.cs and project.json.
6. dnu restore
7. dnx run
Note: This bug was found through investigating the following higher-level issues:
Created attachment 13891 [details]
The C# code file that demonstrates the bug.
Fixed in mono master 27432be3ec4c65ba618b18389561b57e2b2716cb. Thanks for the report.
Notice (2018-05-21): bugzilla.xamarin.com will be
switching to read-only mode on Thursday, 2018-05-25 22:00 UTC.
Please join us on
Visual Studio Developer Community and
GitHub to continue tracking
issues. Bugzilla will remain available for reference in read-only mode.
We will continue to work on open Bugzilla bugs and copy them to the new
locations as needed for follow-up. The See Also field
on each Bugzilla bug will be updated with a link to its new location
After Bugzilla is read-only, if you have new information to add for a
bug that does not yet have a matching issue on Developer Community or
GitHub, you can create a follow-up issue in the new location. Copy and
paste the title and description from this bug, and then add your new
details. You can get a pre-formatted version of the title and
In special cases you might also want the comments:
Our sincere thanks to everyone who has contributed on this bug tracker
over the years. Thanks also for your understanding as we make these
adjustments and improvements for the future.