Identify Cause of Serialization Error Coming From Inside Library/NuGet Package - c#

Sometimes when calling the Mastercard MATCH API via the NuGet package MasterCard-Match, I will get a JSON deserialization exception:
Unexpected character encountered while parsing value: <. Path '',
line 0, position 0.
The exception is from MasterCard.Core with an inner exception from Newtonsoft.Json, both have the same message.
It looks like I'm receiving HTML ('<' at line 0, position 0) and the library is trying to deserialize it as JSON. My guess is that the MasterCard API is sending back an HTML error page instead of a JSON error. But I can't step into the function call to "see" the response its getting before throwing the exception.
As per the documentation I create a request map with the provided data and call TerminationInquiryRequest.Create(map), this is the line the exception is thrown. This function call is a black box, I can't step into it, it just throws the exception.
try
{
RequestMap requestMap = CreateRequestMap();
// This line throws the exception
TerminationInquiryRequest apiResponse = TerminationInquiryRequest.Create(requestMap);
}
catch(Exception e)
{
// Exception handling
}
I've made over 11,000+ calls using this library and only 32 have had this error, but of course I get to hear about it every time it happens.
Is there any way to debug libraries that I'm not aware of, or a way to view the response that the library is getting from the API?
I already have some logic to wait and retry the call if it fails.

Related

CodecQuery.FindAllAsync crashes through try/catch when querying Audio codecs without subtype

Blank project repo with problematic code
I have the following code for querying all the supported Audio codec following this article using CodecQuery.FindAllAsync
try
{
var query = new CodecQuery();
var queryResult = await query.FindAllAsync(CodecKind.Audio, CodecCategory.Encoder, "");
var subTypes = queryResult
.SelectMany(q => q.Subtypes)
.ToHashSet();
// Other codes
}
catch (Exception ex)
{
Debug.WriteLine(ex);
throw;
}
As the documentation mentioned,
To specify that all codecs of the specified kind and category should be returned, regardless of what media subtypes are supported, specify an empty string ("") or null for this parameter.
For empty string "", it works for CodecKind.Video but not for Audio (for both CodecCategory of Encoder or Decoder). If I specify a subtype, then it does not crash, for example:
var queryResult = await query.FindAllAsync(CodecKind.Audio, CodecCategory.Encoder, CodecSubtypes.AudioFormatMP3);
What is strange about that is that even though I have a try/catch with generic Exception, the app just crashes through that one and show this instead:
I have tried restarting Windows, uninstall the UWP app and make a clean build. What is happening? How do I query all available audio codecs?
Update: after changing Debug setting, I could trace the error message:
Unhandled exception at 0x00007FFDCE5FD759 (KernelBase.dll) in ******.exe: 0xC0000002: The requested operation is not implemented.
After my testing, the content of this document is correct. When I set “” for the third parameter to find all audio codecs, the code works well. So there is not an error in this document.
You could choose the Debug options, and change Debugger type from Managed Only to Mixed. It won't fix your exception, but you can trace it with the debugger. You could refer to this reply to get more information.

Why is system.exception not serializable in send message shape?

I am testing the exception handling of my BizTalk 2010 orchestration. The orchestration has one scope shape with one catch shape attached to it.
The scope shape's transaction type is set to 'NONE' so I can work with the .NET exception. Inside the catch is a construct message shape with a message assignment shape. The message assignment shape is using the active message type from the receive shape.
When the orchestration runs it suspends on the send message shape. The error is:
Type System.Xml.XmlDocument in Assembly System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=xxx is not marked as serializable.
My project is set up such that for testing purposes I can process either an incoming BizTalk message or an XML file (via the test editor.)
I can take the XML that is submitted to the receive shape, save it as an XML file and process the XML file.
To test the exception handling I have purposely
coded a database insert that will fail. The full database error is written to a log file and a new exception is throw with a message like this:
Failed to process BLAH request to completion - Message Processor - Image ID: ABC Note ID: XYZ. When running the XML file, the application throws the error
in the expected place and the error is caught back at the test editor. I am able to serialize the error message in the test editor function.
However, when running from BizTalk I get the error. A correlation set has been defined with these properties:
BTS.ReceivePortName,ErrorReport.ErrorType,ErrorReport.InboundTransportLocation.
The code in the assign shape is as follows.
msgFail = InputMsg;
msgFail(ErrorReport.ErrorType) = "FailedMessage";
msgFail(ErrorReport.Description) = ex.Message;
msgFail(ErrorReport.FailureCategory) = 0;
msgFail(ErrorReport.FailureCode) = "";
msgFail(ErrorReport.InboundTransportLocation) = InputMsg(BTS.InboundTransportLocation);
msgFail(ErrorReport.RoutingFailureReportID) = System.Convert.ToString(System.Guid.NewGuid());
msgFail is the message I am trying to send.
InputMsg is the active message type from the initial receive shape. It is a multi-part message type tied to a schema that validates.
ex is the exception object name in the catch shape. It is of type System.Exception.
I've read many posts about how to set the properties for the scope and catch shapes to be able to use the exception object, but it is still not working.
I am making an assumption that since I can serialize the error message when running from the XML file that my problem is with how my orchestration is getting the exception.
If you have the ESB Toolkit installed you can use that to create your fault messages.
e.g
eSBFault = Microsoft.Practices.ESB.ExceptionHandling.ExceptionMgmt.CreateFaultMessage();
eSBFault.FailureCategory= "General System Exception";
eSBFault.FaultCode = "500";
eSBFault.FaultDescription = orchestrationName + ": " + ex.Message;
eSBFault.FaultSeverity = Microsoft.Practices.ESB.ExceptionHandling.FaultSeverity.Error;
eSBFault.Scope = "Scope Name";
Microsoft.Practices.ESB.ExceptionHandling.ExceptionMgmt.AddMessage(eSBFault, InputMsg);
Note 1: orchestrationName is a variable that was set earlier in the Orchestration
orchestrationName = Microsoft.XLANGs.Core.Service.RootService.Name;
Note 2: Your msgFail is eSBFault in this example, but you can call it msgFail as well. It is of Message Type Microsoft.Practices.ESB.ExceptionHandling.Schemas.Faults.FaultMessage

