AWS SDK using Mono Timeout error - c#

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

Related

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

Unhandled Exception running eBay C# SDK on Mono

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

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.

Assembly Injection into Live Processes (Mono)

I've recently came across the blog article Monovation: Assembly Injection into Live Processes of Miguel de Icaza.
I've tried to reproduce it with no luck. My command line was
'csharp --attach 5612'
where 5612 was the pid of a simple running mono 'Hello World' console application.
I've got an exception (see the stack trace above).
What I've tried so far:
using Mono 2.10.8 (csharp and csharp2 commands for .NET 4 and 2 )
using Mono 3.2.3 (only csharp command exists)
Q1: Missed I something?
Q2: Is it possible that this virtual machine attach facility (see Monovation: Assembly Injection into Live Processes) is available only in Linux installations? (I am using Windows 7) It sounds an easy answer, but Miguel does not mention platform restriction in his article, and the whole point of mono is the multiplatform, is not it? So I can not believe it so easy.
Q3: What about Mac? Is there any chance it will work in a Mac, or we must look elsewhere?
Thx in advance
Stack trace:
Unhandled Exception:
System.TypeInitializationException: An exception was thrown by the type initializer for Mono.Unix.Native.Syscall ---> System.EntryPointNotFoundException: Mono_Posix_Syscall_get_at_fdcwd
at (wrapper managed-to-native) Mono.Unix.Native.Syscall:get_at_fdcwd ()
at Mono.Unix.Native.Syscall..cctor () [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at Mono.Unix.UnixUserInfo.GetRealUserId () [0x00000] in <filename unknown>:0
at Mono.Unix.UnixUserInfo.GetRealUser () [0x00000] in <filename unknown>:0
at Mono.Attach.VirtualMachine.Attach (System.String agent, System.String args) [0x00000] in <filename unknown>:0
at Mono.ClientCSharpShell..ctor (Mono.CSharp.Evaluator evaluator, Int32 pid) [0x00000] in <filename unknown>:0
at Mono.Driver.Main (System.String[] args) [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: An exception was thrown by the type initializer for Mono.Unix.Native.Syscall ---> System.EntryPointNotFoundException: Mono_Posix_Syscall_get_at_fdcwd
at (wrapper managed-to-native) Mono.Unix.Native.Syscall:get_at_fdcwd ()
at Mono.Unix.Native.Syscall..cctor () [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at Mono.Unix.UnixUserInfo.GetRealUserId () [0x00000] in <filename unknown>:0
at Mono.Unix.UnixUserInfo.GetRealUser () [0x00000] in <filename unknown>:0
at Mono.Attach.VirtualMachine.Attach (System.String agent, System.String args) [0x00000] in <filename unknown>:0
at Mono.ClientCSharpShell..ctor (Mono.CSharp.Evaluator evaluator, Int32 pid) [0x00000] in <filename unknown>:0
at Mono.Driver.Main (System.String[] args) [0x00000] in <filename unknown>:0

Trouble deploying release version of Xamarin.Android app

I'm getting the following error when the app finishes installing on the emulator using Xamarin Release run tool.
GREF GC Threshold: 1800
Unhandled Exception:
System.Net.WebException: Error: NameResolutionFailure
at System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
at CallRestService.Activity1.<OnCreate>m__0 (IAsyncResult ar) [0x00000] in <filename unknown>:0
at System.Net.WebAsyncResult.CB (System.Object unused) [0x00000] in <filename unknown>:0
The emulator is running Android 2.3.3, and the Debug build ran from Xamarin compiler works just fine.
Any hint on why this is happening and how to solve this problem?
Had the same issue. Solved by adding <uses-permission android:name="android.permission.INTERNET" /> to the manifest.

Categories

Resources