René's URL Explorer Experiment


Title: Usage of await operator in the JsonRpcMethod. · Issue #147 · Astn/JSON-RPC.NET · GitHub

Open Graph Title: Usage of await operator in the JsonRpcMethod. · Issue #147 · Astn/JSON-RPC.NET

X Title: Usage of await operator in the JsonRpcMethod. · Issue #147 · Astn/JSON-RPC.NET

Description: Hello. I was wondering if it is possible to use the await operator in [JsonRpcMethod] methods? Inside the [JsonRpcMethod] I would like to call asynchronous methods and return Task from the function. But this approach throws an excepti...

Open Graph Description: Hello. I was wondering if it is possible to use the await operator in [JsonRpcMethod] methods? Inside the [JsonRpcMethod] I would like to call asynchronous methods and return Task from the funct...

X Description: Hello. I was wondering if it is possible to use the await operator in [JsonRpcMethod] methods? Inside the [JsonRpcMethod] I would like to call asynchronous methods and return Task<T> from the...

Opengraph URL: https://github.com/Astn/JSON-RPC.NET/issues/147

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Usage of await operator in the JsonRpcMethod.","articleBody":"Hello. I was wondering if it is possible to use the await operator in `[JsonRpcMethod]` methods?\r\nInside the `[JsonRpcMethod]` I would like to call asynchronous methods and return `Task\u003cT\u003e` from the function. But this approach throws an exception. All I could do was call synchronous versions of the functions and return `Task.FromResult` from the  function.\r\n\r\nSome examples:\r\n\r\n```\r\nusing AustinHarris.JsonRpc;\r\n\r\nobject[] services = new object[] { new ExampleService() };\r\n\r\nfor (string line = Console.ReadLine(); !string.IsNullOrEmpty(line); line = Console.ReadLine())\r\n{\r\n    try\r\n    {\r\n        var response = await JsonRpcProcessor.Process(line);\r\n        Console.WriteLine(response);\r\n    }\r\n    catch(Exception ex)\r\n    {\r\n        Console.WriteLine(ex.ToString());\r\n    }\r\n\r\n}\r\npublic class ExampleService : JsonRpcService\r\n{\r\n    [JsonRpcMethod]\r\n    private async Task\u003cdouble\u003e DoSomethingAsync(double l, double r) // {'method':'DoSomethingAsync','params':[1.0,2.0],'id':1}\r\n    {\r\n        return await Worker.SummAsync(l, r);\r\n    }\r\n}\r\npublic class Worker\r\n{\r\n    public static async Task\u003cdouble\u003e SummAsync(double a, double b)\r\n    {\r\n        await Task.Delay(1000);\r\n        return await Task.FromResult(a + b);\r\n    }\r\n}\r\n```\r\nException:\r\n```\r\nNewtonsoft.Json.JsonSerializationException: Self referencing loop detected for property 'Task' with type 'System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[System.Double,ExampleService+\u003cDoSomethingAsync\u003ed__0]'. Path 'StateMachine.\u003c\u003et__builder'.\r\n   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.CheckForCircularReference(JsonWriter writer, Object value, JsonProperty property, JsonContract contract, JsonContainerContract containerContract, JsonProperty containerProperty)\r\n   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.CalculatePropertyValues(JsonWriter writer, Object value, JsonContainerContract contract, JsonProperty member, JsonProperty property, JsonContract\u0026 memberContract, Object\u0026 memberValue)\r\n   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)\r\n   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)\r\n   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)\r\n   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)\r\n   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)\r\n   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)\r\n   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)\r\n   at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)\r\n   at Newtonsoft.Json.JsonSerializer.Serialize(JsonWriter jsonWriter, Object value, Type objectType)\r\n   at Newtonsoft.Json.JsonConvert.SerializeObjectInternal(Object value, Type type, JsonSerializer jsonSerializer)\r\n   at Newtonsoft.Json.JsonConvert.SerializeObject(Object value, Type type, JsonSerializerSettings settings)\r\n   at Newtonsoft.Json.JsonConvert.SerializeObject(Object value)\r\n   at AustinHarris.JsonRpc.JsonRpcProcessor.ProcessSync(String sessionId, String jsonRpc, Object jsonRpcContext, JsonSerializerSettings settings)\r\n   at AustinHarris.JsonRpc.JsonRpcProcessor.\u003c\u003ec.\u003cProcess\u003eb__3_0(Object _)\r\n   at System.Threading.Tasks.Task`1.InnerInvoke()\r\n   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)\r\n--- End of stack trace from previous location ---\r\n   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)\r\n   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task\u0026 currentTaskSlot, Thread threadPoolThread)\r\n--- End of stack trace from previous location ---\r\n   at Program.\u003cMain\u003e$(String[] args) in D:\\Work\\other\\JsonRpcNetAsync\\JsonRpcNetAsync\\Program.cs:line 9\r\n\r\n```\r\nWorking example:\r\n```\r\nusing AustinHarris.JsonRpc;\r\n\r\nobject[] services = new object[] { new ExampleService() };\r\n\r\nfor (string line = Console.ReadLine(); !string.IsNullOrEmpty(line); line = Console.ReadLine())\r\n{\r\n    try\r\n    {\r\n        Task\u003cstring\u003e task1 = JsonRpcProcessor.Process(line);\r\n        Task\u003cstring\u003e task2 = JsonRpcProcessor.Process(line);\r\n        Task\u003cstring\u003e task3 = JsonRpcProcessor.Process(line);\r\n        Task\u003cstring\u003e[] tasks = [task1, task2, task3];\r\n        string[] result = await Task.WhenAll(tasks);\r\n        foreach (string res in result) Console.WriteLine(res);\r\n    }\r\n    catch(Exception ex)\r\n    {\r\n        Console.WriteLine(ex.ToString());\r\n    }\r\n\r\n}\r\npublic class ExampleService : JsonRpcService\r\n{\r\n    [JsonRpcMethod]\r\n    private Task\u003cdouble\u003e DoSomethingAsync(double l, double r) // {'method':'DoSomethingAsync','params':[1.0,2.0],'id':1}\r\n    {\r\n        return Task.FromResult(Worker.SummSync(l, r));\r\n    }\r\n}\r\npublic class Worker\r\n{\r\n    public static double SummSync(double a, double b)\r\n    {\r\n        Thread.Sleep(10000);\r\n        return a + b;\r\n    }\r\n}\r\n```\r\nIf I understand correctly, calling `JsonRpcProcessor.Process(line)` runs in a separate thread, so blocking synchronous methods do not block the calling thread. But in the future, I might want to call asynchronous methods, and I was wondering if it is possible to do so using your framework? Thanks a lot for your answer!","author":{"url":"https://github.com/posahok","@type":"Person","name":"posahok"},"datePublished":"2024-09-17T16:31:53.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/147/JSON-RPC.NET/issues/147"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:6a9e6de9-ec89-ce39-efa5-44461592b3de
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idBB6A:1DF886:2F100C5:3C19F88:69904442
html-safe-nonce8374377814514b95ead73281bdf1cd05f83c80e93dea545e3655b41d28a66807
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQjZBOjFERjg4NjoyRjEwMEM1OjNDMTlGODg6Njk5MDQ0NDIiLCJ2aXNpdG9yX2lkIjoiMzg3OTMzMDUzOTMwNDQwNDAzNCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac60bf080644e37dc860e24685ad0887d821ace30cf5d2c29b9f172718eac7b356
hovercard-subject-tagissue:2531595394
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/Astn/JSON-RPC.NET/147/issue_layout
twitter:imagehttps://opengraph.githubassets.com/ce256320dc4ddb05ebca0749110519aa18863b20532bda8fe78efe301e4be95f/Astn/JSON-RPC.NET/issues/147
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/ce256320dc4ddb05ebca0749110519aa18863b20532bda8fe78efe301e4be95f/Astn/JSON-RPC.NET/issues/147
og:image:altHello. I was wondering if it is possible to use the await operator in [JsonRpcMethod] methods? Inside the [JsonRpcMethod] I would like to call asynchronous methods and return Task from the funct...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameposahok
hostnamegithub.com
expected-hostnamegithub.com
None42c603b9d642c4a9065a51770f75e5e27132fef0e858607f5c9cb7e422831a7b
turbo-cache-controlno-preview
go-importgithub.com/Astn/JSON-RPC.NET git https://github.com/Astn/JSON-RPC.NET.git
octolytics-dimension-user_id6857743
octolytics-dimension-user_loginAstn
octolytics-dimension-repository_id17465376
octolytics-dimension-repository_nwoAstn/JSON-RPC.NET
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id17465376
octolytics-dimension-repository_network_root_nwoAstn/JSON-RPC.NET
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release3b33c5aedc9808f45bc5fcf0b1e4404cf749dac7
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/Astn/JSON-RPC.NET/issues/147#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FAstn%2FJSON-RPC.NET%2Fissues%2F147
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FAstn%2FJSON-RPC.NET%2Fissues%2F147
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=Astn%2FJSON-RPC.NET
Reloadhttps://github.com/Astn/JSON-RPC.NET/issues/147
Reloadhttps://github.com/Astn/JSON-RPC.NET/issues/147
Reloadhttps://github.com/Astn/JSON-RPC.NET/issues/147
Astn https://github.com/Astn
JSON-RPC.NEThttps://github.com/Astn/JSON-RPC.NET
Notifications https://github.com/login?return_to=%2FAstn%2FJSON-RPC.NET
Fork 87 https://github.com/login?return_to=%2FAstn%2FJSON-RPC.NET
Star 329 https://github.com/login?return_to=%2FAstn%2FJSON-RPC.NET
Code https://github.com/Astn/JSON-RPC.NET
Issues 13 https://github.com/Astn/JSON-RPC.NET/issues
Pull requests 8 https://github.com/Astn/JSON-RPC.NET/pulls
Actions https://github.com/Astn/JSON-RPC.NET/actions
Projects 0 https://github.com/Astn/JSON-RPC.NET/projects
Wiki https://github.com/Astn/JSON-RPC.NET/wiki
Security 0 https://github.com/Astn/JSON-RPC.NET/security
Insights https://github.com/Astn/JSON-RPC.NET/pulse
Code https://github.com/Astn/JSON-RPC.NET
Issues https://github.com/Astn/JSON-RPC.NET/issues
Pull requests https://github.com/Astn/JSON-RPC.NET/pulls
Actions https://github.com/Astn/JSON-RPC.NET/actions
Projects https://github.com/Astn/JSON-RPC.NET/projects
Wiki https://github.com/Astn/JSON-RPC.NET/wiki
Security https://github.com/Astn/JSON-RPC.NET/security
Insights https://github.com/Astn/JSON-RPC.NET/pulse
New issuehttps://github.com/login?return_to=https://github.com/Astn/JSON-RPC.NET/issues/147
New issuehttps://github.com/login?return_to=https://github.com/Astn/JSON-RPC.NET/issues/147
Usage of await operator in the JsonRpcMethod.https://github.com/Astn/JSON-RPC.NET/issues/147#top
https://github.com/posahok
https://github.com/posahok
posahokhttps://github.com/posahok
on Sep 17, 2024https://github.com/Astn/JSON-RPC.NET/issues/147#issue-2531595394
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.