LordVeovis / xmlrpc

A port of CookComputing.XmlRpcV2 for dotnet core 2
MIT License
33 stars 21 forks source link

I set the flag to `AllowStringFaultCode` and it keeps throwing the error `Exception thrown: 'CookComputing.XmlRpc.XmlRpcTypeMismatchException' in Kveer.XmlRPC.dll: 'fault response contains string value where integer expected [fault response : struct mapped to type Fault : member faultCode mapped to type Int32]'` #16

Open LordVeovis opened 4 years ago

LordVeovis commented 4 years ago

I set the flag to AllowStringFaultCode and it keeps throwing the error Exception thrown: 'CookComputing.XmlRpc.XmlRpcTypeMismatchException' in Kveer.XmlRPC.dll: 'fault response contains string value where integer expected [fault response : struct mapped to type Fault : member faultCode mapped to type Int32]'

Originally posted by @epgeroy in https://github.com/LordVeovis/xmlrpc/issues/7#issuecomment-633566417

LordVeovis commented 4 years ago

epregoy, please provide the steps to reproduce the error.

chitswe commented 3 years ago

I am using this library for consuming odoo xml-rpc api. Odoo not return integer fault code. Even though I set the flag AllowStringFaultCode, it keeps throwing the above error. This is because of this line. If AllowStringFaultCode is true, exception should not be thrown. So the condition should be if(!AllowStringFaultCode) throw;;

If AllowStringFaultCode is set, XmlRpcSerializer will try to extract string fault code again. But here is also another problem. There are two internal struct representing faultCode and faultString. internal struct Fault is for integer fault code and private struct FaultStruct is for string fault code. This two struct should have exact same property name. But faultCode and faultString property in Fault struct start with small letter and FaultCode and FaultString property in FaultStructStringCode start with capital letter. So when serializer can't exact faultCode and faultString, it throw exception because it can't find non optional member faultCode and faultString.

Finally with odoo, there is another problem. Odoo return detail error text as faultCode with empty faultString. When serializer try to parse faultCode, it fails because faultCode returned by odoo is a long text. So I conditionally set faultCode = -1 and set odoo returned faultCode to faultString.

`

if (!AllowStringFaultCode) throw;
FaultStructStringCode faultStrCode;
faultStrCode = (FaultStructStringCode)ParseValue(structNode,typeof(FaultStructStringCode), parseStack, mappingAction);
int faultCode = -1;
if (!int.TryParse(faultStrCode.faultCode, out faultCode))
{
    if (String.IsNullOrEmpty(faultStrCode.faultString))
    {
        fault.faultString = faultStrCode.faultCode;
    }
    else
    {
        fault.faultString = faultStrCode.faultString;
    }
}
else
{
  fault.faultString = faultStrCode.faultString;
}
fault.faultCode = faultCode;

`

Gabinrn commented 3 years ago

Hello @chitswe, i have the same problem and I don't know enough about this part at the moment.

In my case, i'm trying some operation using this git repository to add some PoS Order : https://github.com/ieski/OdooXmlRpc

Actually, i would like to know where can I paste this code you wrote so I don't get this error anymore? Btw do you have any documentation on it ?

Gabin,

Gabinrn commented 3 years ago

Hello @chitswe, i have the same problem and I don't know enough about this part at the moment.

In my case, i'm trying some operation using this git repository to add some PoS Order : https://github.com/ieski/OdooXmlRpc

Actually, i would like to know where can I paste this code you wrote so I don't get this error anymore? Btw do you have any documentation on it ?

Gabin,

UP, hope you can help me @ieski

epgeroy commented 3 years ago

Sorry for the late response, I wasn't looking at my notifications. My conclusion with all this was that Odoo was not consistent. I end up just retrying the request and most of the time it worked in the second request. I'm not working on that project anymore, so, I can't provide any steps right now. Hope it helps.

ezarzone commented 2 years ago

Same here!

dinodipardo commented 4 months ago

Hello, this issue is still current and happens running a request on the latest version of Odoo (17). Is there any update on this?

LordVeovis commented 4 months ago

@dinodipardo Please provide steps to reproduce it.

From what @chitswe said, there is two issue:

dinodipardo commented 4 months ago

Hello,

I digged a bit deeper in the cause of the exception. This is what Odoo is returning as innerxml which is passed in structNode and causing the exception in this try block:

try { fault = (Fault)ParseValue(structNode, typeof(Fault), parseStack, mappingAction); }

faultCode warning -- AccessError You are not allowed to access 'Website Visitor' (website.visitor) records. This operation is allowed for the following groups: - Administration/Settings - Website/Editor and Designer Contact your administrator to request access if necessary. faultString

If needed I can provide more details. Would be great to have this fixed ....

LordVeovis commented 4 months ago

As you said yourself, Odoo is returning a string in the faultCode node, where XML-RPC is expecting a number (https://xmlrpc.com/spec.md). If someone has to fix this, it's on Odoo side. I notice that no such ticket has been open on their github.

You can also use the snippet proposed by @chitswe: https://github.com/LordVeovis/xmlrpc/issues/16#issuecomment-740363969

dinodipardo commented 4 months ago

I'll log a ticket today for this and meanwhile I've implemented a temp fix for this myself. Once the ticket has been logged I'll update here with the ticket ref.