JSON-RPC.NET
JSON-RPC.NET copied to clipboard
Fix for error "An item with the same key has already been added." and AspNet Test Server Project
Hi Austin, Thanks for sharing your work! I made a couple of changes to the solution. One to avoid an error "An item with the same key has already been added." when a Json Rpc service class is instantiated from the Global.asax.cs Init() method where it can be called multiple times. Another change is, I added a TestServer_AspNet project that can be used to reproduce the error and outline possible solutions.
Hope you will find these changes useful. Thanks again,
Best regards, Alexander.
Thanks for the contribution. However, I am not seeing the tests you refer to in this merge request.
Hi Austin, there was no unit test. Initially I added Test_AspNet web project that demonstrates the error. However, Travis would fail on build, so I removed that project. I now added Test_AspNet project again and added a unit test. Please review and let me know if my changes could add value to your project.
Hi. Will this branch be merged soon ? The error is still there :(
@razvancurcudel this PR adds some tests and enhances the exception that is thrown when your code tries to register the same service multiple times. There are some build fixes that need to happen before I can merge this. After it is merged you will still get an exception with trying to register a service multiple times with the same service name. It will just be a better message in the exception.
What is the workaround for this problem? I started an empty asp.net project and I added a service with a rpc method as in example. I initialised that service in Init method from Global.asax class and I got the error. I moved the initialization into Application_start method and it seems to work now, but I don't know if it is the right thing to do.
Anything that is only called once would be perfect! Sounds like we need to change the wiki to say App_Start instead of Init.
Workaround here: https://github.com/Astn/JSON-RPC.NET/pull/83#discussion_r124734273