dotnetrdf xml exception using QueryWithResultSet

I have an asp.net project in which, I would like to query DBPedia.
Using the following code I am getting an error:
public string testEndpoint()
{
//TEST02
SparqlRemoteEndpoint endpoint = new SparqlRemoteEndpoint(new Uri("http://dbpedia.org/sparql"), "http://dbpedia.org");
string res = "";
//Make a SELECT query against the Endpoint
SparqlResultSet results = endpoint.QueryWithResultSet("SELECT ?year WHERE {dbpedia:Rihanna dbpedia-owl:birthYear ?year}");
foreach (SparqlResult result in results)
{
res = result.ToString();
Console.WriteLine(result.ToString());}
Error message: "An exception of type 'System.Xml.XmlException' occurred in dotNetRDF.dll but was not handled in user code".
Even if I handle the exception the method cannot be executed. Regarding the details it says that there is an invalid XML-version 1.1.
As the XML comes from DBPedia I don't know how to change the xml version or how else I can handle this problem.
Virtuoso, which is the triple store used behind the dbpedia SPARQL endpoint, has updated its XML result generation. They replaced the XML version 1.0 with 1.1 in this commit. This causes the exception in the dotNetRDF parser.
Later on Virtuoso reverted the changes in the XML header. Hopefully DBPedia will update their binaries soon, so the old XML header appears again in the SPARQL results.
Source: http://github.com/openlink/virtuoso-opensource/issues/405

Why QBFC is throwing exception with message "String too long" instead of response containing error code?

I have a C# program that is using QBFCv13 to create 46 customers in QuickBooks Pro 2014.
When the program runs, I get an exception with message "String too long.". I am guessing it's probably caused by one of the customer name is too long so I test the program to create 2 customers with one long name. This time I didn't get an exception. I get a response list with one response containing error code and the other response without error.
I am confused. Why in certain case I get an exception? The message doesn't contain any more message than "String too long". I am wondering if there is something else I can do to figure what is causing this "String too long" error.
Thanks.
Try enabling verbose logging and see if it tells you what the error is.
https://intuitpartnerplatform.lc.intuit.com/questions/177198-troubleshooting-sdk-issues

Twitterizer2 1.2.4 Streaming API exception - Unexpected end when deserializing object

Any help would be appreciated. I'm getting an exception thrown during deserialization inside JSON.Net:
Unexpected end when deserializing object. Line 216, position 2.
My calling code:
var asyncResult = s.StartPublicStream(streamErrorCallback, statusCreatedCallback, statusDeletedCallback, eventCallback, rawJsonCallback);
Setting a breakpoint in my rawJsonCallback handler shows (what appears to be) valid JSON coming back from the API.
Added the source for Twitterizer2 and JSON.Net, looks like Twitterizer.Streaming.TwitterStream.ParseMessage(string) is failing here near line 520
var user = obj.SelectToken("user", false);
if (user != null)
{
if (statusCreatedCallback != null && user.HasValues)
{
statusCreatedCallback(JsonConvert.DeserializeObject<TwitterStatus>(ConvertJTokenToString(obj)));
}
return;
}
On the call to DeserializeObject().
Newtonsoft.Json.Serliazation.JsonSerializerInternalReader.PopulateObject() fails because the reader.TokenType == None.
I suspect there is a discrepancy between the contract type/values and the object coming back from the API, but I'm not sure how to test further. Wasn't able to get the Json.Net source to compile so I can't step through it.
The problem is that Twitterizer 2.4 is using NewtonSoft.Json v4.08, which breaks it. Install Newtonsoft.Json v4.03, and you'll be fine.
Maybe this could solve your issue. I had a simillar one when I wanted to use the twitterize with JSON.NET 4.5
I follow the steps that someone mentioned on github and then I've compiled the whole source code with the new json lib and voilá ;)

Categories

Resources