Page 1 of 3

Sequence contains more than one matching element on endpoint

PostPosted: Wed Apr 05, 2023 10:20 am
by sameermoin
Hi Everyone,

I am getting an exception saying "{"ResponseStatus":{"ErrorCode":"Exception","Message":"Plugin 'Custom Plugin Name' caused an exception 'Sequence contains more than one matching element'"}}" on Jiwa "/Queries/SalesOrderList" endpoint.

if I disable that custom plugin and restart the API service then it works and if I re-enable the custom it stop working.

Endpoint: "http://localhost:8090/queries/SalesOrderList.json?Fields=InvoiceId&InvoiceNo=100505&apikey=7_G0vUX0tdRMkNhA2qW4Bm07E3yZEvCwHGNTaIQxDCs"

Re: Sequence contains more than one matching element on endp

PostPosted: Wed Apr 05, 2023 10:35 am
by SBarnes
Can you post the custom plugin?

Re: Sequence contains more than one matching element on endp

PostPosted: Wed Apr 05, 2023 10:44 am
by sameermoin
No, I can't. It is a quite big plugin.

Re: Sequence contains more than one matching element on endp

PostPosted: Wed Apr 05, 2023 10:59 am
by SBarnes
Then I am not sure how you are expecting someone to work out what is wrong if Scott, Mike or I can't replicate the issue, could you provide a cut down plugin that exhibits the same problem?

Re: Sequence contains more than one matching element on endp

PostPosted: Wed Apr 05, 2023 11:36 am
by Mike.Sheen
It could be a conflict introduced by your custom plugin. I'm not sure how things would behave if, for instance, your custom plugin added a route which conflicted with one we already have.

As you're trying the /Queries/SalesOrderList route - check to see if you are adding in your custom plugin the same route, or even a route with the same request class.

Failing that, start commenting out bits in your custom plugin, restart the API and test again until you can isolate the cause.

Re: Sequence contains more than one matching element on endp

PostPosted: Wed Apr 05, 2023 11:41 am
by SBarnes
Also if you can replicate the problem on a machine with Visual Studio installed and can get the debugger up from the configure function with a System.Diagnostics.Debugger.Launch() statement you might find when you make the call Visual studio should jump to the line causing the exception.

Re: Sequence contains more than one matching element on endp

PostPosted: Wed Apr 05, 2023 6:36 pm
by sameermoin
SBarnes wrote:Also if you can replicate the problem on a machine with Visual Studio installed and can get the debugger up from the configure function with a System.Diagnostics.Debugger.Launch() statement you might find when you make the call Visual studio should jump to the line causing the exception.



Not occurring locally. I commented complete Configure method even though the whole class but still occurring. I noticed it's occurring sometimes. Sometimes it returns the result.

I moved some parts of the plugin code into a new separate custom plugin also one system settings but, removed that from the main plugin

Re: Sequence contains more than one matching element on endp

PostPosted: Wed Apr 05, 2023 6:41 pm
by SBarnes
show-me-the-source-yoda.jpg
show-me-the-source-yoda.jpg (116.86 KiB) Viewed 25896 times

All I can suggest is you upload some version of the plugin

Re: Sequence contains more than one matching element on endp

PostPosted: Wed Apr 05, 2023 6:44 pm
by Mike.Sheen
Try turning on debug mode in the plugin system settings - this should give you the stack trace which might give you a clue.

Re: Sequence contains more than one matching element on endp

PostPosted: Wed Apr 05, 2023 6:59 pm
by SBarnes
You could also try something like the below in your configure method which is from the documentation here


Code: Select all

    //Handle Exceptions occurring in Services:

    Apphost.ServiceExceptionHandlers.Add((httpReq, request, exception) => {
        //log your exceptions here

        //return null; //continue with default Error Handling

        //or return your own custom response
        return DtoUtils.CreateErrorResponse(request, exception);
    });

    //Handle Unhandled Exceptions occurring outside of Services
    //E.g. Exceptions during Request binding or in filters:
    AppHost.UncaughtExceptionHandlers.Add((req, res, operationName, ex) => {
         res.Write($"Error: {ex.GetType().Name}: {ex.Message}");
         res.EndRequest(skipHeaders: true);
    });