Skip to content

Commit 12775c7

Browse files
committed
Fixed AOT compatibility
1 parent 73edce0 commit 12775c7

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/DotNext/Runtime/BoxedValue.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,25 @@ namespace DotNext.Runtime;
2424
public class BoxedValue<T> // do not add any interfaces or base types
2525
where T : struct
2626
{
27+
private T value;
28+
29+
static BoxedValue()
30+
{
31+
// AOT: instantiate the class to make instance members visible to AOT
32+
var boxed = new BoxedValue<T>();
33+
GC.KeepAlive(boxed);
34+
}
35+
2736
[ExcludeFromCodeCoverage]
28-
private BoxedValue() => throw new NotImplementedException();
37+
private BoxedValue()
38+
{
39+
}
2940

3041
/// <summary>
3142
/// Gets a reference to the boxed value.
3243
/// </summary>
3344
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
34-
public ref T Value => ref Unsafe.Unbox<T>(this);
45+
public ref T Value => ref value;
3546

3647
/// <summary>
3748
/// Converts untyped reference to a boxed value into a typed reference.

0 commit comments

Comments
 (0)