Unhandled Exception running eBay C# SDK on Mono - c#

I downloaded the eBay SDK for use in an internal application we are developing. The catch is we are developing on Mono. When I run the eBay Hello World sample on .NET, it displays the following output:
+++++++++++++++++++++++++++++++++++++++
+ Welcome to eBay SDK for .Net Sample +
+ - HelloWorld +
+++++++++++++++++++++++++++++++++++++++
Begin to call eBay API, please wait ...
End to call eBay API, show call result:
eBay official Time: 11/27/2013 3:02:19 PM
When I run it with Mono, I get the following:
Unhandled Exception: eBay.Service.Core.Sdk.ApiException: Exception has been thrown by the target of an invocation.
---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> System.InvalidOperationException: WebServiceBindingAttribute is required on proxy class 'eBay.Service.Core.Sdk.eBayAPIInterfaceService2'.
at System.Web.Services.Protocols.SoapTypeStubInfo..ctor (System.Web.Services.Protocols.LogicalTypeInfo logicalTypeInfo) [0x00000]
at (wrapper managed-to-native) System.Reflection.MonoCMethod:InternalInvoke (object,object[],System.Exception&)
etc...etc...etc...
I found a workaround and will post it in an answer below.

I searched Xamarin's Bugzilla and found nothing, but I found this relevant bug posted in Novell's old Mono Bugzilla: https://bugzilla.novell.com/show_bug.cgi?id=693367
So I dug through the eBay SDK source and found that this was indeed the issue. eBay.Service.Core.Sdk.eBayAPIInterfaceService2 inherits from eBay.Service.Core.Sdk.eBayAPIInterfaceService, which is decorated with a System.Web.Services.WebServiceBindingAttribute.
So I changed eBay.Service.Core.Sdk.eBayAPIInterfaceService2, adding [System.Web.Services.WebServiceBindingAttribute(Name = "eBayAPISoapBinding", Namespace = "urn:ebay:apis:eBLBaseComponents")] so that it now looks like the following:
using System;
using System.Net;
using eBay.Service.Core.Soap;
namespace eBay.Service.Core.Sdk {
/// <summary>
/// Enhanced eBayAPIInterfaceService with GZIP compression support.
/// </summary>
[System.Web.Services.WebServiceBindingAttribute(Name = "eBayAPISoapBinding", Namespace = "urn:ebay:apis:eBLBaseComponents")]
internal class eBayAPIInterfaceService2 : eBayAPIInterfaceService {
...
}
}
I followed the instructions in the eBay SDK for building from the sources and the problem was solved.
Footnote: Incidentally, if this is your first time using Mono to connect to an HTTPS web service, you will likely immediately run into another exception. That one will look like this:
Unhandled Exception: System.Net.WebException: Error getting response stream (Write: The authentication or decryption has failed.): SendFailure ---> System.IO.IOException: The authentication or decryption has failed. ---> Mono.Security.Protocol.Tls.TlsException: Invalid certificate received from server. Error code: 0xffffffff800b010a
at Mono.Security.Protocol.Tls.Handshake.Client.TlsServerCertificate.validateCertificates (Mono.Security.X509.X509CertificateCollection certificates) [0x00000] in <filename unknown>:0
at Mono.Security.Protocol.Tls.Handshake.Client.TlsServerCertificate.ProcessAsTls1 () [0x00000] in <filename unknown>:0
at Mono.Security.Protocol.Tls.Handshake.HandshakeMessage.Process () [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) Mono.Security.Protocol.Tls.Handshake.HandshakeMessage:Process ()
at Mono.Security.Protocol.Tls.ClientRecordProtocol.ProcessHandshakeMessage (Mono.Security.Protocol.Tls.TlsStream handMsg) [0x00000] in <filename unknown>:0
at Mono.Security.Protocol.Tls.RecordProtocol.InternalReceiveRecordCallback (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at Mono.Security.Protocol.Tls.SslStreamBase.AsyncHandshakeCallback (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
at System.Net.HttpWebRequest.GetResponse () [0x00000] in <filename unknown>:0
For the solution to that, go here: http://www.mono-project.com/FAQ:_Security

Related

C# application developed in monomac & xcode not executing on windows with mono framework

I have developed a simple application with a window having a button in Mac using xamarine studio and xcode. I have compiled and created HelloMonoMac.exe
I have installed mono framework on windows machine and opened mono command prompt
mono HelloMonoMac.exe
It gives the following error
System.TypeInitializationException: An exception was thrown by the type initializer for MonoMac.AppKit.NSApplication ---> System.TypeInitializationException: An exception
was thrown by the type initializer for MonoMac.ObjCRuntime.Selector --->
System.DllNotFoundException: /usr/lib/libobjc.dylib
at (wrapper managed-to-native) MonoMac.ObjCRuntime.Selector:GetHandle (string)
at MonoMac.ObjCRuntime.Selector..cctor () [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at MonoMac.AppKit.NSApplication..cctor () [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at HelloMonoMac.MainClass.Main (System.String[] args) [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: An exception was thrown by the type initializer for MonoMac.AppKit.NSApplication ---> System.TypeIn
itializationException: An exception was thrown by the type initializer for MonoMac.ObjCRuntime.Selector ---> System.DllNotFoundException: /usr/lib/libobjc.dylib
at (wrapper managed-to-native) MonoMac.ObjCRuntime.Selector:GetHandle (string)
at MonoMac.ObjCRuntime.Selector..cctor () [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at MonoMac.AppKit.NSApplication..cctor () [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at HelloMonoMac.MainClass.Main (System.String[] args) [0x00000] in <filename unknown>:0
I have also copied MonoMac.dll in the same folder where .exe was.
Is it possible to develop some application in mono with xcode and run it on windows?
I had the same problem, check this:
mono project

C# Couldn't decode XML

I am having a problem where my C# program running in Mono on a Raspberry Pi with Arch Linux gives an error when I try to make it load a key from an XML string or file. It can encrypt and decrypt a message when I tell it to generated its own keys but if I were to take the exact same XML of the generated keys gotten from ToXmlString and give them to it through FromXmlString then it complains about "System.Security.Cryptography.CryptographyException: Couldn't decode XML...".
I should mention that providing any code is probably useless because the exact same code works perfectly when run on Windows or my Arch Linux desktop, the issue obviously has something to do with the ARM Mono implementation for the RPi which after a quick version check is said to be V2 (I have updated it just now) whereas my desktop Arch Linux has V4.
I would therefore like to know if anyone knows of a workaround for this or could report it as a bug to the Mono developers.
EDIT:
Here is the full console output:
Unhandled Exception: System.Security.Cryptography.CryptographicException: Couldn't decode XML ---> System.Security.Cryptography.CryptographicException: Private/public key mismatch
at Mono.Security.Cryptography.RSAManaged.ImportParameters (RSAParameters parameters) [0x00000] in :0
at System.Security.Cryptography.RSACryptoServiceProvider.ImportParameters (RSAParameters parameters) [0x00000] in :0
at System.Security.Cryptography.RSA.FromXmlString (System.String xmlString) [0x00000] in :0
--- End of inner exception stack trace ---
at System.Security.Cryptography.RSA.FromXmlString (System.String xmlString) [0x00000] in :0
at PHPEncryptTest.RSA.EncryptData (System.String strData2Encrypt) [0x00000] in :0
at PHPEncryptTest.Program.Main (System.String[] args) [0x00000] in :0
[ERROR] FATAL UNHANDLED EXCEPTION: System.Security.Cryptography.CryptographicException: Couldn't decode XML ---> System.Security.Cryptography.CryptographicException: Private/public key mismatch
at Mono.Security.Cryptography.RSAManaged.ImportParameters (RSAParameters parameters) [0x00000] in :0
at System.Security.Cryptography.RSACryptoServiceProvider.ImportParameters (RSAParameters parameters) [0x00000] in :0
at System.Security.Cryptography.RSA.FromXmlString (System.String xmlString) [0x00000] in :0
--- End of inner exception stack trace ---
at System.Security.Cryptography.RSA.FromXmlString (System.String xmlString) [0x00000] in :0
at PHPEncryptTest.RSA.EncryptData (System.String strData2Encrypt) [0x00000] in :0
at PHPEncryptTest.Program.Main (System.String[] args) [0x00000] in :0
I have been running mono on RPI for a while now, but i have not gone into the security namespace, since mono best supported on linux and they are porting (lose words) the .Net framework to fit linux we can always expect some bugs, especially when namespaces as security,
check out: Mono System.Security.Cryptography.CryptographicException when running on Linux

mono Google Calendar Api v2 authentication error

We are busy with an application on a rasp pi where we retrieve a google calendar with the Google Calendar API. We wrote it in C# and tested it on Windows where i works fine. When we compile it on the Rasp PI (xbuild) we don't get any errors, but when we run (mono) it we get the following error:
Unhandled Exception: Google.GData.Client.GDataRequestException: Execution of request failed: http://www.google.com/calendar/feeds/USERNAME#gmail.com/private/full?start-min=2013-10-29T14:11:41Z ---> System.Net.WebException: The remote server returned an error: (401) Authorization required.
at System.Net.HttpWebRequest.CheckFinalStatus (System.Net.WebAsyncResult result) [0x00000] in <filename unknown>:0
at System.Net.HttpWebRequest.SetResponseData (System.Net.WebConnectionData data) [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at Google.GData.Client.GDataRequest.Execute () [0x00000] in <filename unknown>:0
at Google.GData.Client.GDataGAuthRequest.Execute (Int32 retryCounter) [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: Google.GData.Client.GDataRequestException: Execution of request failed: http://www.google.com/calendar/feeds/USERNAME#gmail.com/private/full?start-min=2013-10-29T14:11:41Z ---> System.Net.WebException: The remote server returned an error: (401) Authorization required.
at System.Net.HttpWebRequest.CheckFinalStatus (System.Net.WebAsyncResult result) [0x00000] in <filename unknown>:0
at System.Net.HttpWebRequest.SetResponseData (System.Net.WebConnectionData data) [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at Google.GData.Client.GDataRequest.Execute () [0x00000] in <filename unknown>:0
at Google.GData.Client.GDataGAuthRequest.Execute (Int32 retryCounter) [0x00000] in <filename unknown>:0
Could someone help us, we don't see a solution.
We solved the authentification problem with running the following code:
mozroots --import --ask-remove
this is because Mono (by default) doesn't allow outside connections, so you have add it to the certificate list.

AWS SDK using Mono Timeout error

I am trying to run a console app that connects to DynamoDb using mono, it runs fine from visual studio, but after compiling the program and running it on the Ubuntu server I get the following output:
[dev#dev Debug]$ mono Server.exe
Attempting call
Missing method .ctor in assembly /usr/local/lib/mono/gac/System/4.0.0.0__b77a5c561934e089/System.dll, type Mono.Security.Protocol.Tls.CertificateValidationCallback2
Missing method .ctor in assembly /usr/local/lib/mono/gac/System/4.0.0.0__b77a5c561934e089/System.dll, type Mono.Security.Protocol.Tls.CertificateValidationCallback2
Unhandled Exception:
Amazon.Runtime.AmazonServiceException: The request timed out ---> System.Net.WebException: The request timed out
at System.Net.HttpWebRequest.GetRequestStream () [0x00000] in <filename unknown>:0
at Amazon.Runtime.AmazonWebServiceClient.getRequestStreamCallback (IAsyncResult result) [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at Amazon.Runtime.AmazonWebServiceClient.handleHttpWebErrorResponse (Amazon.Runtime.Internal.AsyncResult asyncResult, System.Net.WebException we) [0x00000] in <filename unknown>:0
at Amazon.Runtime.AmazonWebServiceClient.getRequestStreamCallback (IAsyncResult result) [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: Amazon.Runtime.AmazonServiceException: The request timed out ---> System.Net.WebException: The request timed out
at System.Net.HttpWebRequest.GetRequestStream () [0x00000] in <filename unknown>:0
at Amazon.Runtime.AmazonWebServiceClient.getRequestStreamCallback (IAsyncResult result) [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at Amazon.Runtime.AmazonWebServiceClient.handleHttpWebErrorResponse (Amazon.Runtime.Internal.AsyncResult asyncResult, System.Net.WebException we) [0x00000] in <filename unknown>:0
at Amazon.Runtime.AmazonWebServiceClient.getRequestStreamCallback (IAsyncResult result) [0x00000] in <filename unknown>:0
This is the code I was running
using Amazon.DynamoDBv2;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace Server
{
class Program
{
static void Main(string[] args)
{
// adding this has no affect, this is never even called
ServicePointManager.ServerCertificateValidationCallback = (sender, cert, chain, error) => true;
using (var ddb = new AmazonDynamoDBClient(DynamoServer.Region)) egion))
{
Console.WriteLine("Attempting call");
Console.WriteLine(ddb.ListTables());
}
}
}
}
I tried with both Mono 3.0.12 and 2.10.8 and both had the same error, I'm using AWSSDK 1.5.26.3. The project I used to build Server.exe target .net 4.0, I simply ran xbuild Server.csproj to build it
I would guess that it has something to do with ssl and the Missing method messages, can anyone offer any suggestions or ways to debug this further? I can't seem to find reports of this same error happening previously.
And immediately after posting this I found this old bug that lead me to the problem
The problem was from my including an old Mono.Security.dll that was a requirement for Thrift. By deleting that out of date dll I was able run without error

"The authentication or decryption has failed" exception when connecting to Apple Push Notification Service

I keep getting "The authentication or decryption has failed" errors while connecting to APNS. I have simple console application in C# that tries to connect to gateway.sandbox.push.apple.com an exception is thrown:
Unhandled Exception: System.IO.IOException: The authentication or decryption has failed. ---> Mono.Security.Protocol.Tls.TlsException: The authentication or decryption has failed.
at Mono.Security.Protocol.Tls.RecordProtocol.ProcessAlert (AlertLevel alertLevel, AlertDescription alertDesc) [0x00000] in <filename unknown>:0
at Mono.Security.Protocol.Tls.RecordProtocol.InternalReceiveRecordCallback (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at Mono.Security.Protocol.Tls.SslStreamBase.AsyncHandshakeCallback (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.IO.IOException: The authentication or decryption has failed. ---> Mono.Security.Protocol.Tls.TlsException: The authentication or decryption has failed.
at Mono.Security.Protocol.Tls.RecordProtocol.ProcessAlert (AlertLevel alertLevel, AlertDescription alertDesc) [0x00000] in <filename unknown>:0
at Mono.Security.Protocol.Tls.RecordProtocol.InternalReceiveRecordCallback (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at Mono.Security.Protocol.Tls.SslStreamBase.AsyncHandshakeCallback (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
I also get above exception when connecting with certmgr:
certmgr -ssl ssl://gateway.sandbox.push.apple.com:2195
I manually imported Enrtust root certificates to Trust store but it didn't help.
OSX 10.7, Mono 2.10.8

Categories

Resources