Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
Mono organizations on
GitHub to continue tracking issues. Bugzilla will remain
available for reference in read-only mode. We will continue to work
on open Bugzilla bugs, copy them to the new locations
as needed for follow-up, and add the new items under Related
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.
Please create a new report on
GitHub or Developer Community with
your current version information, steps to reproduce, and relevant error
messages or log files if you are hitting an issue that looks similar to
this resolved bug and you do not yet see a matching new report.
Created attachment 5528 [details]
gzip + tar, with source codes of vb.net and c#, and compiled binary files
when using ThreadStaticAttribute with ValueType, ie, struct, the behavior is inconsistent between mono-sgen and mono / .net.
briefly when using mono-sgen, the thread static value will be collected, while mono w/ boehm does not have the issue, and same as in .net. both c# and vb.net have the same issue.
following both vb.net and c# source code to trigger the issue.
vb.net, use compiling command as vbc /removeintchecks threadstaticvaluetype.vb
Public Module Main
Private Structure vt
Public v() As Int32
Public Sub init()
If v Is Nothing Then
<ThreadStatic> Private vto As vt
Public Sub Main()
For i As Int32 = 0 To 127
Dim v As Int32 = 0
Dim t As Int32 = 0
If t Mod 10000 = 0 Then
v = CInt(Rnd() * 100000)
vto.v(0) = v
If vto.v Is Nothing OrElse vto.v.Length() = 0 OrElse vto.v(0) <> v Then
t += 1
c#, use compiling command as csc /out:threadstaticvaluetype.cs.exe threadstaticvaluetype.cs
public static class program
private struct vt
public int v;
public void init()
if(v == null)
v = new int;
[ThreadStatic()] private static vt vto;
public static void Main()
for(int i = 0; i < 128; i++)
int v = 0;
int t = 0;
Random r = new Random();
if(t % 10000 == 0)
v = r.Next();
vto.v = v;
if(vto.v == null || vto.v.Length == 0 || vto.v != v)
i am using .net 3.5 in my machine, but i trust the behavior is consistent between different .net versions.
and the binary files are attached, threadstaticvaluetype.exe is for vb.net version, threadstaticvaluetype.cs.exe is for c# version.
What mono version is this ? This is probably fixed by:
which is not yet in any released mono version.
thank you for your update.