C# bindings generator for the Debug Adapter Protocol targeting .NET Standard 2.0 for universal support.
Adapted from Zed's rust bindings.
See Releases for the built C# bindings:
Dap-vX.X.X.zipcontains the generated source files +.csprojDap-vX.X.X-NetStandard20.zipcontains the compiled.NET Standard 2.0library
Alternatively, you can clone csharp-dap-types as a git submodule and reference the .csproj directly, i.e.
<ItemGroup>
<ProjectReference Include="./csharp-dap-types/Dap/Dap.csproj" />
</ItemGroup>To parse a received JSON-RPC message from the DAP you can call Newtonsoft.Json.JsonConvert.DeserializeObject<Dap.ProtocolMessage>(string json) -
this will automatically deserialize into the appropriate type (a subclass of Dap.Request, Dap.Response or Dap.Event, depending on the message's type):
using Newtonsoft.Json;
using Dap;
// ...
string json = """{
"type": "response",
"seq": 32,
"success": false,
"request_seq": 78,
"command": "attach",
"message": "failed to attach to debugger 'test'",
"body": {
"error": {
"id": 715,
"format": "failed to attach to debugger '{_name}'",
"variables": {
"_name": "test"
}
}
}
}""";
ProtocolMessage message = JsonConvert.DeserializeObject<ProtocolMessage>(json);
switch (message.MessageType)
{
case MessageType.Response:
{
Response response = (Response)message;
if (!response.Success)
// if (response is ErrorResponse error)
{
ErrorResponse error = (ErrorResponse)response;
throw new System.Exception($"response #{error.seq} had error: {error.message}");
}
// ...To send a new message, you can simply serialize the type to json:
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Dap;
// ...
ErrorResponse response = new ErrorResponse(
request.Command,
new Message
{
id = 753.
format = "failed to resolve breakpoint '{_breakpointId}' at '{path}'",
variables = new JObject(
new JProperty("path", path),
new JProperty("_breakpointId", 0)),
});
string json = JsonConvert.SerializeObject(response);The actual generator is written in rust, so you'll need to install the toolchain.
The bindings generator can be run using cargo:
cd csharp-dap-types
cargo runGenerated files will be placed in csharp-dap-types/Dap alongside some hand-written bindings in Common.cs.