From 4b0a72ee683904b88d5bb225887ee5e79c21d288 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Fri, 20 Feb 2026 16:09:43 +0100 Subject: [PATCH 1/7] Fix F# exception serialization to preserve fields Fixes #878 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../.FSharp.Compiler.Service/10.0.300.md | 2 + src/Compiler/CodeGen/IlxGen.fs | 102 +++++++++++++- .../CodeGenRegressions_Exceptions.fs | 107 ++++++++++++++ .../Nullness/ExceptionType.fs.il.netcore.bsl | 132 +++++++++++++++++- ...nternalSignatureOff.il.netcore.release.bsl | 61 +++++++- ...InternalSignatureOn.il.netcore.release.bsl | 61 +++++++- ...nternalSignatureOff.il.netcore.release.bsl | 91 +++++++++++- ...InternalSignatureOn.il.netcore.release.bsl | 91 +++++++++++- .../FSharp.Compiler.ComponentTests.fsproj | 1 + 9 files changed, 628 insertions(+), 20 deletions(-) create mode 100644 tests/FSharp.Compiler.ComponentTests/EmittedIL/CodeGenRegressions/CodeGenRegressions_Exceptions.fs diff --git a/docs/release-notes/.FSharp.Compiler.Service/10.0.300.md b/docs/release-notes/.FSharp.Compiler.Service/10.0.300.md index ca425fb63c4..18344c57f42 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/10.0.300.md +++ b/docs/release-notes/.FSharp.Compiler.Service/10.0.300.md @@ -32,4 +32,6 @@ * Symbols: safer qualified name getting ([PR #19298](https://github.com/dotnet/fsharp/pull/19298)) +* Fix F# exception serialization now preserves fields. (Issue [#878](https://github.com/dotnet/fsharp/issues/878), [PR #19342](https://github.com/dotnet/fsharp/pull/19342)) + ### Breaking Changes diff --git a/src/Compiler/CodeGen/IlxGen.fs b/src/Compiler/CodeGen/IlxGen.fs index 1e2f26b011e..f044922c66c 100644 --- a/src/Compiler/CodeGen/IlxGen.fs +++ b/src/Compiler/CodeGen/IlxGen.fs @@ -11908,6 +11908,49 @@ and GenExnDef cenv mgbuf eenv m (exnc: Tycon) : ILTypeRef option = match g.iltyp_SerializationInfo, g.iltyp_StreamingContext with | Some serializationInfoType, Some streamingContextType -> + let emitSerializationFieldIL emitPerField = + [ + for (ilPropName, ilFieldName, ilPropType, _) in fieldNamesAndTypes do + yield! emitPerField ilPropName ilFieldName ilPropType + ] + + let isILValueType (ty: ILType) = + ty.IsNominal && ty.Boxity = ILBoxity.AsValue + + let ilInstrsToRestoreFields = + emitSerializationFieldIL (fun ilPropName ilFieldName ilPropType -> + [ + mkLdarg0 + mkLdarg 1us + I_ldstr ilPropName + I_ldtoken(ILToken.ILType ilPropType) + + mkNormalCall ( + mkILNonGenericStaticMethSpecInTy ( + g.ilg.typ_Type, + "GetTypeFromHandle", + [ g.iltyp_RuntimeTypeHandle ], + g.ilg.typ_Type + ) + ) + + mkNormalCallvirt ( + mkILNonGenericInstanceMethSpecInTy ( + serializationInfoType, + "GetValue", + [ g.ilg.typ_String; g.ilg.typ_Type ], + g.ilg.typ_Object + ) + ) + + if isILValueType ilPropType then + I_unbox_any ilPropType + else + I_castclass ilPropType + + mkNormalStfld (mkILFieldSpecInTy (ilThisTy, ilFieldName, ilPropType)) + ]) + let ilInstrsForSerialization = [ mkLdarg0 @@ -11915,6 +11958,10 @@ and GenExnDef cenv mgbuf eenv m (exnc: Tycon) : ILTypeRef option = mkLdarg 2us mkNormalCall (mkILCtorMethSpecForTy (g.iltyp_Exception, [ serializationInfoType; streamingContextType ])) ] + @ (if fieldNamesAndTypes.IsEmpty then + [] + else + ilInstrsToRestoreFields) |> nonBranchingInstrsToCode let ilCtorDefForSerialization = @@ -11927,7 +11974,60 @@ and GenExnDef cenv mgbuf eenv m (exnc: Tycon) : ILTypeRef option = mkMethodBody (false, [], 8, ilInstrsForSerialization, None, eenv.imports) ) - [ ilCtorDefForSerialization ] + let ilInstrsToSaveFields = + emitSerializationFieldIL (fun ilPropName ilFieldName ilPropType -> + [ + mkLdarg 1us + I_ldstr ilPropName + mkLdarg0 + mkNormalLdfld (mkILFieldSpecInTy (ilThisTy, ilFieldName, ilPropType)) + + if isILValueType ilPropType then + I_box ilPropType + + mkNormalCallvirt ( + mkILNonGenericInstanceMethSpecInTy ( + serializationInfoType, + "AddValue", + [ g.ilg.typ_String; g.ilg.typ_Object ], + ILType.Void + ) + ) + ]) + + let ilInstrsForGetObjectData = + [ + mkLdarg0 + mkLdarg 1us + mkLdarg 2us + mkNormalCall ( + mkILNonGenericInstanceMethSpecInTy ( + g.iltyp_Exception, + "GetObjectData", + [ serializationInfoType; streamingContextType ], + ILType.Void + ) + ) + ] + @ ilInstrsToSaveFields + |> nonBranchingInstrsToCode + + let ilGetObjectDataDef = + mkILNonGenericVirtualInstanceMethod ( + "GetObjectData", + ILMemberAccess.Public, + [ + mkILParamNamed ("info", serializationInfoType) + mkILParamNamed ("context", streamingContextType) + ], + mkILReturn ILType.Void, + mkMethodBody (false, [], 8, ilInstrsForGetObjectData, None, eenv.imports) + ) + + if fieldNamesAndTypes.IsEmpty then + [ ilCtorDefForSerialization ] + else + [ ilCtorDefForSerialization; ilGetObjectDataDef ] | _ -> [] let ilTypeName = tref.Name diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/CodeGenRegressions/CodeGenRegressions_Exceptions.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/CodeGenRegressions/CodeGenRegressions_Exceptions.fs new file mode 100644 index 00000000000..bccea2b9a5c --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/CodeGenRegressions/CodeGenRegressions_Exceptions.fs @@ -0,0 +1,107 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. + +namespace EmittedIL + +open Xunit +open FSharp.Test +open FSharp.Test.Compiler +open FSharp.Test.Utilities + +module CodeGenRegressions_Exceptions = + + let private getActualIL (result: CompilationResult) = + match result with + | CompilationResult.Success s -> + match s.OutputPath with + | Some p -> + let (_, _, actualIL) = ILChecker.verifyILAndReturnActual [] p [ "// dummy" ] + actualIL + | None -> failwith "No output path" + | _ -> failwith "Compilation failed" + + // https://github.com/dotnet/fsharp/issues/878 + [] + let ``Issue_878_ExceptionSerialization`` () = + let source = """ +module Test + +exception Foo of x:string * y:int +""" + let result = + FSharp source + |> asLibrary + |> compile + |> shouldSucceed + + result + |> verifyIL [ + ".method public strict virtual instance void GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo info, valuetype [runtime]System.Runtime.Serialization.StreamingContext context) cil managed" + "call instance void [runtime]System.Exception::GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo," + ".method family specialname rtspecialname instance void .ctor(class [runtime]System.Runtime.Serialization.SerializationInfo info, valuetype [runtime]System.Runtime.Serialization.StreamingContext context) cil managed" + ] + |> ignore + + let actualIL = getActualIL result + Assert.Contains("AddValue", actualIL) + + // https://github.com/dotnet/fsharp/issues/878 + + [] + let ``Issue_878_ExceptionSerialization_Roundtrip`` () = + let source = """ +module Test +open System +open System.Runtime.Serialization + +#nowarn "44" // Serialization types are obsolete but needed for testing ISerializable +#nowarn "67" + +exception Foo of x:string * y:int + +let roundtrip (e: Exception) = + let info = SerializationInfo(e.GetType(), FormatterConverter()) + let ctx = StreamingContext(StreamingContextStates.All) + e.GetObjectData(info, ctx) + let ctor = + e.GetType().GetConstructor( + System.Reflection.BindingFlags.Instance ||| System.Reflection.BindingFlags.NonPublic ||| System.Reflection.BindingFlags.Public, + null, + [| typeof; typeof |], + null) + if ctor = null then failwith "Deserialization constructor not found" + ctor.Invoke([| info :> obj; ctx :> obj |]) :?> Exception + +[] +let main _ = + let original = Foo("value", 42) + // Check GetObjectData actually writes our fields + let info = SerializationInfo(original.GetType(), FormatterConverter()) + let ctx = StreamingContext(StreamingContextStates.All) + original.GetObjectData(info, ctx) + let xVal = info.GetString("x") + let yVal = info.GetInt32("y") + if xVal <> "value" then failwithf "GetObjectData: Expected x='value', got '%s'" xVal + if yVal <> 42 then failwithf "GetObjectData: Expected y=42, got %d" yVal + + // Check full roundtrip + let cloned = roundtrip original + // Access fields via internal backing fields using reflection + let xField = cloned.GetType().GetField("x@", System.Reflection.BindingFlags.Instance ||| System.Reflection.BindingFlags.NonPublic) + let yField = cloned.GetType().GetField("y@", System.Reflection.BindingFlags.Instance ||| System.Reflection.BindingFlags.NonPublic) + if xField = null then failwith "Field x@ not found" + if yField = null then failwith "Field y@ not found" + let xCloned = xField.GetValue(cloned) :?> string + let yCloned = yField.GetValue(cloned) :?> int + if xCloned <> "value" then failwithf "Roundtrip: Expected x='value', got '%s'" xCloned + if yCloned <> 42 then failwithf "Roundtrip: Expected y=42, got %d" yCloned + printfn "SUCCESS: Foo(value, 42) roundtripped correctly" + 0 +""" + FSharp source + |> asExe + |> ignoreWarnings + |> compile + |> shouldSucceed + |> run + |> shouldSucceed + |> ignore diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/ExceptionType.fs.il.netcore.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/ExceptionType.fs.il.netcore.bsl index 2a8a0c50d27..f2e6ff73712 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/ExceptionType.fs.il.netcore.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/ExceptionType.fs.il.netcore.bsl @@ -62,7 +62,34 @@ IL_0002: ldarg.2 IL_0003: call instance void [runtime]System.Exception::.ctor(class [runtime]System.Runtime.Serialization.SerializationInfo, valuetype [runtime]System.Runtime.Serialization.StreamingContext) - IL_0008: ret + IL_0008: ldarg.0 + IL_0009: ldarg.1 + IL_000a: ldstr "Data0" + IL_000f: ldtoken [runtime]System.String + IL_0014: call class [runtime]System.Type [runtime]System.Type::GetTypeFromHandle(valuetype [runtime]System.RuntimeTypeHandle) + IL_0019: callvirt instance object [runtime]System.Runtime.Serialization.SerializationInfo::GetValue(string, + class [runtime]System.Type) + IL_001e: castclass [runtime]System.String + IL_0023: stfld string MyLibrary/JustStringE::Data0@ + IL_0028: ret + } + + .method public strict virtual instance void GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo info, valuetype [runtime]System.Runtime.Serialization.StreamingContext context) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: ldarg.2 + IL_0003: call instance void [runtime]System.Exception::GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo, + valuetype [runtime]System.Runtime.Serialization.StreamingContext) + IL_0008: ldarg.1 + IL_0009: ldstr "Data0" + IL_000e: ldarg.0 + IL_000f: ldfld string MyLibrary/JustStringE::Data0@ + IL_0014: callvirt instance void [runtime]System.Runtime.Serialization.SerializationInfo::AddValue(string, + object) + IL_0019: ret } .method public hidebysig specialname instance string get_Data0() cil managed @@ -137,7 +164,49 @@ IL_0002: ldarg.2 IL_0003: call instance void [runtime]System.Exception::.ctor(class [runtime]System.Runtime.Serialization.SerializationInfo, valuetype [runtime]System.Runtime.Serialization.StreamingContext) - IL_0008: ret + IL_0008: ldarg.0 + IL_0009: ldarg.1 + IL_000a: ldstr "M1" + IL_000f: ldtoken [runtime]System.String + IL_0014: call class [runtime]System.Type [runtime]System.Type::GetTypeFromHandle(valuetype [runtime]System.RuntimeTypeHandle) + IL_0019: callvirt instance object [runtime]System.Runtime.Serialization.SerializationInfo::GetValue(string, + class [runtime]System.Type) + IL_001e: castclass [runtime]System.String + IL_0023: stfld string MyLibrary/TwoStrings::M1@ + IL_0028: ldarg.0 + IL_0029: ldarg.1 + IL_002a: ldstr "M2" + IL_002f: ldtoken [runtime]System.String + IL_0034: call class [runtime]System.Type [runtime]System.Type::GetTypeFromHandle(valuetype [runtime]System.RuntimeTypeHandle) + IL_0039: callvirt instance object [runtime]System.Runtime.Serialization.SerializationInfo::GetValue(string, + class [runtime]System.Type) + IL_003e: castclass [runtime]System.String + IL_0043: stfld string MyLibrary/TwoStrings::M2@ + IL_0048: ret + } + + .method public strict virtual instance void GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo info, valuetype [runtime]System.Runtime.Serialization.StreamingContext context) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: ldarg.2 + IL_0003: call instance void [runtime]System.Exception::GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo, + valuetype [runtime]System.Runtime.Serialization.StreamingContext) + IL_0008: ldarg.1 + IL_0009: ldstr "M1" + IL_000e: ldarg.0 + IL_000f: ldfld string MyLibrary/TwoStrings::M1@ + IL_0014: callvirt instance void [runtime]System.Runtime.Serialization.SerializationInfo::AddValue(string, + object) + IL_0019: ldarg.1 + IL_001a: ldstr "M2" + IL_001f: ldarg.0 + IL_0020: ldfld string MyLibrary/TwoStrings::M2@ + IL_0025: callvirt instance void [runtime]System.Runtime.Serialization.SerializationInfo::AddValue(string, + object) + IL_002a: ret } .method public hidebysig specialname instance string get_M1() cil managed @@ -226,7 +295,34 @@ IL_0002: ldarg.2 IL_0003: call instance void [runtime]System.Exception::.ctor(class [runtime]System.Runtime.Serialization.SerializationInfo, valuetype [runtime]System.Runtime.Serialization.StreamingContext) - IL_0008: ret + IL_0008: ldarg.0 + IL_0009: ldarg.1 + IL_000a: ldstr "Data0" + IL_000f: ldtoken [runtime]System.String + IL_0014: call class [runtime]System.Type [runtime]System.Type::GetTypeFromHandle(valuetype [runtime]System.RuntimeTypeHandle) + IL_0019: callvirt instance object [runtime]System.Runtime.Serialization.SerializationInfo::GetValue(string, + class [runtime]System.Type) + IL_001e: castclass [runtime]System.String + IL_0023: stfld string MyLibrary/NullableStringE::Data0@ + IL_0028: ret + } + + .method public strict virtual instance void GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo info, valuetype [runtime]System.Runtime.Serialization.StreamingContext context) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: ldarg.2 + IL_0003: call instance void [runtime]System.Exception::GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo, + valuetype [runtime]System.Runtime.Serialization.StreamingContext) + IL_0008: ldarg.1 + IL_0009: ldstr "Data0" + IL_000e: ldarg.0 + IL_000f: ldfld string MyLibrary/NullableStringE::Data0@ + IL_0014: callvirt instance void [runtime]System.Runtime.Serialization.SerializationInfo::AddValue(string, + object) + IL_0019: ret } .method public hidebysig specialname instance string get_Data0() cil managed @@ -300,7 +396,34 @@ IL_0002: ldarg.2 IL_0003: call instance void [runtime]System.Exception::.ctor(class [runtime]System.Runtime.Serialization.SerializationInfo, valuetype [runtime]System.Runtime.Serialization.StreamingContext) - IL_0008: ret + IL_0008: ldarg.0 + IL_0009: ldarg.1 + IL_000a: ldstr "Message" + IL_000f: ldtoken [runtime]System.String + IL_0014: call class [runtime]System.Type [runtime]System.Type::GetTypeFromHandle(valuetype [runtime]System.RuntimeTypeHandle) + IL_0019: callvirt instance object [runtime]System.Runtime.Serialization.SerializationInfo::GetValue(string, + class [runtime]System.Type) + IL_001e: castclass [runtime]System.String + IL_0023: stfld string MyLibrary/NullableMessage::Message@ + IL_0028: ret + } + + .method public strict virtual instance void GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo info, valuetype [runtime]System.Runtime.Serialization.StreamingContext context) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: ldarg.2 + IL_0003: call instance void [runtime]System.Exception::GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo, + valuetype [runtime]System.Runtime.Serialization.StreamingContext) + IL_0008: ldarg.1 + IL_0009: ldstr "Message" + IL_000e: ldarg.0 + IL_000f: ldfld string MyLibrary/NullableMessage::Message@ + IL_0014: callvirt instance void [runtime]System.Runtime.Serialization.SerializationInfo::AddValue(string, + object) + IL_0019: ret } .method public hidebysig specialname virtual instance string get_Message() cil managed @@ -334,4 +457,3 @@ - diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/SerializableAttribute/ToplevelModule.fs.RealInternalSignatureOff.il.netcore.release.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/SerializableAttribute/ToplevelModule.fs.RealInternalSignatureOff.il.netcore.release.bsl index 9c163b8ec4e..50410ebe0e5 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/SerializableAttribute/ToplevelModule.fs.RealInternalSignatureOff.il.netcore.release.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/SerializableAttribute/ToplevelModule.fs.RealInternalSignatureOff.il.netcore.release.bsl @@ -480,7 +480,35 @@ IL_0002: ldarg.2 IL_0003: call instance void [runtime]System.Exception::.ctor(class [runtime]System.Runtime.Serialization.SerializationInfo, valuetype [runtime]System.Runtime.Serialization.StreamingContext) - IL_0008: ret + IL_0008: ldarg.0 + IL_0009: ldarg.1 + IL_000a: ldstr "Data0" + IL_000f: ldtoken [runtime]System.Int32 + IL_0014: call class [runtime]System.Type [runtime]System.Type::GetTypeFromHandle(valuetype [runtime]System.RuntimeTypeHandle) + IL_0019: callvirt instance object [runtime]System.Runtime.Serialization.SerializationInfo::GetValue(string, + class [runtime]System.Type) + IL_001e: unbox.any [runtime]System.Int32 + IL_0023: stfld int32 ABC/MyExn::Data0@ + IL_0028: ret + } + + .method public strict virtual instance void GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo info, valuetype [runtime]System.Runtime.Serialization.StreamingContext context) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: ldarg.2 + IL_0003: call instance void [runtime]System.Exception::GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo, + valuetype [runtime]System.Runtime.Serialization.StreamingContext) + IL_0008: ldarg.1 + IL_0009: ldstr "Data0" + IL_000e: ldarg.0 + IL_000f: ldfld int32 ABC/MyExn::Data0@ + IL_0014: box [runtime]System.Int32 + IL_0019: callvirt instance void [runtime]System.Runtime.Serialization.SerializationInfo::AddValue(string, + object) + IL_001e: ret } .method public hidebysig specialname instance int32 get_Data0() cil managed @@ -1180,7 +1208,35 @@ IL_0002: ldarg.2 IL_0003: call instance void [runtime]System.Exception::.ctor(class [runtime]System.Runtime.Serialization.SerializationInfo, valuetype [runtime]System.Runtime.Serialization.StreamingContext) - IL_0008: ret + IL_0008: ldarg.0 + IL_0009: ldarg.1 + IL_000a: ldstr "Data0" + IL_000f: ldtoken [runtime]System.Int32 + IL_0014: call class [runtime]System.Type [runtime]System.Type::GetTypeFromHandle(valuetype [runtime]System.RuntimeTypeHandle) + IL_0019: callvirt instance object [runtime]System.Runtime.Serialization.SerializationInfo::GetValue(string, + class [runtime]System.Type) + IL_001e: unbox.any [runtime]System.Int32 + IL_0023: stfld int32 ABC/ABC/MyExn::Data0@ + IL_0028: ret + } + + .method public strict virtual instance void GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo info, valuetype [runtime]System.Runtime.Serialization.StreamingContext context) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: ldarg.2 + IL_0003: call instance void [runtime]System.Exception::GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo, + valuetype [runtime]System.Runtime.Serialization.StreamingContext) + IL_0008: ldarg.1 + IL_0009: ldstr "Data0" + IL_000e: ldarg.0 + IL_000f: ldfld int32 ABC/ABC/MyExn::Data0@ + IL_0014: box [runtime]System.Int32 + IL_0019: callvirt instance void [runtime]System.Runtime.Serialization.SerializationInfo::AddValue(string, + object) + IL_001e: ret } .method public hidebysig specialname instance int32 get_Data0() cil managed @@ -1512,4 +1568,3 @@ - diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/SerializableAttribute/ToplevelModule.fs.RealInternalSignatureOn.il.netcore.release.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/SerializableAttribute/ToplevelModule.fs.RealInternalSignatureOn.il.netcore.release.bsl index e9375f2d0f3..6adebd24f77 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/SerializableAttribute/ToplevelModule.fs.RealInternalSignatureOn.il.netcore.release.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/SerializableAttribute/ToplevelModule.fs.RealInternalSignatureOn.il.netcore.release.bsl @@ -480,7 +480,35 @@ IL_0002: ldarg.2 IL_0003: call instance void [runtime]System.Exception::.ctor(class [runtime]System.Runtime.Serialization.SerializationInfo, valuetype [runtime]System.Runtime.Serialization.StreamingContext) - IL_0008: ret + IL_0008: ldarg.0 + IL_0009: ldarg.1 + IL_000a: ldstr "Data0" + IL_000f: ldtoken [runtime]System.Int32 + IL_0014: call class [runtime]System.Type [runtime]System.Type::GetTypeFromHandle(valuetype [runtime]System.RuntimeTypeHandle) + IL_0019: callvirt instance object [runtime]System.Runtime.Serialization.SerializationInfo::GetValue(string, + class [runtime]System.Type) + IL_001e: unbox.any [runtime]System.Int32 + IL_0023: stfld int32 ABC/MyExn::Data0@ + IL_0028: ret + } + + .method public strict virtual instance void GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo info, valuetype [runtime]System.Runtime.Serialization.StreamingContext context) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: ldarg.2 + IL_0003: call instance void [runtime]System.Exception::GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo, + valuetype [runtime]System.Runtime.Serialization.StreamingContext) + IL_0008: ldarg.1 + IL_0009: ldstr "Data0" + IL_000e: ldarg.0 + IL_000f: ldfld int32 ABC/MyExn::Data0@ + IL_0014: box [runtime]System.Int32 + IL_0019: callvirt instance void [runtime]System.Runtime.Serialization.SerializationInfo::AddValue(string, + object) + IL_001e: ret } .method public hidebysig specialname instance int32 get_Data0() cil managed @@ -1180,7 +1208,35 @@ IL_0002: ldarg.2 IL_0003: call instance void [runtime]System.Exception::.ctor(class [runtime]System.Runtime.Serialization.SerializationInfo, valuetype [runtime]System.Runtime.Serialization.StreamingContext) - IL_0008: ret + IL_0008: ldarg.0 + IL_0009: ldarg.1 + IL_000a: ldstr "Data0" + IL_000f: ldtoken [runtime]System.Int32 + IL_0014: call class [runtime]System.Type [runtime]System.Type::GetTypeFromHandle(valuetype [runtime]System.RuntimeTypeHandle) + IL_0019: callvirt instance object [runtime]System.Runtime.Serialization.SerializationInfo::GetValue(string, + class [runtime]System.Type) + IL_001e: unbox.any [runtime]System.Int32 + IL_0023: stfld int32 ABC/ABC/MyExn::Data0@ + IL_0028: ret + } + + .method public strict virtual instance void GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo info, valuetype [runtime]System.Runtime.Serialization.StreamingContext context) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: ldarg.2 + IL_0003: call instance void [runtime]System.Exception::GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo, + valuetype [runtime]System.Runtime.Serialization.StreamingContext) + IL_0008: ldarg.1 + IL_0009: ldstr "Data0" + IL_000e: ldarg.0 + IL_000f: ldfld int32 ABC/ABC/MyExn::Data0@ + IL_0014: box [runtime]System.Int32 + IL_0019: callvirt instance void [runtime]System.Runtime.Serialization.SerializationInfo::AddValue(string, + object) + IL_001e: ret } .method public hidebysig specialname instance int32 get_Data0() cil managed @@ -1502,4 +1558,3 @@ - diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/SerializableAttribute/ToplevelNamespace.fs.RealInternalSignatureOff.il.netcore.release.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/SerializableAttribute/ToplevelNamespace.fs.RealInternalSignatureOff.il.netcore.release.bsl index 36d2089b286..f967c51988c 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/SerializableAttribute/ToplevelNamespace.fs.RealInternalSignatureOff.il.netcore.release.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/SerializableAttribute/ToplevelNamespace.fs.RealInternalSignatureOff.il.netcore.release.bsl @@ -476,7 +476,35 @@ IL_0002: ldarg.2 IL_0003: call instance void [runtime]System.Exception::.ctor(class [runtime]System.Runtime.Serialization.SerializationInfo, valuetype [runtime]System.Runtime.Serialization.StreamingContext) - IL_0008: ret + IL_0008: ldarg.0 + IL_0009: ldarg.1 + IL_000a: ldstr "Data0" + IL_000f: ldtoken [runtime]System.Int32 + IL_0014: call class [runtime]System.Type [runtime]System.Type::GetTypeFromHandle(valuetype [runtime]System.RuntimeTypeHandle) + IL_0019: callvirt instance object [runtime]System.Runtime.Serialization.SerializationInfo::GetValue(string, + class [runtime]System.Type) + IL_001e: unbox.any [runtime]System.Int32 + IL_0023: stfld int32 XYZ.MyExn::Data0@ + IL_0028: ret + } + + .method public strict virtual instance void GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo info, valuetype [runtime]System.Runtime.Serialization.StreamingContext context) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: ldarg.2 + IL_0003: call instance void [runtime]System.Exception::GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo, + valuetype [runtime]System.Runtime.Serialization.StreamingContext) + IL_0008: ldarg.1 + IL_0009: ldstr "Data0" + IL_000e: ldarg.0 + IL_000f: ldfld int32 XYZ.MyExn::Data0@ + IL_0014: box [runtime]System.Int32 + IL_0019: callvirt instance void [runtime]System.Runtime.Serialization.SerializationInfo::AddValue(string, + object) + IL_001e: ret } .method public hidebysig specialname instance int32 get_Data0() cil managed @@ -1176,7 +1204,35 @@ IL_0002: ldarg.2 IL_0003: call instance void [runtime]System.Exception::.ctor(class [runtime]System.Runtime.Serialization.SerializationInfo, valuetype [runtime]System.Runtime.Serialization.StreamingContext) - IL_0008: ret + IL_0008: ldarg.0 + IL_0009: ldarg.1 + IL_000a: ldstr "Data0" + IL_000f: ldtoken [runtime]System.Int32 + IL_0014: call class [runtime]System.Type [runtime]System.Type::GetTypeFromHandle(valuetype [runtime]System.RuntimeTypeHandle) + IL_0019: callvirt instance object [runtime]System.Runtime.Serialization.SerializationInfo::GetValue(string, + class [runtime]System.Type) + IL_001e: unbox.any [runtime]System.Int32 + IL_0023: stfld int32 XYZ.ABC/MyExn::Data0@ + IL_0028: ret + } + + .method public strict virtual instance void GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo info, valuetype [runtime]System.Runtime.Serialization.StreamingContext context) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: ldarg.2 + IL_0003: call instance void [runtime]System.Exception::GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo, + valuetype [runtime]System.Runtime.Serialization.StreamingContext) + IL_0008: ldarg.1 + IL_0009: ldstr "Data0" + IL_000e: ldarg.0 + IL_000f: ldfld int32 XYZ.ABC/MyExn::Data0@ + IL_0014: box [runtime]System.Int32 + IL_0019: callvirt instance void [runtime]System.Runtime.Serialization.SerializationInfo::AddValue(string, + object) + IL_001e: ret } .method public hidebysig specialname instance int32 get_Data0() cil managed @@ -1876,7 +1932,35 @@ IL_0002: ldarg.2 IL_0003: call instance void [runtime]System.Exception::.ctor(class [runtime]System.Runtime.Serialization.SerializationInfo, valuetype [runtime]System.Runtime.Serialization.StreamingContext) - IL_0008: ret + IL_0008: ldarg.0 + IL_0009: ldarg.1 + IL_000a: ldstr "Data0" + IL_000f: ldtoken [runtime]System.Int32 + IL_0014: call class [runtime]System.Type [runtime]System.Type::GetTypeFromHandle(valuetype [runtime]System.RuntimeTypeHandle) + IL_0019: callvirt instance object [runtime]System.Runtime.Serialization.SerializationInfo::GetValue(string, + class [runtime]System.Type) + IL_001e: unbox.any [runtime]System.Int32 + IL_0023: stfld int32 XYZ.ABC/ABC/MyExn::Data0@ + IL_0028: ret + } + + .method public strict virtual instance void GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo info, valuetype [runtime]System.Runtime.Serialization.StreamingContext context) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: ldarg.2 + IL_0003: call instance void [runtime]System.Exception::GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo, + valuetype [runtime]System.Runtime.Serialization.StreamingContext) + IL_0008: ldarg.1 + IL_0009: ldstr "Data0" + IL_000e: ldarg.0 + IL_000f: ldfld int32 XYZ.ABC/ABC/MyExn::Data0@ + IL_0014: box [runtime]System.Int32 + IL_0019: callvirt instance void [runtime]System.Runtime.Serialization.SerializationInfo::AddValue(string, + object) + IL_001e: ret } .method public hidebysig specialname instance int32 get_Data0() cil managed @@ -2208,4 +2292,3 @@ - diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/SerializableAttribute/ToplevelNamespace.fs.RealInternalSignatureOn.il.netcore.release.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/SerializableAttribute/ToplevelNamespace.fs.RealInternalSignatureOn.il.netcore.release.bsl index d166fc2f2ff..5b8492fbd4b 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/SerializableAttribute/ToplevelNamespace.fs.RealInternalSignatureOn.il.netcore.release.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/SerializableAttribute/ToplevelNamespace.fs.RealInternalSignatureOn.il.netcore.release.bsl @@ -476,7 +476,35 @@ IL_0002: ldarg.2 IL_0003: call instance void [runtime]System.Exception::.ctor(class [runtime]System.Runtime.Serialization.SerializationInfo, valuetype [runtime]System.Runtime.Serialization.StreamingContext) - IL_0008: ret + IL_0008: ldarg.0 + IL_0009: ldarg.1 + IL_000a: ldstr "Data0" + IL_000f: ldtoken [runtime]System.Int32 + IL_0014: call class [runtime]System.Type [runtime]System.Type::GetTypeFromHandle(valuetype [runtime]System.RuntimeTypeHandle) + IL_0019: callvirt instance object [runtime]System.Runtime.Serialization.SerializationInfo::GetValue(string, + class [runtime]System.Type) + IL_001e: unbox.any [runtime]System.Int32 + IL_0023: stfld int32 XYZ.MyExn::Data0@ + IL_0028: ret + } + + .method public strict virtual instance void GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo info, valuetype [runtime]System.Runtime.Serialization.StreamingContext context) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: ldarg.2 + IL_0003: call instance void [runtime]System.Exception::GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo, + valuetype [runtime]System.Runtime.Serialization.StreamingContext) + IL_0008: ldarg.1 + IL_0009: ldstr "Data0" + IL_000e: ldarg.0 + IL_000f: ldfld int32 XYZ.MyExn::Data0@ + IL_0014: box [runtime]System.Int32 + IL_0019: callvirt instance void [runtime]System.Runtime.Serialization.SerializationInfo::AddValue(string, + object) + IL_001e: ret } .method public hidebysig specialname instance int32 get_Data0() cil managed @@ -1176,7 +1204,35 @@ IL_0002: ldarg.2 IL_0003: call instance void [runtime]System.Exception::.ctor(class [runtime]System.Runtime.Serialization.SerializationInfo, valuetype [runtime]System.Runtime.Serialization.StreamingContext) - IL_0008: ret + IL_0008: ldarg.0 + IL_0009: ldarg.1 + IL_000a: ldstr "Data0" + IL_000f: ldtoken [runtime]System.Int32 + IL_0014: call class [runtime]System.Type [runtime]System.Type::GetTypeFromHandle(valuetype [runtime]System.RuntimeTypeHandle) + IL_0019: callvirt instance object [runtime]System.Runtime.Serialization.SerializationInfo::GetValue(string, + class [runtime]System.Type) + IL_001e: unbox.any [runtime]System.Int32 + IL_0023: stfld int32 XYZ.ABC/MyExn::Data0@ + IL_0028: ret + } + + .method public strict virtual instance void GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo info, valuetype [runtime]System.Runtime.Serialization.StreamingContext context) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: ldarg.2 + IL_0003: call instance void [runtime]System.Exception::GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo, + valuetype [runtime]System.Runtime.Serialization.StreamingContext) + IL_0008: ldarg.1 + IL_0009: ldstr "Data0" + IL_000e: ldarg.0 + IL_000f: ldfld int32 XYZ.ABC/MyExn::Data0@ + IL_0014: box [runtime]System.Int32 + IL_0019: callvirt instance void [runtime]System.Runtime.Serialization.SerializationInfo::AddValue(string, + object) + IL_001e: ret } .method public hidebysig specialname instance int32 get_Data0() cil managed @@ -1876,7 +1932,35 @@ IL_0002: ldarg.2 IL_0003: call instance void [runtime]System.Exception::.ctor(class [runtime]System.Runtime.Serialization.SerializationInfo, valuetype [runtime]System.Runtime.Serialization.StreamingContext) - IL_0008: ret + IL_0008: ldarg.0 + IL_0009: ldarg.1 + IL_000a: ldstr "Data0" + IL_000f: ldtoken [runtime]System.Int32 + IL_0014: call class [runtime]System.Type [runtime]System.Type::GetTypeFromHandle(valuetype [runtime]System.RuntimeTypeHandle) + IL_0019: callvirt instance object [runtime]System.Runtime.Serialization.SerializationInfo::GetValue(string, + class [runtime]System.Type) + IL_001e: unbox.any [runtime]System.Int32 + IL_0023: stfld int32 XYZ.ABC/ABC/MyExn::Data0@ + IL_0028: ret + } + + .method public strict virtual instance void GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo info, valuetype [runtime]System.Runtime.Serialization.StreamingContext context) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: ldarg.2 + IL_0003: call instance void [runtime]System.Exception::GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo, + valuetype [runtime]System.Runtime.Serialization.StreamingContext) + IL_0008: ldarg.1 + IL_0009: ldstr "Data0" + IL_000e: ldarg.0 + IL_000f: ldfld int32 XYZ.ABC/ABC/MyExn::Data0@ + IL_0014: box [runtime]System.Int32 + IL_0019: callvirt instance void [runtime]System.Runtime.Serialization.SerializationInfo::AddValue(string, + object) + IL_001e: ret } .method public hidebysig specialname instance int32 get_Data0() cil managed @@ -2198,4 +2282,3 @@ - diff --git a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj index fd02dace6e1..63cc7b7a1eb 100644 --- a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj +++ b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj @@ -280,6 +280,7 @@ + From cc19259c5eb99a7c8385042059affb5e6e05d088 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Thu, 26 Feb 2026 16:08:19 +0100 Subject: [PATCH 2/7] Fix GetObjectData override with SecurityCritical attribute The generated GetObjectData override on F# exception types must have the [SecurityCritical] attribute to match the security accessibility of Exception.GetObjectData on .NET Framework. Without this, the CLR rejects the override with 'Inheritance security rules violated', causing FS0193 errors when any project references FSharp.Core (which contains MatchFailureException with the new GetObjectData override). Also update IL baselines and FSharp.Core surface area baseline. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/Compiler/CodeGen/IlxGen.fs | 27 ++++++++++++------- .../CodeGenRegressions_Exceptions.fs | 1 + .../Nullness/ExceptionType.fs.il.netcore.bsl | 4 +++ ...nternalSignatureOff.il.netcore.release.bsl | 2 ++ ...InternalSignatureOn.il.netcore.release.bsl | 2 ++ ...nternalSignatureOff.il.netcore.release.bsl | 3 +++ ...InternalSignatureOn.il.netcore.release.bsl | 3 +++ ...Core.SurfaceArea.netstandard21.release.bsl | 1 + 8 files changed, 33 insertions(+), 10 deletions(-) diff --git a/src/Compiler/CodeGen/IlxGen.fs b/src/Compiler/CodeGen/IlxGen.fs index f044922c66c..6691d63a7d1 100644 --- a/src/Compiler/CodeGen/IlxGen.fs +++ b/src/Compiler/CodeGen/IlxGen.fs @@ -12013,16 +12013,23 @@ and GenExnDef cenv mgbuf eenv m (exnc: Tycon) : ILTypeRef option = |> nonBranchingInstrsToCode let ilGetObjectDataDef = - mkILNonGenericVirtualInstanceMethod ( - "GetObjectData", - ILMemberAccess.Public, - [ - mkILParamNamed ("info", serializationInfoType) - mkILParamNamed ("context", streamingContextType) - ], - mkILReturn ILType.Void, - mkMethodBody (false, [], 8, ilInstrsForGetObjectData, None, eenv.imports) - ) + let mdef = + mkILNonGenericVirtualInstanceMethod ( + "GetObjectData", + ILMemberAccess.Public, + [ + mkILParamNamed ("info", serializationInfoType) + mkILParamNamed ("context", streamingContextType) + ], + mkILReturn ILType.Void, + mkMethodBody (false, [], 8, ilInstrsForGetObjectData, None, eenv.imports) + ) + + // SecurityCritical is required for .NET Framework where Exception.GetObjectData is security-critical + let securityCriticalAttr = + mkILCustomAttribute (g.attrib_SecurityCriticalAttribute.TypeRef, [], [], []) + + mdef.With(customAttrs = mkILCustomAttrs [ securityCriticalAttr ]) if fieldNamesAndTypes.IsEmpty then [ ilCtorDefForSerialization ] diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/CodeGenRegressions/CodeGenRegressions_Exceptions.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/CodeGenRegressions/CodeGenRegressions_Exceptions.fs index bccea2b9a5c..9ed85477320 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/CodeGenRegressions/CodeGenRegressions_Exceptions.fs +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/CodeGenRegressions/CodeGenRegressions_Exceptions.fs @@ -36,6 +36,7 @@ exception Foo of x:string * y:int result |> verifyIL [ ".method public strict virtual instance void GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo info, valuetype [runtime]System.Runtime.Serialization.StreamingContext context) cil managed" + ".custom instance void [runtime]System.Security.SecurityCriticalAttribute::.ctor() = ( 01 00 00 00 )" "call instance void [runtime]System.Exception::GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo," ".method family specialname rtspecialname instance void .ctor(class [runtime]System.Runtime.Serialization.SerializationInfo info, valuetype [runtime]System.Runtime.Serialization.StreamingContext context) cil managed" ] diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/ExceptionType.fs.il.netcore.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/ExceptionType.fs.il.netcore.bsl index f2e6ff73712..0ff3392e278 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/ExceptionType.fs.il.netcore.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/ExceptionType.fs.il.netcore.bsl @@ -76,6 +76,7 @@ .method public strict virtual instance void GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo info, valuetype [runtime]System.Runtime.Serialization.StreamingContext context) cil managed { + .custom instance void [runtime]System.Security.SecurityCriticalAttribute::.ctor() = ( 01 00 00 00 ) .maxstack 8 IL_0000: ldarg.0 @@ -187,6 +188,7 @@ .method public strict virtual instance void GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo info, valuetype [runtime]System.Runtime.Serialization.StreamingContext context) cil managed { + .custom instance void [runtime]System.Security.SecurityCriticalAttribute::.ctor() = ( 01 00 00 00 ) .maxstack 8 IL_0000: ldarg.0 @@ -309,6 +311,7 @@ .method public strict virtual instance void GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo info, valuetype [runtime]System.Runtime.Serialization.StreamingContext context) cil managed { + .custom instance void [runtime]System.Security.SecurityCriticalAttribute::.ctor() = ( 01 00 00 00 ) .maxstack 8 IL_0000: ldarg.0 @@ -410,6 +413,7 @@ .method public strict virtual instance void GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo info, valuetype [runtime]System.Runtime.Serialization.StreamingContext context) cil managed { + .custom instance void [runtime]System.Security.SecurityCriticalAttribute::.ctor() = ( 01 00 00 00 ) .maxstack 8 IL_0000: ldarg.0 diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/SerializableAttribute/ToplevelModule.fs.RealInternalSignatureOff.il.netcore.release.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/SerializableAttribute/ToplevelModule.fs.RealInternalSignatureOff.il.netcore.release.bsl index 50410ebe0e5..e230897b4ff 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/SerializableAttribute/ToplevelModule.fs.RealInternalSignatureOff.il.netcore.release.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/SerializableAttribute/ToplevelModule.fs.RealInternalSignatureOff.il.netcore.release.bsl @@ -494,6 +494,7 @@ .method public strict virtual instance void GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo info, valuetype [runtime]System.Runtime.Serialization.StreamingContext context) cil managed { + .custom instance void [runtime]System.Security.SecurityCriticalAttribute::.ctor() = ( 01 00 00 00 ) .maxstack 8 IL_0000: ldarg.0 @@ -1222,6 +1223,7 @@ .method public strict virtual instance void GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo info, valuetype [runtime]System.Runtime.Serialization.StreamingContext context) cil managed { + .custom instance void [runtime]System.Security.SecurityCriticalAttribute::.ctor() = ( 01 00 00 00 ) .maxstack 8 IL_0000: ldarg.0 diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/SerializableAttribute/ToplevelModule.fs.RealInternalSignatureOn.il.netcore.release.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/SerializableAttribute/ToplevelModule.fs.RealInternalSignatureOn.il.netcore.release.bsl index 6adebd24f77..a0129f45485 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/SerializableAttribute/ToplevelModule.fs.RealInternalSignatureOn.il.netcore.release.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/SerializableAttribute/ToplevelModule.fs.RealInternalSignatureOn.il.netcore.release.bsl @@ -494,6 +494,7 @@ .method public strict virtual instance void GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo info, valuetype [runtime]System.Runtime.Serialization.StreamingContext context) cil managed { + .custom instance void [runtime]System.Security.SecurityCriticalAttribute::.ctor() = ( 01 00 00 00 ) .maxstack 8 IL_0000: ldarg.0 @@ -1222,6 +1223,7 @@ .method public strict virtual instance void GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo info, valuetype [runtime]System.Runtime.Serialization.StreamingContext context) cil managed { + .custom instance void [runtime]System.Security.SecurityCriticalAttribute::.ctor() = ( 01 00 00 00 ) .maxstack 8 IL_0000: ldarg.0 diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/SerializableAttribute/ToplevelNamespace.fs.RealInternalSignatureOff.il.netcore.release.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/SerializableAttribute/ToplevelNamespace.fs.RealInternalSignatureOff.il.netcore.release.bsl index f967c51988c..6f4b9051b97 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/SerializableAttribute/ToplevelNamespace.fs.RealInternalSignatureOff.il.netcore.release.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/SerializableAttribute/ToplevelNamespace.fs.RealInternalSignatureOff.il.netcore.release.bsl @@ -490,6 +490,7 @@ .method public strict virtual instance void GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo info, valuetype [runtime]System.Runtime.Serialization.StreamingContext context) cil managed { + .custom instance void [runtime]System.Security.SecurityCriticalAttribute::.ctor() = ( 01 00 00 00 ) .maxstack 8 IL_0000: ldarg.0 @@ -1218,6 +1219,7 @@ .method public strict virtual instance void GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo info, valuetype [runtime]System.Runtime.Serialization.StreamingContext context) cil managed { + .custom instance void [runtime]System.Security.SecurityCriticalAttribute::.ctor() = ( 01 00 00 00 ) .maxstack 8 IL_0000: ldarg.0 @@ -1946,6 +1948,7 @@ .method public strict virtual instance void GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo info, valuetype [runtime]System.Runtime.Serialization.StreamingContext context) cil managed { + .custom instance void [runtime]System.Security.SecurityCriticalAttribute::.ctor() = ( 01 00 00 00 ) .maxstack 8 IL_0000: ldarg.0 diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/SerializableAttribute/ToplevelNamespace.fs.RealInternalSignatureOn.il.netcore.release.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/SerializableAttribute/ToplevelNamespace.fs.RealInternalSignatureOn.il.netcore.release.bsl index 5b8492fbd4b..172f68c93c9 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/SerializableAttribute/ToplevelNamespace.fs.RealInternalSignatureOn.il.netcore.release.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/SerializableAttribute/ToplevelNamespace.fs.RealInternalSignatureOn.il.netcore.release.bsl @@ -490,6 +490,7 @@ .method public strict virtual instance void GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo info, valuetype [runtime]System.Runtime.Serialization.StreamingContext context) cil managed { + .custom instance void [runtime]System.Security.SecurityCriticalAttribute::.ctor() = ( 01 00 00 00 ) .maxstack 8 IL_0000: ldarg.0 @@ -1218,6 +1219,7 @@ .method public strict virtual instance void GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo info, valuetype [runtime]System.Runtime.Serialization.StreamingContext context) cil managed { + .custom instance void [runtime]System.Security.SecurityCriticalAttribute::.ctor() = ( 01 00 00 00 ) .maxstack 8 IL_0000: ldarg.0 @@ -1946,6 +1948,7 @@ .method public strict virtual instance void GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo info, valuetype [runtime]System.Runtime.Serialization.StreamingContext context) cil managed { + .custom instance void [runtime]System.Security.SecurityCriticalAttribute::.ctor() = ( 01 00 00 00 ) .maxstack 8 IL_0000: ldarg.0 diff --git a/tests/FSharp.Core.UnitTests/FSharp.Core.SurfaceArea.netstandard21.release.bsl b/tests/FSharp.Core.UnitTests/FSharp.Core.SurfaceArea.netstandard21.release.bsl index 606217f9fc5..37b4aee6700 100644 --- a/tests/FSharp.Core.UnitTests/FSharp.Core.SurfaceArea.netstandard21.release.bsl +++ b/tests/FSharp.Core.UnitTests/FSharp.Core.SurfaceArea.netstandard21.release.bsl @@ -1640,6 +1640,7 @@ Microsoft.FSharp.Core.MatchFailureException: System.String get_Data0() Microsoft.FSharp.Core.MatchFailureException: System.String get_Message() Microsoft.FSharp.Core.MatchFailureException: Void .ctor() Microsoft.FSharp.Core.MatchFailureException: Void .ctor(System.String, Int32, Int32) +Microsoft.FSharp.Core.MatchFailureException: Void GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext) Microsoft.FSharp.Core.MeasureAnnotatedAbbreviationAttribute: Void .ctor() Microsoft.FSharp.Core.MeasureAttribute: Void .ctor() Microsoft.FSharp.Core.NoComparisonAttribute: Void .ctor() From 32178312c75876b04be8e0be261d87f77bf6679c Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Mon, 2 Mar 2026 14:08:07 +0100 Subject: [PATCH 3/7] Skip serialization members for FSharp.Core exceptions FSharp.Core has [assembly: SecurityTransparent] which makes all methods transparent. On .NET Framework, transparent methods cannot override SecurityCritical methods (Exception.GetObjectData) nor call SecurityCritical base constructors (Exception(SerializationInfo, StreamingContext)). Skip emitting serialization members for FSharp.Core exceptions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/Compiler/CodeGen/IlxGen.fs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Compiler/CodeGen/IlxGen.fs b/src/Compiler/CodeGen/IlxGen.fs index 6691d63a7d1..38b2ebf9410 100644 --- a/src/Compiler/CodeGen/IlxGen.fs +++ b/src/Compiler/CodeGen/IlxGen.fs @@ -12031,7 +12031,14 @@ and GenExnDef cenv mgbuf eenv m (exnc: Tycon) : ILTypeRef option = mdef.With(customAttrs = mkILCustomAttrs [ securityCriticalAttr ]) - if fieldNamesAndTypes.IsEmpty then + // FSharp.Core has [assembly: SecurityTransparent], so all methods are transparent. + // On .NET Framework, transparent methods cannot override SecurityCritical methods + // like Exception.GetObjectData, nor call SecurityCritical base constructors like + // Exception(SerializationInfo, StreamingContext). Skip serialization members entirely + // for FSharp.Core exceptions. + if g.compilingFSharpCore then + [] + elif fieldNamesAndTypes.IsEmpty then [ ilCtorDefForSerialization ] else [ ilCtorDefForSerialization; ilGetObjectDataDef ] From e63aa8cb53682eb020f2aa3d0c214527c5458356 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Mon, 2 Mar 2026 14:45:49 +0100 Subject: [PATCH 4/7] Refine FSharp.Core exception serialization: keep deserialization ctor, add test FSharp.Core has [assembly: SecurityTransparent]. On .NET Framework, transparent code cannot override SecurityCritical methods (GetObjectData). Without GetObjectData to write fields, the field-restoring ctor would crash. So for FSharp.Core exceptions: - Keep the base-call-only deserialization ctor (status quo, SecuritySafeCritical base) - Skip GetObjectData override (can't override SecurityCritical from transparent) For user exceptions (no SecurityTransparent): - Emit both GetObjectData and field-restoring ctor (full serialization) Add test verifying FSharp.Core MatchFailureException: - Loads without TypeLoadException - Has deserialization ctor - Does NOT have GetObjectData override Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/Compiler/CodeGen/IlxGen.fs | 32 ++++++++--- .../CodeGenRegressions_Exceptions.fs | 54 +++++++++++++++++++ 2 files changed, 80 insertions(+), 6 deletions(-) diff --git a/src/Compiler/CodeGen/IlxGen.fs b/src/Compiler/CodeGen/IlxGen.fs index 38b2ebf9410..5842ba19e58 100644 --- a/src/Compiler/CodeGen/IlxGen.fs +++ b/src/Compiler/CodeGen/IlxGen.fs @@ -12031,13 +12031,33 @@ and GenExnDef cenv mgbuf eenv m (exnc: Tycon) : ILTypeRef option = mdef.With(customAttrs = mkILCustomAttrs [ securityCriticalAttr ]) - // FSharp.Core has [assembly: SecurityTransparent], so all methods are transparent. - // On .NET Framework, transparent methods cannot override SecurityCritical methods - // like Exception.GetObjectData, nor call SecurityCritical base constructors like - // Exception(SerializationInfo, StreamingContext). Skip serialization members entirely - // for FSharp.Core exceptions. + // FSharp.Core has [assembly: SecurityTransparent], making all code transparent. + // On .NET Framework, transparent code cannot override SecurityCritical virtual + // methods like Exception.GetObjectData. Without GetObjectData to write the fields, + // the field-restoring deserialization constructor would crash (fields not in + // SerializationInfo). So for FSharp.Core: emit only the base-call ctor (status quo). + // For user exceptions: emit both GetObjectData and the field-restoring ctor. if g.compilingFSharpCore then - [] + let ilBaseOnlyCtorInstrs = + [ + mkLdarg0 + mkLdarg 1us + mkLdarg 2us + mkNormalCall (mkILCtorMethSpecForTy (g.iltyp_Exception, [ serializationInfoType; streamingContextType ])) + ] + |> nonBranchingInstrsToCode + + let ilBaseOnlyCtor = + mkILCtor ( + ILMemberAccess.Family, + [ + mkILParamNamed ("info", serializationInfoType) + mkILParamNamed ("context", streamingContextType) + ], + mkMethodBody (false, [], 8, ilBaseOnlyCtorInstrs, None, eenv.imports) + ) + + [ ilBaseOnlyCtor ] elif fieldNamesAndTypes.IsEmpty then [ ilCtorDefForSerialization ] else diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/CodeGenRegressions/CodeGenRegressions_Exceptions.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/CodeGenRegressions/CodeGenRegressions_Exceptions.fs index 9ed85477320..6e3c95e54fb 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/CodeGenRegressions/CodeGenRegressions_Exceptions.fs +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/CodeGenRegressions/CodeGenRegressions_Exceptions.fs @@ -97,6 +97,60 @@ let main _ = if yCloned <> 42 then failwithf "Roundtrip: Expected y=42, got %d" yCloned printfn "SUCCESS: Foo(value, 42) roundtripped correctly" 0 +""" + FSharp source + |> asExe + |> ignoreWarnings + |> compile + |> shouldSucceed + |> run + |> shouldSucceed + |> ignore + + // FSharp.Core has [assembly: SecurityTransparent] which prevents overriding + // SecurityCritical methods like Exception.GetObjectData on .NET Framework. + // Verify that FSharp.Core exceptions (MatchFailureException) still load and work, + // have the deserialization ctor, but do NOT have a GetObjectData override. + [] + let ``Issue_878_FSharpCoreExceptions_NoGetObjectDataOverride`` () = + let source = """ +module Test + +// Force MatchFailureException to be loaded by triggering an incomplete match +let triggerMatch x = + match x with + | 1 -> "one" + +// Verify FSharp.Core exceptions can be created and used without TypeLoadException +let test () = + try + triggerMatch 999 |> ignore + failwith "Expected MatchFailureException" + with + | :? MatchFailureException as e -> + // Verify the exception loaded successfully (no TypeLoadException from GetObjectData) + printfn "MatchFailureException loaded OK: %s" e.Message + + // Check that deserialization ctor exists (it should — base ctor is SecuritySafeCritical) + let ctorParams = [| typeof; typeof |] + let ctor = typeof.GetConstructor( + System.Reflection.BindingFlags.Instance ||| System.Reflection.BindingFlags.NonPublic, + null, ctorParams, null) + if ctor = null then failwith "Deserialization ctor missing on MatchFailureException" + printfn "Deserialization ctor present" + + // GetObjectData should NOT be overridden on MatchFailureException + // (FSharp.Core is SecurityTransparent, can't override SecurityCritical base) + let godMethod = typeof.GetMethod("GetObjectData", + System.Reflection.BindingFlags.Instance ||| System.Reflection.BindingFlags.Public, + null, ctorParams, null) + if godMethod <> null && godMethod.DeclaringType = typeof then + failwith "GetObjectData should NOT be overridden on FSharp.Core exceptions" + printfn "GetObjectData correctly not overridden" + 0 + +[] +let main _ = test () """ FSharp source |> asExe From d9af612899464979d3d913108a18862489100d8f Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Mon, 2 Mar 2026 15:48:50 +0100 Subject: [PATCH 5/7] Revert surface area baseline: no GetObjectData on FSharp.Core exceptions The compilingFSharpCore guard skips GetObjectData, so the surface area baseline should not include it for MatchFailureException. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../FSharp.Core.SurfaceArea.netstandard21.release.bsl | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/FSharp.Core.UnitTests/FSharp.Core.SurfaceArea.netstandard21.release.bsl b/tests/FSharp.Core.UnitTests/FSharp.Core.SurfaceArea.netstandard21.release.bsl index 37b4aee6700..606217f9fc5 100644 --- a/tests/FSharp.Core.UnitTests/FSharp.Core.SurfaceArea.netstandard21.release.bsl +++ b/tests/FSharp.Core.UnitTests/FSharp.Core.SurfaceArea.netstandard21.release.bsl @@ -1640,7 +1640,6 @@ Microsoft.FSharp.Core.MatchFailureException: System.String get_Data0() Microsoft.FSharp.Core.MatchFailureException: System.String get_Message() Microsoft.FSharp.Core.MatchFailureException: Void .ctor() Microsoft.FSharp.Core.MatchFailureException: Void .ctor(System.String, Int32, Int32) -Microsoft.FSharp.Core.MatchFailureException: Void GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext) Microsoft.FSharp.Core.MeasureAnnotatedAbbreviationAttribute: Void .ctor() Microsoft.FSharp.Core.MeasureAttribute: Void .ctor() Microsoft.FSharp.Core.NoComparisonAttribute: Void .ctor() From d81d201f5c0e9088da03a9ae8ffc35d568d026a6 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Fri, 6 Mar 2026 19:18:45 +0100 Subject: [PATCH 6/7] Move release notes to 11.0.100 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- docs/release-notes/.FSharp.Compiler.Service/10.0.300.md | 2 -- docs/release-notes/.FSharp.Compiler.Service/11.0.100.md | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/release-notes/.FSharp.Compiler.Service/10.0.300.md b/docs/release-notes/.FSharp.Compiler.Service/10.0.300.md index d1fd1cf24ff..057bf1d18a9 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/10.0.300.md +++ b/docs/release-notes/.FSharp.Compiler.Service/10.0.300.md @@ -42,6 +42,4 @@ * Symbols: safer qualified name getting ([PR #19298](https://github.com/dotnet/fsharp/pull/19298)) -* Fix F# exception serialization now preserves fields. (Issue [#878](https://github.com/dotnet/fsharp/issues/878), [PR #19342](https://github.com/dotnet/fsharp/pull/19342)) - ### Breaking Changes diff --git a/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md b/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md index da89cec27a2..469788d5f6c 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md +++ b/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md @@ -1,4 +1,5 @@ ### Fixed +* Fix F# exception serialization now preserves fields. (Issue [#878](https://github.com/dotnet/fsharp/issues/878), [PR #19342](https://github.com/dotnet/fsharp/pull/19342)) ### Added From cb3593342e645bb3af3e000d0a5a3655ae6fdc2b Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Fri, 6 Mar 2026 21:43:59 +0100 Subject: [PATCH 7/7] Update net472 EmittedIL baselines for exception serialization constructors Add deserialization constructor bodies (reading fields from SerializationInfo) and GetObjectData overrides to match the netcore baselines. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../Nullness/ExceptionType.fs.il.net472.bsl | 135 +++++++++++++++++- ...InternalSignatureOff.il.net472.release.bsl | 62 +++++++- ...lInternalSignatureOn.il.net472.release.bsl | 62 +++++++- ...InternalSignatureOff.il.net472.release.bsl | 93 +++++++++++- ...lInternalSignatureOn.il.net472.release.bsl | 93 +++++++++++- 5 files changed, 431 insertions(+), 14 deletions(-) diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/ExceptionType.fs.il.net472.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/ExceptionType.fs.il.net472.bsl index f2feb99321b..39d8616f94b 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/ExceptionType.fs.il.net472.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/ExceptionType.fs.il.net472.bsl @@ -62,7 +62,35 @@ IL_0002: ldarg.2 IL_0003: call instance void [runtime]System.Exception::.ctor(class [runtime]System.Runtime.Serialization.SerializationInfo, valuetype [runtime]System.Runtime.Serialization.StreamingContext) - IL_0008: ret + IL_0008: ldarg.0 + IL_0009: ldarg.1 + IL_000a: ldstr "Data0" + IL_000f: ldtoken [runtime]System.String + IL_0014: call class [runtime]System.Type [runtime]System.Type::GetTypeFromHandle(valuetype [runtime]System.RuntimeTypeHandle) + IL_0019: callvirt instance object [runtime]System.Runtime.Serialization.SerializationInfo::GetValue(string, + class [runtime]System.Type) + IL_001e: castclass [runtime]System.String + IL_0023: stfld string MyLibrary/JustStringE::Data0@ + IL_0028: ret + } + + .method public strict virtual instance void GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo info, valuetype [runtime]System.Runtime.Serialization.StreamingContext context) cil managed + { + .custom instance void [runtime]System.Security.SecurityCriticalAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: ldarg.2 + IL_0003: call instance void [runtime]System.Exception::GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo, + valuetype [runtime]System.Runtime.Serialization.StreamingContext) + IL_0008: ldarg.1 + IL_0009: ldstr "Data0" + IL_000e: ldarg.0 + IL_000f: ldfld string MyLibrary/JustStringE::Data0@ + IL_0014: callvirt instance void [runtime]System.Runtime.Serialization.SerializationInfo::AddValue(string, + object) + IL_0019: ret } .method public hidebysig specialname instance string get_Data0() cil managed @@ -137,7 +165,50 @@ IL_0002: ldarg.2 IL_0003: call instance void [runtime]System.Exception::.ctor(class [runtime]System.Runtime.Serialization.SerializationInfo, valuetype [runtime]System.Runtime.Serialization.StreamingContext) - IL_0008: ret + IL_0008: ldarg.0 + IL_0009: ldarg.1 + IL_000a: ldstr "M1" + IL_000f: ldtoken [runtime]System.String + IL_0014: call class [runtime]System.Type [runtime]System.Type::GetTypeFromHandle(valuetype [runtime]System.RuntimeTypeHandle) + IL_0019: callvirt instance object [runtime]System.Runtime.Serialization.SerializationInfo::GetValue(string, + class [runtime]System.Type) + IL_001e: castclass [runtime]System.String + IL_0023: stfld string MyLibrary/TwoStrings::M1@ + IL_0028: ldarg.0 + IL_0029: ldarg.1 + IL_002a: ldstr "M2" + IL_002f: ldtoken [runtime]System.String + IL_0034: call class [runtime]System.Type [runtime]System.Type::GetTypeFromHandle(valuetype [runtime]System.RuntimeTypeHandle) + IL_0039: callvirt instance object [runtime]System.Runtime.Serialization.SerializationInfo::GetValue(string, + class [runtime]System.Type) + IL_003e: castclass [runtime]System.String + IL_0043: stfld string MyLibrary/TwoStrings::M2@ + IL_0048: ret + } + + .method public strict virtual instance void GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo info, valuetype [runtime]System.Runtime.Serialization.StreamingContext context) cil managed + { + .custom instance void [runtime]System.Security.SecurityCriticalAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: ldarg.2 + IL_0003: call instance void [runtime]System.Exception::GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo, + valuetype [runtime]System.Runtime.Serialization.StreamingContext) + IL_0008: ldarg.1 + IL_0009: ldstr "M1" + IL_000e: ldarg.0 + IL_000f: ldfld string MyLibrary/TwoStrings::M1@ + IL_0014: callvirt instance void [runtime]System.Runtime.Serialization.SerializationInfo::AddValue(string, + object) + IL_0019: ldarg.1 + IL_001a: ldstr "M2" + IL_001f: ldarg.0 + IL_0020: ldfld string MyLibrary/TwoStrings::M2@ + IL_0025: callvirt instance void [runtime]System.Runtime.Serialization.SerializationInfo::AddValue(string, + object) + IL_002a: ret } .method public hidebysig specialname instance string get_M1() cil managed @@ -226,7 +297,35 @@ IL_0002: ldarg.2 IL_0003: call instance void [runtime]System.Exception::.ctor(class [runtime]System.Runtime.Serialization.SerializationInfo, valuetype [runtime]System.Runtime.Serialization.StreamingContext) - IL_0008: ret + IL_0008: ldarg.0 + IL_0009: ldarg.1 + IL_000a: ldstr "Data0" + IL_000f: ldtoken [runtime]System.String + IL_0014: call class [runtime]System.Type [runtime]System.Type::GetTypeFromHandle(valuetype [runtime]System.RuntimeTypeHandle) + IL_0019: callvirt instance object [runtime]System.Runtime.Serialization.SerializationInfo::GetValue(string, + class [runtime]System.Type) + IL_001e: castclass [runtime]System.String + IL_0023: stfld string MyLibrary/NullableStringE::Data0@ + IL_0028: ret + } + + .method public strict virtual instance void GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo info, valuetype [runtime]System.Runtime.Serialization.StreamingContext context) cil managed + { + .custom instance void [runtime]System.Security.SecurityCriticalAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: ldarg.2 + IL_0003: call instance void [runtime]System.Exception::GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo, + valuetype [runtime]System.Runtime.Serialization.StreamingContext) + IL_0008: ldarg.1 + IL_0009: ldstr "Data0" + IL_000e: ldarg.0 + IL_000f: ldfld string MyLibrary/NullableStringE::Data0@ + IL_0014: callvirt instance void [runtime]System.Runtime.Serialization.SerializationInfo::AddValue(string, + object) + IL_0019: ret } .method public hidebysig specialname instance string get_Data0() cil managed @@ -300,7 +399,35 @@ IL_0002: ldarg.2 IL_0003: call instance void [runtime]System.Exception::.ctor(class [runtime]System.Runtime.Serialization.SerializationInfo, valuetype [runtime]System.Runtime.Serialization.StreamingContext) - IL_0008: ret + IL_0008: ldarg.0 + IL_0009: ldarg.1 + IL_000a: ldstr "Message" + IL_000f: ldtoken [runtime]System.String + IL_0014: call class [runtime]System.Type [runtime]System.Type::GetTypeFromHandle(valuetype [runtime]System.RuntimeTypeHandle) + IL_0019: callvirt instance object [runtime]System.Runtime.Serialization.SerializationInfo::GetValue(string, + class [runtime]System.Type) + IL_001e: castclass [runtime]System.String + IL_0023: stfld string MyLibrary/NullableMessage::Message@ + IL_0028: ret + } + + .method public strict virtual instance void GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo info, valuetype [runtime]System.Runtime.Serialization.StreamingContext context) cil managed + { + .custom instance void [runtime]System.Security.SecurityCriticalAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: ldarg.2 + IL_0003: call instance void [runtime]System.Exception::GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo, + valuetype [runtime]System.Runtime.Serialization.StreamingContext) + IL_0008: ldarg.1 + IL_0009: ldstr "Message" + IL_000e: ldarg.0 + IL_000f: ldfld string MyLibrary/NullableMessage::Message@ + IL_0014: callvirt instance void [runtime]System.Runtime.Serialization.SerializationInfo::AddValue(string, + object) + IL_0019: ret } .method public hidebysig specialname virtual instance string get_Message() cil managed diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/SerializableAttribute/ToplevelModule.fs.RealInternalSignatureOff.il.net472.release.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/SerializableAttribute/ToplevelModule.fs.RealInternalSignatureOff.il.net472.release.bsl index bc1e702435d..3e50fbe8595 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/SerializableAttribute/ToplevelModule.fs.RealInternalSignatureOff.il.net472.release.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/SerializableAttribute/ToplevelModule.fs.RealInternalSignatureOff.il.net472.release.bsl @@ -480,7 +480,36 @@ IL_0002: ldarg.2 IL_0003: call instance void [runtime]System.Exception::.ctor(class [runtime]System.Runtime.Serialization.SerializationInfo, valuetype [runtime]System.Runtime.Serialization.StreamingContext) - IL_0008: ret + IL_0008: ldarg.0 + IL_0009: ldarg.1 + IL_000a: ldstr "Data0" + IL_000f: ldtoken [runtime]System.Int32 + IL_0014: call class [runtime]System.Type [runtime]System.Type::GetTypeFromHandle(valuetype [runtime]System.RuntimeTypeHandle) + IL_0019: callvirt instance object [runtime]System.Runtime.Serialization.SerializationInfo::GetValue(string, + class [runtime]System.Type) + IL_001e: unbox.any [runtime]System.Int32 + IL_0023: stfld int32 ABC/MyExn::Data0@ + IL_0028: ret + } + + .method public strict virtual instance void GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo info, valuetype [runtime]System.Runtime.Serialization.StreamingContext context) cil managed + { + .custom instance void [runtime]System.Security.SecurityCriticalAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: ldarg.2 + IL_0003: call instance void [runtime]System.Exception::GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo, + valuetype [runtime]System.Runtime.Serialization.StreamingContext) + IL_0008: ldarg.1 + IL_0009: ldstr "Data0" + IL_000e: ldarg.0 + IL_000f: ldfld int32 ABC/MyExn::Data0@ + IL_0014: box [runtime]System.Int32 + IL_0019: callvirt instance void [runtime]System.Runtime.Serialization.SerializationInfo::AddValue(string, + object) + IL_001e: ret } .method public hidebysig specialname instance int32 get_Data0() cil managed @@ -1180,7 +1209,36 @@ IL_0002: ldarg.2 IL_0003: call instance void [runtime]System.Exception::.ctor(class [runtime]System.Runtime.Serialization.SerializationInfo, valuetype [runtime]System.Runtime.Serialization.StreamingContext) - IL_0008: ret + IL_0008: ldarg.0 + IL_0009: ldarg.1 + IL_000a: ldstr "Data0" + IL_000f: ldtoken [runtime]System.Int32 + IL_0014: call class [runtime]System.Type [runtime]System.Type::GetTypeFromHandle(valuetype [runtime]System.RuntimeTypeHandle) + IL_0019: callvirt instance object [runtime]System.Runtime.Serialization.SerializationInfo::GetValue(string, + class [runtime]System.Type) + IL_001e: unbox.any [runtime]System.Int32 + IL_0023: stfld int32 ABC/ABC/MyExn::Data0@ + IL_0028: ret + } + + .method public strict virtual instance void GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo info, valuetype [runtime]System.Runtime.Serialization.StreamingContext context) cil managed + { + .custom instance void [runtime]System.Security.SecurityCriticalAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: ldarg.2 + IL_0003: call instance void [runtime]System.Exception::GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo, + valuetype [runtime]System.Runtime.Serialization.StreamingContext) + IL_0008: ldarg.1 + IL_0009: ldstr "Data0" + IL_000e: ldarg.0 + IL_000f: ldfld int32 ABC/ABC/MyExn::Data0@ + IL_0014: box [runtime]System.Int32 + IL_0019: callvirt instance void [runtime]System.Runtime.Serialization.SerializationInfo::AddValue(string, + object) + IL_001e: ret } .method public hidebysig specialname instance int32 get_Data0() cil managed diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/SerializableAttribute/ToplevelModule.fs.RealInternalSignatureOn.il.net472.release.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/SerializableAttribute/ToplevelModule.fs.RealInternalSignatureOn.il.net472.release.bsl index c2c806ca394..73f2fdc3aac 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/SerializableAttribute/ToplevelModule.fs.RealInternalSignatureOn.il.net472.release.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/SerializableAttribute/ToplevelModule.fs.RealInternalSignatureOn.il.net472.release.bsl @@ -480,7 +480,36 @@ IL_0002: ldarg.2 IL_0003: call instance void [runtime]System.Exception::.ctor(class [runtime]System.Runtime.Serialization.SerializationInfo, valuetype [runtime]System.Runtime.Serialization.StreamingContext) - IL_0008: ret + IL_0008: ldarg.0 + IL_0009: ldarg.1 + IL_000a: ldstr "Data0" + IL_000f: ldtoken [runtime]System.Int32 + IL_0014: call class [runtime]System.Type [runtime]System.Type::GetTypeFromHandle(valuetype [runtime]System.RuntimeTypeHandle) + IL_0019: callvirt instance object [runtime]System.Runtime.Serialization.SerializationInfo::GetValue(string, + class [runtime]System.Type) + IL_001e: unbox.any [runtime]System.Int32 + IL_0023: stfld int32 ABC/MyExn::Data0@ + IL_0028: ret + } + + .method public strict virtual instance void GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo info, valuetype [runtime]System.Runtime.Serialization.StreamingContext context) cil managed + { + .custom instance void [runtime]System.Security.SecurityCriticalAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: ldarg.2 + IL_0003: call instance void [runtime]System.Exception::GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo, + valuetype [runtime]System.Runtime.Serialization.StreamingContext) + IL_0008: ldarg.1 + IL_0009: ldstr "Data0" + IL_000e: ldarg.0 + IL_000f: ldfld int32 ABC/MyExn::Data0@ + IL_0014: box [runtime]System.Int32 + IL_0019: callvirt instance void [runtime]System.Runtime.Serialization.SerializationInfo::AddValue(string, + object) + IL_001e: ret } .method public hidebysig specialname instance int32 get_Data0() cil managed @@ -1180,7 +1209,36 @@ IL_0002: ldarg.2 IL_0003: call instance void [runtime]System.Exception::.ctor(class [runtime]System.Runtime.Serialization.SerializationInfo, valuetype [runtime]System.Runtime.Serialization.StreamingContext) - IL_0008: ret + IL_0008: ldarg.0 + IL_0009: ldarg.1 + IL_000a: ldstr "Data0" + IL_000f: ldtoken [runtime]System.Int32 + IL_0014: call class [runtime]System.Type [runtime]System.Type::GetTypeFromHandle(valuetype [runtime]System.RuntimeTypeHandle) + IL_0019: callvirt instance object [runtime]System.Runtime.Serialization.SerializationInfo::GetValue(string, + class [runtime]System.Type) + IL_001e: unbox.any [runtime]System.Int32 + IL_0023: stfld int32 ABC/ABC/MyExn::Data0@ + IL_0028: ret + } + + .method public strict virtual instance void GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo info, valuetype [runtime]System.Runtime.Serialization.StreamingContext context) cil managed + { + .custom instance void [runtime]System.Security.SecurityCriticalAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: ldarg.2 + IL_0003: call instance void [runtime]System.Exception::GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo, + valuetype [runtime]System.Runtime.Serialization.StreamingContext) + IL_0008: ldarg.1 + IL_0009: ldstr "Data0" + IL_000e: ldarg.0 + IL_000f: ldfld int32 ABC/ABC/MyExn::Data0@ + IL_0014: box [runtime]System.Int32 + IL_0019: callvirt instance void [runtime]System.Runtime.Serialization.SerializationInfo::AddValue(string, + object) + IL_001e: ret } .method public hidebysig specialname instance int32 get_Data0() cil managed diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/SerializableAttribute/ToplevelNamespace.fs.RealInternalSignatureOff.il.net472.release.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/SerializableAttribute/ToplevelNamespace.fs.RealInternalSignatureOff.il.net472.release.bsl index 2124b122fce..ecc195810c5 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/SerializableAttribute/ToplevelNamespace.fs.RealInternalSignatureOff.il.net472.release.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/SerializableAttribute/ToplevelNamespace.fs.RealInternalSignatureOff.il.net472.release.bsl @@ -476,7 +476,36 @@ IL_0002: ldarg.2 IL_0003: call instance void [runtime]System.Exception::.ctor(class [runtime]System.Runtime.Serialization.SerializationInfo, valuetype [runtime]System.Runtime.Serialization.StreamingContext) - IL_0008: ret + IL_0008: ldarg.0 + IL_0009: ldarg.1 + IL_000a: ldstr "Data0" + IL_000f: ldtoken [runtime]System.Int32 + IL_0014: call class [runtime]System.Type [runtime]System.Type::GetTypeFromHandle(valuetype [runtime]System.RuntimeTypeHandle) + IL_0019: callvirt instance object [runtime]System.Runtime.Serialization.SerializationInfo::GetValue(string, + class [runtime]System.Type) + IL_001e: unbox.any [runtime]System.Int32 + IL_0023: stfld int32 XYZ.MyExn::Data0@ + IL_0028: ret + } + + .method public strict virtual instance void GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo info, valuetype [runtime]System.Runtime.Serialization.StreamingContext context) cil managed + { + .custom instance void [runtime]System.Security.SecurityCriticalAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: ldarg.2 + IL_0003: call instance void [runtime]System.Exception::GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo, + valuetype [runtime]System.Runtime.Serialization.StreamingContext) + IL_0008: ldarg.1 + IL_0009: ldstr "Data0" + IL_000e: ldarg.0 + IL_000f: ldfld int32 XYZ.MyExn::Data0@ + IL_0014: box [runtime]System.Int32 + IL_0019: callvirt instance void [runtime]System.Runtime.Serialization.SerializationInfo::AddValue(string, + object) + IL_001e: ret } .method public hidebysig specialname instance int32 get_Data0() cil managed @@ -1176,7 +1205,36 @@ IL_0002: ldarg.2 IL_0003: call instance void [runtime]System.Exception::.ctor(class [runtime]System.Runtime.Serialization.SerializationInfo, valuetype [runtime]System.Runtime.Serialization.StreamingContext) - IL_0008: ret + IL_0008: ldarg.0 + IL_0009: ldarg.1 + IL_000a: ldstr "Data0" + IL_000f: ldtoken [runtime]System.Int32 + IL_0014: call class [runtime]System.Type [runtime]System.Type::GetTypeFromHandle(valuetype [runtime]System.RuntimeTypeHandle) + IL_0019: callvirt instance object [runtime]System.Runtime.Serialization.SerializationInfo::GetValue(string, + class [runtime]System.Type) + IL_001e: unbox.any [runtime]System.Int32 + IL_0023: stfld int32 XYZ.ABC/MyExn::Data0@ + IL_0028: ret + } + + .method public strict virtual instance void GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo info, valuetype [runtime]System.Runtime.Serialization.StreamingContext context) cil managed + { + .custom instance void [runtime]System.Security.SecurityCriticalAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: ldarg.2 + IL_0003: call instance void [runtime]System.Exception::GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo, + valuetype [runtime]System.Runtime.Serialization.StreamingContext) + IL_0008: ldarg.1 + IL_0009: ldstr "Data0" + IL_000e: ldarg.0 + IL_000f: ldfld int32 XYZ.ABC/MyExn::Data0@ + IL_0014: box [runtime]System.Int32 + IL_0019: callvirt instance void [runtime]System.Runtime.Serialization.SerializationInfo::AddValue(string, + object) + IL_001e: ret } .method public hidebysig specialname instance int32 get_Data0() cil managed @@ -1876,7 +1934,36 @@ IL_0002: ldarg.2 IL_0003: call instance void [runtime]System.Exception::.ctor(class [runtime]System.Runtime.Serialization.SerializationInfo, valuetype [runtime]System.Runtime.Serialization.StreamingContext) - IL_0008: ret + IL_0008: ldarg.0 + IL_0009: ldarg.1 + IL_000a: ldstr "Data0" + IL_000f: ldtoken [runtime]System.Int32 + IL_0014: call class [runtime]System.Type [runtime]System.Type::GetTypeFromHandle(valuetype [runtime]System.RuntimeTypeHandle) + IL_0019: callvirt instance object [runtime]System.Runtime.Serialization.SerializationInfo::GetValue(string, + class [runtime]System.Type) + IL_001e: unbox.any [runtime]System.Int32 + IL_0023: stfld int32 XYZ.ABC/ABC/MyExn::Data0@ + IL_0028: ret + } + + .method public strict virtual instance void GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo info, valuetype [runtime]System.Runtime.Serialization.StreamingContext context) cil managed + { + .custom instance void [runtime]System.Security.SecurityCriticalAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: ldarg.2 + IL_0003: call instance void [runtime]System.Exception::GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo, + valuetype [runtime]System.Runtime.Serialization.StreamingContext) + IL_0008: ldarg.1 + IL_0009: ldstr "Data0" + IL_000e: ldarg.0 + IL_000f: ldfld int32 XYZ.ABC/ABC/MyExn::Data0@ + IL_0014: box [runtime]System.Int32 + IL_0019: callvirt instance void [runtime]System.Runtime.Serialization.SerializationInfo::AddValue(string, + object) + IL_001e: ret } .method public hidebysig specialname instance int32 get_Data0() cil managed diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/SerializableAttribute/ToplevelNamespace.fs.RealInternalSignatureOn.il.net472.release.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/SerializableAttribute/ToplevelNamespace.fs.RealInternalSignatureOn.il.net472.release.bsl index f51bf1231fc..592d7d686be 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/SerializableAttribute/ToplevelNamespace.fs.RealInternalSignatureOn.il.net472.release.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/SerializableAttribute/ToplevelNamespace.fs.RealInternalSignatureOn.il.net472.release.bsl @@ -476,7 +476,36 @@ IL_0002: ldarg.2 IL_0003: call instance void [runtime]System.Exception::.ctor(class [runtime]System.Runtime.Serialization.SerializationInfo, valuetype [runtime]System.Runtime.Serialization.StreamingContext) - IL_0008: ret + IL_0008: ldarg.0 + IL_0009: ldarg.1 + IL_000a: ldstr "Data0" + IL_000f: ldtoken [runtime]System.Int32 + IL_0014: call class [runtime]System.Type [runtime]System.Type::GetTypeFromHandle(valuetype [runtime]System.RuntimeTypeHandle) + IL_0019: callvirt instance object [runtime]System.Runtime.Serialization.SerializationInfo::GetValue(string, + class [runtime]System.Type) + IL_001e: unbox.any [runtime]System.Int32 + IL_0023: stfld int32 XYZ.MyExn::Data0@ + IL_0028: ret + } + + .method public strict virtual instance void GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo info, valuetype [runtime]System.Runtime.Serialization.StreamingContext context) cil managed + { + .custom instance void [runtime]System.Security.SecurityCriticalAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: ldarg.2 + IL_0003: call instance void [runtime]System.Exception::GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo, + valuetype [runtime]System.Runtime.Serialization.StreamingContext) + IL_0008: ldarg.1 + IL_0009: ldstr "Data0" + IL_000e: ldarg.0 + IL_000f: ldfld int32 XYZ.MyExn::Data0@ + IL_0014: box [runtime]System.Int32 + IL_0019: callvirt instance void [runtime]System.Runtime.Serialization.SerializationInfo::AddValue(string, + object) + IL_001e: ret } .method public hidebysig specialname instance int32 get_Data0() cil managed @@ -1176,7 +1205,36 @@ IL_0002: ldarg.2 IL_0003: call instance void [runtime]System.Exception::.ctor(class [runtime]System.Runtime.Serialization.SerializationInfo, valuetype [runtime]System.Runtime.Serialization.StreamingContext) - IL_0008: ret + IL_0008: ldarg.0 + IL_0009: ldarg.1 + IL_000a: ldstr "Data0" + IL_000f: ldtoken [runtime]System.Int32 + IL_0014: call class [runtime]System.Type [runtime]System.Type::GetTypeFromHandle(valuetype [runtime]System.RuntimeTypeHandle) + IL_0019: callvirt instance object [runtime]System.Runtime.Serialization.SerializationInfo::GetValue(string, + class [runtime]System.Type) + IL_001e: unbox.any [runtime]System.Int32 + IL_0023: stfld int32 XYZ.ABC/MyExn::Data0@ + IL_0028: ret + } + + .method public strict virtual instance void GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo info, valuetype [runtime]System.Runtime.Serialization.StreamingContext context) cil managed + { + .custom instance void [runtime]System.Security.SecurityCriticalAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: ldarg.2 + IL_0003: call instance void [runtime]System.Exception::GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo, + valuetype [runtime]System.Runtime.Serialization.StreamingContext) + IL_0008: ldarg.1 + IL_0009: ldstr "Data0" + IL_000e: ldarg.0 + IL_000f: ldfld int32 XYZ.ABC/MyExn::Data0@ + IL_0014: box [runtime]System.Int32 + IL_0019: callvirt instance void [runtime]System.Runtime.Serialization.SerializationInfo::AddValue(string, + object) + IL_001e: ret } .method public hidebysig specialname instance int32 get_Data0() cil managed @@ -1876,7 +1934,36 @@ IL_0002: ldarg.2 IL_0003: call instance void [runtime]System.Exception::.ctor(class [runtime]System.Runtime.Serialization.SerializationInfo, valuetype [runtime]System.Runtime.Serialization.StreamingContext) - IL_0008: ret + IL_0008: ldarg.0 + IL_0009: ldarg.1 + IL_000a: ldstr "Data0" + IL_000f: ldtoken [runtime]System.Int32 + IL_0014: call class [runtime]System.Type [runtime]System.Type::GetTypeFromHandle(valuetype [runtime]System.RuntimeTypeHandle) + IL_0019: callvirt instance object [runtime]System.Runtime.Serialization.SerializationInfo::GetValue(string, + class [runtime]System.Type) + IL_001e: unbox.any [runtime]System.Int32 + IL_0023: stfld int32 XYZ.ABC/ABC/MyExn::Data0@ + IL_0028: ret + } + + .method public strict virtual instance void GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo info, valuetype [runtime]System.Runtime.Serialization.StreamingContext context) cil managed + { + .custom instance void [runtime]System.Security.SecurityCriticalAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: ldarg.2 + IL_0003: call instance void [runtime]System.Exception::GetObjectData(class [runtime]System.Runtime.Serialization.SerializationInfo, + valuetype [runtime]System.Runtime.Serialization.StreamingContext) + IL_0008: ldarg.1 + IL_0009: ldstr "Data0" + IL_000e: ldarg.0 + IL_000f: ldfld int32 XYZ.ABC/ABC/MyExn::Data0@ + IL_0014: box [runtime]System.Int32 + IL_0019: callvirt instance void [runtime]System.Runtime.Serialization.SerializationInfo::AddValue(string, + object) + IL_001e: ret } .method public hidebysig specialname instance int32 get_Data0() cil managed