JSON-RPC.NET icon indicating copy to clipboard operation
JSON-RPC.NET copied to clipboard

Fix for error "An item with the same key has already been added." and AspNet Test Server Project

Open alexbclarke opened this issue 7 years ago • 6 comments

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.

alexbclarke avatar Jun 15 '17 10:06 alexbclarke

Thanks for the contribution. However, I am not seeing the tests you refer to in this merge request.

Astn avatar Jun 27 '17 18:06 Astn

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.

alexbclarke avatar Jun 28 '17 09:06 alexbclarke

Hi. Will this branch be merged soon ? The error is still there :(

razvancurcudel avatar Oct 14 '18 14:10 razvancurcudel

@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.

Astn avatar Oct 14 '18 19:10 Astn

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.

razvancurcudel avatar Oct 14 '18 19:10 razvancurcudel

Anything that is only called once would be perfect! Sounds like we need to change the wiki to say App_Start instead of Init.

Astn avatar Oct 15 '18 15:10 Astn

Workaround here: https://github.com/Astn/JSON-RPC.NET/pull/83#discussion_r124734273

Astn avatar Mar 13 '24 00:03 Astn