From 27b4938c11c7e0cc5dc9b9c6310efd1571c3caf4 Mon Sep 17 00:00:00 2001 From: Bernard Normier Date: Wed, 11 Oct 2023 19:02:56 -0400 Subject: [PATCH] Suppress BinaryFormatter-related code for .NET 8.0 --- cpp/src/slice2cs/Gen.cpp | 2 ++ csharp/BUILDING.md | 7 +++++++ csharp/msbuild/ice.common.props | 1 + csharp/test/Ice/serialize/AllTests.cs | 9 +++++++-- 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/cpp/src/slice2cs/Gen.cpp b/cpp/src/slice2cs/Gen.cpp index b4ff72c7e2c..4e3af355946 100644 --- a/cpp/src/slice2cs/Gen.cpp +++ b/cpp/src/slice2cs/Gen.cpp @@ -2973,6 +2973,7 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) if(!dataMembers.empty()) { _out << sp; + _out << nl << "#if !NET8_0_OR_GREATER"; emitGeneratedCodeAttribute(); _out << nl << "public override void GetObjectData(global::System.Runtime.Serialization.SerializationInfo info, " << "global::System.Runtime.Serialization.StreamingContext context)"; @@ -2984,6 +2985,7 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) } _out << sp << nl << "base.GetObjectData(info, context);"; _out << eb; + _out << nl << "#endif"; } _out << sp << nl << "#endregion"; // Object members diff --git a/csharp/BUILDING.md b/csharp/BUILDING.md index 7ff502a8ae3..8201a3d48d6 100644 --- a/csharp/BUILDING.md +++ b/csharp/BUILDING.md @@ -45,6 +45,13 @@ To build all Ice assemblies and the associated test suite, run: msbuild msbuild\ice.proj ``` +> Depending on your Visual Studio environment, you may need to specify the platform. +> For example: +> +> ```shell +> msbuild msbuild\ice.proj /p:Platform=x64 +> ``` + Upon completion, the Ice assemblies for the .NET Framework 4.5 and .NET Standard 2.0 are placed in the `lib\net45` and `lib\netstandard2.0` folders respectively. diff --git a/csharp/msbuild/ice.common.props b/csharp/msbuild/ice.common.props index 493d6dd17fb..f1c0a4f3497 100644 --- a/csharp/msbuild/ice.common.props +++ b/csharp/msbuild/ice.common.props @@ -16,6 +16,7 @@ 512 prompt 4 + true TRACE true NET45;$(DefineConstants) diff --git a/csharp/test/Ice/serialize/AllTests.cs b/csharp/test/Ice/serialize/AllTests.cs index 9c23d62cc2a..f4fa28c6c41 100644 --- a/csharp/test/Ice/serialize/AllTests.cs +++ b/csharp/test/Ice/serialize/AllTests.cs @@ -167,16 +167,21 @@ static public int allTests(global::Test.TestHelper helper) private static T inOut(T o, Ice.Communicator communicator) { +#if NET8_0_OR_GREATER + // .NET 8.0 and greater removed support for BinaryFormatter + // See also #1549. + return o; +#else BinaryFormatter bin = new BinaryFormatter(null, new StreamingContext(StreamingContextStates.All, communicator)); using(MemoryStream mem = new MemoryStream()) { -#pragma warning disable SYSLIB0011 // Type or member is obsolete + bin.Serialize(mem, o); mem.Seek(0, 0); return(T)bin.Deserialize(mem); -#pragma warning restore SYSLIB0011 // Type or member is obsolete } +#endif } } }