Skip to content

Commit 671710c

Browse files
committed
Remove dependency on BinaryFormatter
1 parent 9cfc7b6 commit 671710c

File tree

7 files changed

+38
-49
lines changed

7 files changed

+38
-49
lines changed

build.cake

+1-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ BuildSettings.Packages.AddRange(new PackageDefinition[] {
6565
HasDirectory("tools/agents/net462").WithFiles(AGENT_FILES),
6666
HasDirectory("tools/agents/net6.0").WithFiles(AGENT_FILES_NETCORE),
6767
HasDirectory("tools/agents/net8.0").WithFiles(AGENT_FILES_NETCORE),
68-
HasDirectory("tools/agents/net9.0").WithFiles(AGENT_FILES_NETCORE).WithFile("System.Runtime.Serialization.Formatters.dll")
68+
HasDirectory("tools/agents/net9.0").WithFiles(AGENT_FILES_NETCORE)
6969
},
7070
symbols: new PackageCheck[] {
7171
HasDirectory("tools").WithFiles(ENGINE_PDB_FILES).AndFile("nunit3-console.pdb"),
@@ -126,7 +126,6 @@ BuildSettings.Packages.AddRange(new PackageDefinition[] {
126126
HasDirectory("bin/agents/net6.0").WithFiles(AGENT_FILES_NETCORE).AndFiles(AGENT_PDB_FILES_NETCORE),
127127
HasDirectory("bin/agents/net8.0").WithFiles(AGENT_FILES_NETCORE).AndFiles(AGENT_PDB_FILES_NETCORE),
128128
HasDirectory("bin/agents/net9.0").WithFiles(AGENT_FILES_NETCORE).AndFiles(AGENT_PDB_FILES_NETCORE)
129-
.AndFile("System.Runtime.Serialization.Formatters.dll")
130129
},
131130
testRunner: new ConsoleRunnerSelfTester(BuildSettings.ZipTestDirectory
132131
+ $"NUnit.Console.{BuildSettings.PackageVersion}/bin/net462/nunit3-console.exe"),

choco/nunit-console-runner.nuspec

-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@
8585
<file src = "$BIN_DIR$agents/net9.0/nunit.engine.core.dll" target="tools/agents/net9.0" />
8686
<file src = "$BIN_DIR$agents/net9.0/testcentric.engine.metadata.dll" target="tools/agents/net9.0" />
8787
<file src = "$BIN_DIR$agents/net9.0/Microsoft.Extensions.DependencyModel.dll" target="tools/agents/net9.0" />
88-
<file src = "$BIN_DIR$agents/net9.0/System.Runtime.Serialization.Formatters.dll" target="tools/agents/net9.0" />
8988
<!-- File used by ExtensionManager to indicate this is a chocolatey installation -->
9089
<file src = "VERIFICATION.txt" target = "tools/agents/net9.0" />
9190
</files>

nuget/runners/nunit.console-runner.nuspec

-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@
7878
<file src="agents/net9.0/nunit.engine.core.pdb" target="tools/agents/net9.0" />
7979
<file src="agents/net9.0/testcentric.engine.metadata.dll" target="tools/agents/net9.0" />
8080
<file src="agents/net9.0/Microsoft.Extensions.DependencyModel.dll" target="tools/agents/net9.0" />
81-
<file src="agents/net9.0/System.Runtime.Serialization.Formatters.dll" target="tools/agents/net9.0" />
8281

8382
<file src="net462/nunit3-console.exe" target="tools" />
8483
<file src="net462/nunit3-console.pdb" target="tools" />

src/NUnitEngine/nunit-agent/nunit-agent.csproj

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
<GenerateSupportedRuntime>false</GenerateSupportedRuntime>
1010
<OutputPath>..\..\..\bin\$(Configuration)\agents\</OutputPath>
1111
<CheckEolTargetFramework>false</CheckEolTargetFramework>
12-
<EnableUnsafeBinaryFormatterSerialization>true</EnableUnsafeBinaryFormatterSerialization>
1312
</PropertyGroup>
1413

1514
<PropertyGroup>

src/NUnitEngine/nunit.engine.core.tests/nunit.engine.core.tests.csproj

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
<DebugType>Full</DebugType>
1010
<CheckEolTargetFramework>false</CheckEolTargetFramework>
1111
<NuGetAudit>false</NuGetAudit>
12-
<EnableUnsafeBinaryFormatterSerialization>true</EnableUnsafeBinaryFormatterSerialization>
1312
</PropertyGroup>
1413

1514
<PropertyGroup>

src/NUnitEngine/nunit.engine.core/Communication/Protocols/BinarySerializationProtocol.cs

+37-39
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
using System;
44
using System.Collections.Generic;
55
using System.IO;
6-
using System.Runtime.Serialization;
7-
using System.Runtime.Serialization.Formatters.Binary;
86
using System.Text;
97
using NUnit.Engine.Communication.Messages;
108

@@ -101,43 +99,43 @@ public void Reset()
10199
}
102100
}
103101

104-
/// <summary>
105-
/// Serializes a message to a byte array to send to remote application.
106-
/// </summary>
107-
/// <param name="message">Message to be serialized</param>
108-
/// <returns>
109-
/// A byte[] containing the message itself, without a prefixed
110-
/// length, serialized according to the protocol.
111-
/// </returns>
112-
internal byte[] SerializeMessage(object message)
113-
{
114-
using (var memoryStream = new MemoryStream())
115-
{
116-
new BinaryFormatter().Serialize(memoryStream, message);
117-
return memoryStream.ToArray();
118-
}
119-
}
120-
121-
/// <summary>
122-
/// Deserializes a message contained in a byte array.
123-
/// </summary>
124-
/// <param name="bytes">A byte[] containing just the message, without a length prefix</param>
125-
/// <returns>An object representing the message encoded in the byte array</returns>
126-
internal object DeserializeMessage(byte[] bytes)
127-
{
128-
using (var memoryStream = new MemoryStream(bytes))
129-
{
130-
try
131-
{
132-
return new BinaryFormatter().Deserialize(memoryStream);
133-
}
134-
catch (Exception exception)
135-
{
136-
Reset(); // reset the received memory stream before the exception is rethrown - otherwise the same erroneous message is received again and again
137-
throw new SerializationException("error while deserializing message", exception);
138-
}
139-
}
140-
}
102+
///// <summary>
103+
///// Serializes a message to a byte array to send to remote application.
104+
///// </summary>
105+
///// <param name="message">Message to be serialized</param>
106+
///// <returns>
107+
///// A byte[] containing the message itself, without a prefixed
108+
///// length, serialized according to the protocol.
109+
///// </returns>
110+
//internal byte[] SerializeMessage(object message)
111+
//{
112+
// using (var memoryStream = new MemoryStream())
113+
// {
114+
// new BinaryFormatter().Serialize(memoryStream, message);
115+
// return memoryStream.ToArray();
116+
// }
117+
//}
118+
119+
///// <summary>
120+
///// Deserializes a message contained in a byte array.
121+
///// </summary>
122+
///// <param name="bytes">A byte[] containing just the message, without a length prefix</param>
123+
///// <returns>An object representing the message encoded in the byte array</returns>
124+
//internal object DeserializeMessage(byte[] bytes)
125+
//{
126+
// using (var memoryStream = new MemoryStream(bytes))
127+
// {
128+
// try
129+
// {
130+
// return new BinaryFormatter().Deserialize(memoryStream);
131+
// }
132+
// catch (Exception exception)
133+
// {
134+
// Reset(); // reset the received memory stream before the exception is rethrown - otherwise the same erroneous message is received again and again
135+
// throw new SerializationException("error while deserializing message", exception);
136+
// }
137+
// }
138+
//}
141139

142140
/// <summary>
143141
/// This method tries to read a single message and add to the messages collection.

src/NUnitEngine/nunit.engine.core/nunit.engine.core.csproj

-4
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@
3232
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="8.0.2" />
3333
</ItemGroup>
3434

35-
<ItemGroup Condition="'$(TargetFramework)'=='net9.0'">
36-
<PackageReference Include="System.Runtime.Serialization.Formatters" Version="9.0.3" />
37-
</ItemGroup>
38-
3935
<ItemGroup>
4036
<PackageReference Include="TestCentric.Metadata" Version="2.0.0" />
4137
</ItemGroup>

0 commit comments

Comments
 (0)