Skip to content

Commit

Permalink
Suppress BinaryFormatter-related code for .NET 8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardnormier committed Oct 11, 2023
1 parent d7a9f76 commit 27b4938
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
2 changes: 2 additions & 0 deletions cpp/src/slice2cs/Gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)";
Expand All @@ -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
Expand Down
7 changes: 7 additions & 0 deletions csharp/BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions csharp/msbuild/ice.common.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<FileAlignment>512</FileAlignment>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<DefineConstants>TRACE</DefineConstants>
<SignAssembly>true</SignAssembly>
<DefineConstants Condition="'$(TargetFrameworkVersion)' == 'v4.5.1'">NET45;$(DefineConstants)</DefineConstants>
Expand Down
9 changes: 7 additions & 2 deletions csharp/test/Ice/serialize/AllTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,16 +167,21 @@ static public int allTests(global::Test.TestHelper helper)

private static T inOut<T>(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
}
}
}
Expand Down

0 comments on commit 27b4938

Please sign in to comment.