Issue using Microsoft.Testing.Platform in Rider with TUnit

Đang mở
#12,261 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
72/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
csharp
Lĩnh vực
backend-api-design

Hướng nghiên cứu

Start by reading SerializerUtilities.RegisterDeserializers and the ErrorMessage deserializer, then trace how TcpMessageHandler.ReadAsync and ServerTestHost.HandleMessagesAsync handle deserialization failures. Reproduce with the supplied id: null JSON-RPC error response and compare it with the id: 7 control. Done when the null-id response no longer terminates the host and the server continues handling messages.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

needs/triage

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.

Ngôn ngữ chính
C#
Star
1.1k
Fork
312
Merge trung bình
11 giờ 24 phút
Pull request đã merge (30 ngày)
310

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của microsoft/testfx

Tất cả issue của microsoft/testfx

Issue tương tự

Thêm issue về C#

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.