Skip to content

Create .NET bot #79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft

Create .NET bot #79

wants to merge 8 commits into from

Conversation

link2xt
Copy link
Contributor

@link2xt link2xt commented May 26, 2025

.NET has built-in support for JSON-RPC: https://github.com/microsoft/vs-streamjsonrpc/
So it should fit well for bot creation.
I don't have any experience with .NET packaging, but it may be worth building some basic example in case someone familiar with C# or F# wants to write a bot and take over maintenance of "bindings".

@link2xt
Copy link
Contributor Author

link2xt commented May 26, 2025

This already configures an account and starts I/O.

Have not figured out how to parse events with are distinguished by "kind".
Somewhat relevant documentation:
https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/polymorphism

Related issue about matching F# types to union types: dotnet/runtime#55744

@link2xt
Copy link
Contributor Author

link2xt commented May 26, 2025

Deserialization now works for info messages, but for {"jsonrpc":"2.0","id":18,"result":{"contextId":1,"event":{"comment":null,"kind":"ConfigureProgress","progress":1}}} it fails with
"Unhandled exception. System.Text.Json.JsonException: Deserializing JSON-RPC result to type Event failed with JsonException: The metadata property is either not supported by the type or is not the first property in the deserialized JSON object."

So it is unhappy about "kind" being not the first type because there is a "comment" before that.

One way is to switch from StreamJsonRpc.SystemTextJsonFormatter to StreamJsonRpc.JsonMessageFormatter which uses Newtonsoft JSON library instead of standard one. But then polymorphic attributes from the standard library will not work, need to redo the class hieararchy for events.

Maybe there is a solution for standard library or we can change the core to always put "kind" first.

EDIT: fixed with AllowOutOfOrderMetadataProperties.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant