Skip to content

Issue using Microsoft.Testing.Platform in Rider with TUnit #12261

Closed

Description

@AndrewPearson

Summary

In server mode (--server --client-port <N>), a client message that is a JSON-RPC error response with "id": null

makes the host throw an unhandled MessageFormatException: 'id' field is missing. The process dies with exit code

0xE0434352 (-532462766). JSON-RPC 2.0 requires id to be null in an error response when the id of the request could

not be determined (for example after a parse error), so this is a standard message and should not crash the host.

An IDE client (JetBrains Rider 2026.1.4) sends exactly this message after it fails to parse a message from the host, so the

host crash turns one parse problem into a total loss of the test session.

Environment

  • Microsoft.Testing.Platform 2.5.2 (Microsoft.Testing.Platform.dll 2.500.226.52706), hosted by TUnit 1.76.45

  • Target net48 (the only target I tried), Windows 11 Enterprise 10.0.22631, x64

Reproduction (without any IDE)

  1. Listen on a loopback TCP port P.

  2. Start any MTP test executable: <Tests>.exe --server --client-port P. It connects to P.

  3. Send an initialize request (framing: Content-Length: <bytes>\r\n\r\n then the JSON body) and read the response:

    
    {"jsonrpc":"2.0","id":1,"method":"initialize","params":{"processId":1,"clientInfo":{"name":"probe","version":"1.0"},"capabilities":{"testing":{"debuggerProvider":false}}}}
    
    
  4. Send this message:

    
    {"jsonrpc":"2.0","id":null,"error":{"code":-32700,"message":"JSON parse error"}}
    
    

Result: the test process exits at once. Its standard output contains:


Unhandled Exception: Microsoft.Testing.Platform.ServerMode.MessageFormatException: 'id' field is missing

   at Microsoft.Testing.Platform.ServerMode.SerializerUtilities.GetRequiredPropertyFromJson[T](IDictionary`2 properties, String propertyName)

   at Microsoft.Testing.Platform.ServerMode.SerializerUtilities.<>c.<RegisterDeserializers>b__16_12(IDictionary`2 properties)

   at Microsoft.Testing.Platform.ServerMode.ObjectDeserializer`1.DeserializeObject(IDictionary`2 properties)

   at Microsoft.Testing.Platform.ServerMode.SerializerUtilities.Deserialize(Type t, IDictionary`2 properties)

   at Microsoft.Testing.Platform.ServerMode.SerializerUtilities.Deserialize[T](IDictionary`2 properties)

   at Microsoft.Testing.Platform.ServerMode.SerializerUtilities.<>c.<RegisterDeserializers>b__16_0(IDictionary`2 properties)

   at Microsoft.Testing.Platform.ServerMode.ObjectDeserializer`1.DeserializeObject(IDictionary`2 properties)

   at Microsoft.Testing.Platform.ServerMode.SerializerUtilities.Deserialize(Type t, IDictionary`2 properties)

   at Microsoft.Testing.Platform.ServerMode.SerializerUtilities.Deserialize[T](IDictionary`2 properties)

   at Microsoft.Testing.Platform.ServerMode.TcpMessageHandler.<ReadAsync>d__14.MoveNext()

   at Microsoft.Testing.Platform.Hosts.ServerTestHost.<HandleMessagesAsync>d__43.MoveNext()

   ...

   at Microsoft.Testing.Platform.Builder.TestApplication.<RunAsync>d__10.MoveNext()

Exit code: -532462766 (0xE0434352, an unhandled .NET exception).

Control: the same error message with "id": 7 does not crash the host (it stays running).

Cause (from decompiling 2.5.2)

SerializerUtilities.RegisterDeserializers routes any message with an error property to the ErrorMessage deserializer:

if (properties.TryGetValue("error", out object _))

    return Deserialize<ErrorMessage>(properties);

and that deserializer does:

object requiredPropertyFromJson = GetRequiredPropertyFromJson<object>(properties, "id");

where

private static T GetRequiredPropertyFromJson<T>(IDictionary<string, object?> properties, string propertyName)

{

    object obj = GetOptionalPropertyFromJson(properties, propertyName)

        ?? throw new MessageFormatException("'" + propertyName + "' field is missing");

    ...

}

so an id that is present but null is reported as "missing". The MessageFormatException is not caught anywhere in

TcpMessageHandler.ReadAsync / ServerTestHost.HandleMessagesAsync, so it ends the process. (The response path just below

it, for a result message, also requires a non-null id.)

Expected behaviour

  1. An error response with "id": null is accepted per JSON-RPC 2.0 (ignored or logged), not treated as malformed.

  2. More generally, a malformed or unexpected message from the client should not terminate the host with an unhandled

    exception. The host could log it, answer with a JSON-RPC error where there is an id to answer, and keep serving.

Impact

Rider 2026.1.4's Testing Platform client sends this reply when it cannot parse a message from the host (it miscounts the

Content-Length of messages containing non-ASCII text, which is reported separately to JetBrains). Because the host then

crashes, the IDE shows no tests at all, with no clear message. If MTP tolerated the reply, the failure would at least be

limited to the one message instead of the whole session.

Activity

  1. Evangelink commented on Nov 9, 2026

    @Evangelink
    Member

    Thanks for the detailed reproduction. We confirmed an MTP bug here, independently of Rider and TUnit.

    Using the released Microsoft.Testing.Platform 2.5.2 DLL (2.500.226.52706) in a minimal net48 host, the explicit null-ID error response reproduces the unhandled MessageFormatException and exit code -532462766. The numeric-ID control continues processing subsequent requests and shuts down normally. Both serializer paths had the defect.

    The fix is ready for review:

    JSON-RPC 2.0 section 5 requires a null response ID when the request ID cannot be determined. The fix accepts and diagnoses these uncorrelated error responses without replying to them, assigning them to another request, or breaking shutdown accounting. Both Jsonite and System.Text.Json, the source-only client, and the protocol schema are covered. This issue is targeted at MSTest 4.5.3 / MTP 2.5.3.

    Main validation passed 1,267 focused unit cases and 18 real packaged/source-package acceptance cases. A buildable comparison retained the nullable model and the same tests while restoring only the strict-ID deserializers: six direct and six packaged cases failed for the intended defect, then the identical twelve executions passed after rebuilding and repacking the correct implementation. Release-branch validation separately passed all 96 new unit-regression executions and all 17 planned packaged/source-package cases, including net48; it is not inferred from main.

    The reported Rider parsing issue is separate: MTP's actual Framework writer declared and wrote 89 UTF-8 bytes for our Unicode sample, while the body contained 80 UTF-16 code units. We have not independently captured Rider's traffic or verified its parser, so we cannot confirm the original parse failure or promise that this fix recovers already lost messages. General recovery from malformed framing remains outside this narrowly scoped fix.

  2. added
    area/mtpMicrosoft.Testing.Platform core library.
    and removed
    needs/triageNeeds triage by a maintainer.
    on Nov 9, 2026
  3. AndrewPearson commented on Nov 10, 2026

    @AndrewPearson
    Author

    Thanks for the quick turnaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/mtpMicrosoft.Testing.Platform core library.area/server-mode-jsonrpcMTP server mode - JSON RPC transport.

    Type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions