Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
namespace Microsoft.VisualStudio.TestTools.UnitTesting;

[SuppressMessage("ApiDesign", "RS0030:Do not use banned APIs", Justification = "MTP logger bridge")]
internal sealed class MTPTraceLogger : MarshalByRefObject, ITraceLogger
internal sealed class MTPTraceLogger :
#if NETFRAMEWORK
MarshalByRefObject,
#endif
ITraceLogger
{
private readonly ILogger _logger;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@

namespace Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.VSTestAdapter;

internal sealed class EqtTraceLogger : MarshalByRefObject, ITraceLogger
internal sealed class EqtTraceLogger :
#if NETFRAMEWORK
MarshalByRefObject,
#endif
ITraceLogger
{
private EqtTraceLogger()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Dep
/// <summary>
/// Specifies type of deployment item origin, where the item comes from.
/// </summary>
#if NETFRAMEWORK
[Serializable]
#endif
internal enum DeploymentItemOriginType
{
/// <summary>
Expand All @@ -37,7 +39,9 @@ internal enum DeploymentItemOriginType
/// <summary>
/// The deployment item for a test class or a test method.
/// </summary>
#if NETFRAMEWORK
[Serializable]
#endif
internal sealed class DeploymentItem
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Dep
/// <summary>
/// The test run directories.
/// </summary>
#if NETFRAMEWORK
[Serializable]
#endif
internal sealed class TestRunDirectories
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Discovery;
/// </summary>
/// <param name="TestElements">The test elements that were discovered.</param>
/// <param name="Warnings">Warnings that happened during discovery.</param>
#if NETFRAMEWORK
[Serializable]
#endif
internal sealed record AssemblyEnumerationResult(List<UnitTestElement> TestElements, List<string> Warnings);
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

// Note: System.Runtime.Serialization is intentionally unconditional — SerializationException is caught
// outside the #if NETFRAMEWORK block (see catch in EnumerateAssembly).
using System.Runtime.Serialization;
#if NETFRAMEWORK
using System.Security;
#endif

using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution;
using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Helpers;
Expand All @@ -16,7 +20,10 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Discovery;
/// Enumerates through all types in the assembly in search of valid test methods.
/// </summary>
[SuppressMessage("Performance", "CA1852: Seal internal types", Justification = "Overrides required for testability")]
internal class AssemblyEnumerator : MarshalByRefObject
internal class AssemblyEnumerator
#if NETFRAMEWORK
: MarshalByRefObject
#endif
{
/// <summary>
/// Helper for reflection API's.
Expand Down Expand Up @@ -45,17 +52,16 @@ public AssemblyEnumerator(MSTestSettings settings) =>
// This would just be resetting the settings to itself in non desktop workflows.
MSTestSettings.PopulateSettings(settings);

#if NETFRAMEWORK
/// <summary>
/// Returns object to be used for controlling lifetime, null means infinite lifetime.
/// </summary>
/// <returns>
/// The <see cref="object"/>.
/// </returns>
[SecurityCritical]
#if NET5_0_OR_GREATER
[Obsolete("MarshalByRefObject.InitializeLifetimeService is obsolete in .NET 5+. This override is required to maintain infinite lifetime service.")]
public override object? InitializeLifetimeService() => null;
#endif
public override object InitializeLifetimeService() => null!;

/// <summary>
/// Enumerates through all types in the assembly in search of valid test methods.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

#if NETFRAMEWORK
using System.Security;
#endif

using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Helpers;
using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.ObjectModel;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution;

internal sealed class TestAssemblySettingsProvider : MarshalByRefObject
internal sealed class TestAssemblySettingsProvider
#if NETFRAMEWORK
: MarshalByRefObject
#endif
{
#if NETFRAMEWORK
/// <summary>
/// Returns object to be used for controlling lifetime, null means infinite lifetime.
/// </summary>
/// <returns>
/// The <see cref="object"/>.
/// </returns>
[SecurityCritical]
#if NET5_0_OR_GREATER
[Obsolete("MarshalByRefObject.InitializeLifetimeService is obsolete in .NET 5+. This override is required to maintain infinite lifetime service.")]
public override object? InitializeLifetimeService() => null;
#endif
public override object InitializeLifetimeService() => null!;

[SuppressMessage(
"Performance",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution;
#pragma warning disable CA1852 // Seal internal types - This class is inherited in tests.
internal class TestExecutionManager
{
private sealed class RemotingMessageLogger : MarshalByRefObject, IMessageLogger
private sealed class RemotingMessageLogger :
#if NETFRAMEWORK
MarshalByRefObject,
#endif
IMessageLogger
{
private readonly IMessageLogger _realMessageLogger;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

#if NETFRAMEWORK
using System.Security;
#endif

using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Discovery;
using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Extensions;
Expand All @@ -15,7 +17,10 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution;
/// <summary>
/// Defines type cache which reflects upon a type and cache its test artifacts.
/// </summary>
internal sealed class TypeCache : MarshalByRefObject
internal sealed class TypeCache
#if NETFRAMEWORK
: MarshalByRefObject
#endif
{
/// <summary>
/// Helper for reflection API's.
Expand Down Expand Up @@ -108,17 +113,16 @@ public IEnumerable<TestAssemblyInfo> AssemblyInfoListWithExecutableCleanupMethod
return ResolveTestMethodInfoForDiscovery(testMethod, testClassInfo);
}

#if NETFRAMEWORK
Comment thread
Evangelink marked this conversation as resolved.
/// <summary>
/// Returns object to be used for controlling lifetime, null means infinite lifetime.
/// </summary>
/// <returns>
/// The <see cref="object"/>.
/// </returns>
[SecurityCritical]
#if NET5_0_OR_GREATER
[Obsolete("MarshalByRefObject.InitializeLifetimeService is obsolete in .NET 5+. This override is required to maintain infinite lifetime service.")]
public override object? InitializeLifetimeService() => null;
#endif
public override object InitializeLifetimeService() => null!;

#region ClassInfo creation and cache logic.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

#if NETFRAMEWORK
using System.Security;
#endif

using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Extensions;
using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Helpers;
Expand All @@ -18,7 +20,10 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution;
/// <summary>
/// The runner that runs a single unit test. Also manages the assembly and class cleanup methods at the end of the run.
/// </summary>
internal sealed class UnitTestRunner : MarshalByRefObject
internal sealed class UnitTestRunner
#if NETFRAMEWORK
: MarshalByRefObject
#endif
{
private readonly TypeCache _typeCache;
private readonly ClassCleanupManager _classCleanupManager;
Expand Down Expand Up @@ -75,17 +80,16 @@ public void Cancel()
=> PlatformServiceProvider.Instance.TestRunCancellationToken?.Cancel();
#pragma warning restore CA1822 // Mark members as static

#if NETFRAMEWORK
/// <summary>
/// Returns object to be used for controlling lifetime, null means infinite lifetime.
/// </summary>
/// <returns>
/// The <see cref="object"/>.
/// </returns>
[SecurityCritical]
#if NET5_0_OR_GREATER
[Obsolete("MarshalByRefObject.InitializeLifetimeService is obsolete in .NET 5+. This override is required to maintain infinite lifetime service.")]
public override object? InitializeLifetimeService() => null;
#endif
public override object InitializeLifetimeService() => null!;

// Task cannot cross app domains.
// For now, TestExecutionManager will call this sync method which is hacky.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

#if NETFRAMEWORK
using System.Security;
#endif

using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Helpers;

[SuppressMessage("Performance", "CA1852: Seal internal types", Justification = "Overrides required for mocking")]
internal class ReflectHelper : MarshalByRefObject
internal class ReflectHelper
#if NETFRAMEWORK
: MarshalByRefObject
#endif
{
#pragma warning disable RS0030 // Do not use banned APIs
private static readonly Lazy<ReflectHelper> InstanceValue = new(() => new());
Expand Down Expand Up @@ -53,17 +58,16 @@ internal class ReflectHelper : MarshalByRefObject
return false;
}

#if NETFRAMEWORK
/// <summary>
/// Returns object to be used for controlling lifetime, null means infinite lifetime.
/// </summary>
/// <returns>
/// The <see cref="object"/>.
/// </returns>
[SecurityCritical]
#if NET5_0_OR_GREATER
[Obsolete("MarshalByRefObject.InitializeLifetimeService is obsolete in .NET 5+. This override is required to maintain infinite lifetime service.")]
public override object? InitializeLifetimeService() => null;
#endif
public override object InitializeLifetimeService() => null!;

/// <summary>
/// Gets first attribute that matches the type.
Expand Down
24 changes: 10 additions & 14 deletions src/Adapter/MSTestAdapter.PlatformServices/MSTestSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter;
/// <summary>
/// Adapter Settings for the run.
/// </summary>
#if NETFRAMEWORK
[Serializable]
#endif
internal sealed partial class MSTestSettings
{
/// <summary>
Expand All @@ -24,16 +26,6 @@ internal sealed partial class MSTestSettings

private const string ParallelizeSettingsName = "Parallelize";

/// <summary>
/// Member variable for Adapter settings.
/// </summary>
private static MSTestSettings? s_currentSettings;

/// <summary>
/// Member variable for RunConfiguration settings.
/// </summary>
private static RunConfigurationSettings? s_runConfigurationSettings;

/// <summary>
/// Initializes a new instance of the <see cref="MSTestSettings"/> class.
/// </summary>
Expand All @@ -60,21 +52,25 @@ public MSTestSettings()
/// <summary>
/// Gets the current settings.
/// </summary>
[field: AllowNull]
[field: MaybeNull]
[AllowNull]
public static MSTestSettings CurrentSettings
{
get => s_currentSettings ??= new MSTestSettings();
private set => s_currentSettings = value;
get => field ??= new MSTestSettings();
private set;
}

/// <summary>
/// Gets the current configuration settings.
/// </summary>
[field: AllowNull]
[field: MaybeNull]
[AllowNull]
public static RunConfigurationSettings RunConfigurationSettings
{
get => s_runConfigurationSettings ??= new RunConfigurationSettings();
private set => s_runConfigurationSettings = value;
get => field ??= new RunConfigurationSettings();
private set;
}

/// <summary>
Expand Down
6 changes: 5 additions & 1 deletion src/Adapter/MSTestAdapter.PlatformServices/NopTraceLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@

namespace Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter;

internal sealed class NopTraceLogger : MarshalByRefObject, ITraceLogger
internal sealed class NopTraceLogger :
#if NETFRAMEWORK
MarshalByRefObject,
#endif
ITraceLogger
{
private NopTraceLogger()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

namespace Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.ObjectModel;

#if NETFRAMEWORK
[Serializable]
#endif
internal sealed class StackTraceInformation
{
public StackTraceInformation(string stackTrace)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

namespace Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.ObjectModel;

#if NETFRAMEWORK
[Serializable]
#endif
internal sealed class TestAssemblySettings
{
public TestAssemblySettings() => Workers = -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.ObjectModel;
/// <summary>
/// TestMethod contains information about a unit test method that needs to be executed.
/// </summary>
#if NETFRAMEWORK
[Serializable]
#endif
internal sealed class TestMethod : ITestMethod
{
/// <summary>
Expand Down Expand Up @@ -101,10 +103,14 @@ internal TestMethod(
// This holds user types that may not be serializable.
// If app domains are enabled, we have no choice other than losing the original data.
// In that case, we fallback to deserializing the SerializedData.
#if NETFRAMEWORK
[field: NonSerialized]
#endif
internal object?[]? ActualData { get; set; }

#if NETFRAMEWORK
[field: NonSerialized]
#endif
internal MethodInfo? MethodInfo { get; set; }

/// <summary>
Expand Down
Loading