Skip to content

Commit

Permalink
Suppress BinaryFormatter-related code for .NET 8.0 (#1550)
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardnormier authored Oct 12, 2023
1 parent f26ad53 commit fbc2d6f
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 0 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
13 changes: 13 additions & 0 deletions csharp/test/Ice/optional/AllTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ public static Test.InitialPrx allTests(global::Test.TestHelper helper)
mo1.ioopd.Value.Add(5, communicator.stringToProxy("test"));

mo1.bos = new bool[] { false, true, false };

#if !NET8_0_OR_GREATER // See #1549
mo1.ser = new Test.SerializableClass(56);
#endif

test(mo1.a.Value ==(byte)15);
test(mo1.b.Value);
Expand Down Expand Up @@ -121,7 +124,12 @@ public static Test.InitialPrx allTests(global::Test.TestHelper helper)
test(mo1.ioopd.Value[5].Equals(communicator.stringToProxy("test")));

test(ArraysEqual(mo1.bos.Value, new bool[] { false, true, false }));

#if NET8_0_OR_GREATER
test(!mo1.ser.HasValue);
#else
test(mo1.ser.Value.Equals(new Test.SerializableClass(56)));
#endif

output.WriteLine("ok");

Expand Down Expand Up @@ -170,7 +178,12 @@ public static Test.InitialPrx allTests(global::Test.TestHelper helper)

test(!mo4.ser.HasValue);

#if NET8_0_OR_GREATER
bool supportsCsharpSerializable = false;
#else
bool supportsCsharpSerializable = initial.supportsCsharpSerializable();
#endif

if(!supportsCsharpSerializable)
{
mo1.ser = Ice.Util.None;
Expand Down
4 changes: 4 additions & 0 deletions csharp/test/Ice/optional/TestI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,11 @@ public override bool supportsJavaSerializable(Ice.Current current)

public override bool supportsCsharpSerializable(Ice.Current current)
{
#if NET8_0_OR_GREATER
return false;
#else
return true;
#endif
}

public override bool supportsCppStringView(Ice.Current current)
Expand Down
2 changes: 2 additions & 0 deletions csharp/test/Ice/seqMapping/Twoways.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1238,6 +1238,7 @@ internal static void twoways(Ice.Communicator communicator, Test.MyClassPrx p)
}
}

#if !NET8_0_OR_GREATER // See #1549
{
Serialize.Small i = null;
Serialize.Small o;
Expand Down Expand Up @@ -1345,6 +1346,7 @@ internal static void twoways(Ice.Communicator communicator, Test.MyClassPrx p)
// OK, talking to non-C# server.
}
}
#endif
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions csharp/test/Ice/seqMapping/TwowaysAMI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,7 @@ public void opCustomCVSSI(Ice.AsyncResult result)
callback.called();
}

#if !NET8_0_OR_GREATER // See #1549
public void opSerialSmallCSharpNullI(Ice.AsyncResult result)
{
try
Expand Down Expand Up @@ -980,6 +981,7 @@ public void opSerialStructCSharpI(Ice.AsyncResult result)
// OK, talking to non-C# server.
}
}
#endif

public virtual void check()
{
Expand Down Expand Up @@ -1843,6 +1845,7 @@ internal static void twowaysAMI(Ice.Communicator communicator, Test.MyClassPrx p
cb.check();
}

#if !NET8_0_OR_GREATER // See #1549
{
Serialize.Small i = null;

Expand Down Expand Up @@ -1889,6 +1892,7 @@ internal static void twowaysAMI(Ice.Communicator communicator, Test.MyClassPrx p
p.begin_opSerialStructCSharp(i, null, cb.opSerialStructCSharpI, i);
cb.check();
}
#endif
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions csharp/test/Ice/serialize/AllTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ 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())
Expand All @@ -177,6 +182,7 @@ private static T inOut<T>(T o, Ice.Communicator communicator)
return(T)bin.Deserialize(mem);
#pragma warning restore SYSLIB0011 // Type or member is obsolete
}
#endif
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions csharp/test/Ice/stream/AllTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ static public int allTests(global::Test.TestHelper helper)
test(Compare(arr2S, arrS));
}

#if !NET8_0_OR_GREATER // See #1549
{
Serialize.Small small = new Serialize.Small();
small.i = 99;
Expand All @@ -376,6 +377,7 @@ static public int allTests(global::Test.TestHelper helper)
var small2 =(Serialize.Small)inS.readSerializable();
test(small2.i == 99);
}
#endif

{
short[] arr = { 0x01, 0x11, 0x12, 0x22 };
Expand Down

0 comments on commit fbc2d6f

Please sign in to comment.