Skip to content

Commit

Permalink
Fix warnings due to FormatterServices
Browse files Browse the repository at this point in the history
  • Loading branch information
hyazinthh committed Jun 19, 2024
1 parent 881eb28 commit f651a0e
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Aardvark.Base.FSharp/Reflection/TypeBuilder.fs
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,11 @@ module Serializer =
abstract member WriteRef : IWriter * 'a -> Coder<unit>

default x.CreateEmptyInstance() =
#if NET8_0_OR_GREATER
System.Runtime.CompilerServices.RuntimeHelpers.GetUninitializedObject(typeof<'a>) |> unbox<'a>
#else
System.Runtime.Serialization.FormatterServices.GetSafeUninitializedObject(typeof<'a>) |> unbox<'a>
#endif

override x.Read(r : IReader) =
code {
Expand Down Expand Up @@ -1056,7 +1060,11 @@ module Serializer =
module AutoCoder =
type Helpers() =
static member NewObj() : 'a =
#if NET8_0_OR_GREATER
System.Runtime.CompilerServices.RuntimeHelpers.GetUninitializedObject(typeof<'a>) |> unbox<'a>
#else
System.Runtime.Serialization.FormatterServices.GetSafeUninitializedObject(typeof<'a>) |> unbox<'a>
#endif

[<AbstractClass>]
type AbstractStateCoder<'a>() =
Expand Down Expand Up @@ -1662,7 +1670,11 @@ module Serializer =
| Some v -> return v
| None ->
do! Coder.pushName "ReferenceValue"
#if NET8_0_OR_GREATER
let res = System.Runtime.CompilerServices.RuntimeHelpers.GetUninitializedObject(typeof<'a>) |> unbox<'a>
#else
let res = System.Runtime.Serialization.FormatterServices.GetSafeUninitializedObject typeof<'a> |> unbox<'a>
#endif
do! Coder.storeValue id res

let! result = inner.Read(r)
Expand Down Expand Up @@ -1703,7 +1715,11 @@ module Serializer =
| Some v -> return v
| None ->
do! Coder.pushName "ReferenceValue"
#if NET8_0_OR_GREATER
let res = System.Runtime.CompilerServices.RuntimeHelpers.GetUninitializedObject(typeof<'a>) |> unbox<'a>
#else
let res = System.Runtime.Serialization.FormatterServices.GetSafeUninitializedObject typeof<'a> |> unbox<'a>
#endif
do! Coder.storeValue id res

let! result = inner.Read(r)
Expand Down

0 comments on commit f651a0e

Please sign in to comment.