Sporadic failure of System.Net.FtpClient.FileExists - c#

I am trying to move to using System.Net.FtpClient, but things are not working as expected.
Running the code below, it seems like even though IsConnected returns true, a directly following call to FileExists() calls Connect() (which means the connection is lost exactly between the calls?). However, as Connect() can fail every now and then, this also results in a failing FileExists() (where failing means it throws Connection refused).
Is there anything wrong with my code? Is this something to be expected, i.e. should I be prepared to retry everything I do with an FtpClient instance? Is there any flag to set to retry automatically?
string myPath = ..;
string myTempPath = myPath+".tmp";
_client = GetClient(_ioc, false);
var _stream = _client.OpenWrite(myTempPath);
//write to stream
_stream.Close();
Android.Util.Log.Debug("NETFTP", "connected: " + _client.IsConnected.ToString()); //always outputs true
if (_client.FileExists(myPath) //sporadically throws, see below
_client.DeleteFile(myPath);
where GetClient() is implemented as using my custom "retry-loop" to hande sporadic connecting failures.
private static T DoInRetryLoop<T>(Func<T> func)
{
double timeout = 30.0;
double timePerRequest = 1.0;
var startTime = DateTime.Now;
while (true)
{
var attemptStartTime = DateTime.Now;
try
{
return func();
}
catch (System.Net.Sockets.SocketException e)
{
if ((e.ErrorCode != 10061) || (DateTime.Now > startTime.AddSeconds(timeout)))
{
throw;
}
double secondsSinceAttemptStart = (DateTime.Now - attemptStartTime).TotalSeconds;
if (secondsSinceAttemptStart < timePerRequest)
{
Thread.Sleep(TimeSpan.FromSeconds(timePerRequest - secondsSinceAttemptStart));
}
}
}
}
internal FtpClient GetClient(IOConnectionInfo ioc)
{
FtpClient client = new FtpClient();
if ((ioc.UserName.Length > 0) || (ioc.Password.Length > 0))
client.Credentials = new NetworkCredential(ioc.UserName, ioc.Password);
else
client.Credentials = new NetworkCredential("anonymous", "");
Uri uri = IocPathToUri(ioc.Path);
client.Host = uri.Host;
if (!uri.IsDefaultPort)
client.Port = uri.Port;
client.EnableThreadSafeDataConnections = false;
client.EncryptionMode = ConnectionSettings.FromIoc(ioc).EncryptionMode;
Func<FtpClient> connect = () =>
{
client.Connect();
return client;
};
return DoInRetryLoop(connect);
}
This is the exception which appears sporadically:
System.Net.Sockets.SocketException : Connection refused
10-24 13:08:07.487 I/mono-stdout(24073): at System.Net.Sockets.SocketAsyncResult.CheckIfThrowDelayedException () [0x00017] in /Users/builder/data/lanes/3540/1cf254db/source/mono/mcs/class/System/System.Net.Sockets/SocketAsyncResult.cs:127
at System.Net.Sockets.SocketAsyncResult.CheckIfThrowDelayedException () [0x00017] in /Users/builder/data/lanes/3540/1cf254db/source/mono/mcs/class/System/System.Net.Sockets/SocketAsyncResult.cs:127
10-24 13:08:07.487 I/mono-stdout(24073): at System.Net.Sockets.Socket.EndConnect (IAsyncResult result) [0x0002f] in /Users/builder/data/lanes/3540/1cf254db/source/mono/mcs/class/System/System.Net.Sockets/Socket.cs:1593
at System.Net.Sockets.Socket.EndConnect (IAsyncResult result) [0x0002f] in /Users/builder/data/lanes/3540/1cf254db/source/mono/mcs/class/System/System.Net.Sockets/Socket.cs:1593
at System.Net.FtpClient.FtpSocketStream.Connect (System.String host, Int32 port, FtpIpVersion ipVersions) [0x0011a] in [my source folder]src
etftpandroid\System.Net.FtpClient\FtpSocketStream.cs:611
10-24 13:08:07.487 I/mono-stdout(24073): at System.Net.FtpClient.FtpSocketStream.Connect (System.String host, Int32 port, FtpIpVersion ipVersions) [0x0011a] in [my source folder]src
etftpandroid\System.Net.FtpClient\FtpSocketStream.cs:611
10-24 13:08:07.487 I/mono-stdout(24073): at (wrapper remoting-invoke-with-check) System.Net.FtpClient.FtpSocketStream:Connect (string,int,System.Net.FtpClient.FtpIpVersion)
at (wrapper remoting-invoke-with-check) System.Net.FtpClient.FtpSocketStream:Connect (string,int,System.Net.FtpClient.FtpIpVersion)
10-24 13:08:07.487 I/mono-stdout(24073): at System.Net.FtpClient.FtpClient.Connect () [0x000ce] in [my source folder]src
etftpandroid\System.Net.FtpClient\FtpClient.cs:807
at System.Net.FtpClient.FtpClient.Connect () [0x000ce] in [my source folder]src
etftpandroid\System.Net.FtpClient\FtpClient.cs:807
at System.Net.FtpClient.FtpClient.Execute (System.String command) [0x00136] in [my source folder]src
etftpandroid\System.Net.FtpClient\FtpClient.cs:735
10-24 13:08:07.487 I/mono-stdout(24073): at System.Net.FtpClient.FtpClient.Execute (System.String command) [0x00136] in [my source folder]src
etftpandroid\System.Net.FtpClient\FtpClient.cs:735
10-24 13:08:07.487 I/mono-stdout(24073): at System.Net.FtpClient.FtpClient.Execute (System.String command, System.Object[] args) [0x00001] in [my source folder]src
etftpandroid\System.Net.FtpClient\FtpClient.cs:694
at System.Net.FtpClient.FtpClient.Execute (System.String command, System.Object[] args) [0x00001] in [my source folder]src
etftpandroid\System.Net.FtpClient\FtpClient.cs:694
10-24 13:08:07.487 I/mono-stdout(24073): at System.Net.FtpClient.FtpClient.DirectoryExists (System.String path) [0x0005d] in [my source folder]src
etftpandroid\System.Net.FtpClient\FtpClient.cs:2679
at System.Net.FtpClient.FtpClient.DirectoryExists (System.String path) [0x0005d] in [my source folder]src
etftpandroid\System.Net.FtpClient\FtpClient.cs:2679
10-24 13:08:07.487 I/mono-stdout(24073): at System.Net.FtpClient.FtpClient.FileExists (System.String path, FtpListOption options) [0x0001c] in [my source folder]src
etftpandroid\System.Net.FtpClient\FtpClient.cs:2751
10-24 13:08:07.487 I/mono-stdout(24073): at System.Net.FtpClient.FtpClient.FileExists (System.String path) [0x00001] in [my source folder]src
etftpandroid\System.Net.FtpClient\FtpClient.cs:2733
at System.Net.FtpClient.FtpClient.FileExists (System.String path, FtpListOption options) [0x0001c] in [my source folder]src
etftpandroid\System.Net.FtpClient\FtpClient.cs:2751
at System.Net.FtpClient.FtpClient.FileExists (System.String path) [0x00001] in [my source folder]src
etftpandroid\System.Net.FtpClient\FtpClient.cs:2733

It turned out that the FtpClient was reconnecting due to some unexpected response from the client which triggered the reconnect because of "stale data". My solution was to derive my own class from FtpClient which overrides the Connect() method using the DoInRetryLoop as posted in the question.
Unfortunately, this only works with either EnableThreadSafeDataConnections=false or with overriding the "CloneConnection" method as well. The latter required me to make it virtual.

Related

Entity Framework Core SaveChanges causes error on Mac

I'm currently trying to build an EF core project, but when I call db.SaveChanges() I get the following error:
System.TypeInitializationException: The type initializer for 'Microsoft.Data.SqlClient.InOutOfProcHelper' threw an exception. ---> System.EntryPointNotFoundException: GetModuleHandle assembly:<unknown assembly> type:<unknown type> member:(null)
at (wrapper managed-to-native) Microsoft.Data.Common.SafeNativeMethods.GetModuleHandle(string)
at Microsoft.Data.SqlClient.InOutOfProcHelper..ctor () [0x00006] in <a1c8e16fd44948ee8c6a463f125e71f0>:0
at Microsoft.Data.SqlClient.InOutOfProcHelper..cctor () [0x00000] in <a1c8e16fd44948ee8c6a463f125e71f0>:0
--- End of inner exception stack trace ---
at Microsoft.Data.SqlClient.SqlConnectionString..ctor (System.String connectionString) [0x0000d] in <a1c8e16fd44948ee8c6a463f125e71f0>:0
at Microsoft.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions (System.String connectionString, Microsoft.Data.Common.DbConnectionOptions previous) [0x00000] in <a1c8e16fd44948ee8c6a463f125e71f0>:0
at Microsoft.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup (Microsoft.Data.Common.DbConnectionPoolKey key, Microsoft.Data.ProviderBase.DbConnectionPoolGroupOptions poolOptions, Microsoft.Data.Common.DbConnectionOptions& userConnectionOptions) [0x0003e] in <a1c8e16fd44948ee8c6a463f125e71f0>:0
at Microsoft.Data.SqlClient.SqlConnection.ConnectionString_Set (Microsoft.Data.Common.DbConnectionPoolKey key) [0x00008] in <a1c8e16fd44948ee8c6a463f125e71f0>:0
at Microsoft.Data.SqlClient.SqlConnection.set_ConnectionString (System.String value) [0x0006b] in <a1c8e16fd44948ee8c6a463f125e71f0>:0
at Microsoft.Data.SqlClient.SqlConnection..ctor (System.String connectionString, Microsoft.Data.SqlClient.SqlCredential credential) [0x00006] in <a1c8e16fd44948ee8c6a463f125e71f0>:0
at Microsoft.Data.SqlClient.SqlConnection..ctor (System.String connectionString) [0x00000] in <a1c8e16fd44948ee8c6a463f125e71f0>:0
at (wrapper remoting-invoke-with-check) Microsoft.Data.SqlClient.SqlConnection..ctor(string)
at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerConnection.CreateDbConnection () [0x00006] in <5c775909c1cf40629fd2452310cf8cc1>:0
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.get_DbConnection () [0x0000a] in <5314a29febc14288a1bc53bf7b46d725>:0
at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.CreateCommand (Microsoft.EntityFrameworkCore.Storage.RelationalCommandParameterObject parameterObject, System.Guid commandId, Microsoft.EntityFrameworkCore.Diagnostics.DbCommandMethod commandMethod) [0x0005c] in <5314a29febc14288a1bc53bf7b46d725>:0
at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReader (Microsoft.EntityFrameworkCore.Storage.RelationalCommandParameterObject parameterObject) [0x00027] in <5314a29febc14288a1bc53bf7b46d725>:0
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1+Enumerator[T].InitializeReader (Microsoft.EntityFrameworkCore.DbContext _, System.Boolean result) [0x00050] in <5314a29febc14288a1bc53bf7b46d725>:0
at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.Execute[TState,TResult] (TState state, System.Func`3[T1,T2,TResult] operation, System.Func`3[T1,T2,TResult] verifySucceeded) [0x00011] in <5c775909c1cf40629fd2452310cf8cc1>:0
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1+Enumerator[T].MoveNext () [0x00193] in <5314a29febc14288a1bc53bf7b46d725>:0
at System.Linq.Enumerable.SingleOrDefault[TSource] (System.Collections.Generic.IEnumerable`1[T] source) [0x00041] in /Users/builder/jenkins/workspace/build-package-osx-mono/2019-10/external/bockbuild/builds/mono-x64/external/corefx/src/System.Linq/src/System/Linq/Single.cs:104
at (wrapper dynamic-method) System.Object.lambda_method(System.Runtime.CompilerServices.Closure,Microsoft.EntityFrameworkCore.Query.QueryContext)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult] (System.Linq.Expressions.Expression query) [0x00075] in <a3dbe48366454fdbb51dfeeb0b5c4997>:0
at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult] (System.Linq.Expressions.Expression expression) [0x00000] in <a3dbe48366454fdbb51dfeeb0b5c4997>:0
at System.Linq.Queryable.FirstOrDefault[TSource] (System.Linq.IQueryable`1[T] source) [0x0000e] in /Users/builder/jenkins/workspace/build-package-osx-mono/2019-10/external/bockbuild/builds/mono-x64/external/corefx/src/System.Linq.Queryable/src/System/Linq/Queryable.cs:729
at GenericEFIAPI.RTATenantsDatabaseHelper.convertTenant (System.String tenantId, GenericEFIAPI.configObject config, GenericEFIAPI.models.TenantDatabase db) [0x002d2] in /Users/jft/projects/GenericAPI/GenericEFIAPI/RTATenantsDatabaseHelper.cs:108
at GenericEFIAPI.Program+<>c__DisplayClass1_0.<Main>b__0 (GenericEFIAPI.Program+Options o) [0x000c1] in /Users/jft/projects/GenericAPI/GenericEFIAPI/Program.cs:78
at CommandLine.ParserResultExtensions.WithParsed[T] (CommandLine.ParserResult`1[T] result, System.Action`1[T] action) [0x00011] in <68c69d6559fd42bc897efd2a474dfda9>:0
at GenericEFIAPI.Program.Main (System.String[] args) [0x00013] in /Users/jft/projects/GenericAPI/GenericEFIAPI/Program.cs:38
I've tried looking around on google for some help, but have come up empty so far... Anybody have any ideas? I'm trying to connect to sql server and using DbContextOptionsBuilder().UseSqlServer() for the underlying connection.
I'm currently getting my old windows laptop up and running to see if it is because I'm on a Mac or not, but I thought I would get this question out there in the mean time.
Alright! So I'm not 100% sure why my connection string is failing when passing it directly to the DbContextOptionsBuilder().UseSqlServer(connectionString), but if I create a SqlConnection object before that, and pass that as the parameter to UseSqlServer, it works.
So got a workaround, but not sure why the error happens when just passing the connection string.

C# Google OAUTH2 using OWIN on Mono results in "System.Web.HttpException (0x80004005): headers have already been sent"

I've followed a number of tutorials for adding google OAUTH2 authentication to an existing MVC project, but I end up with the same issue involving a 404 to the client and the following trace generated:
System.Web.HttpException (0x80004005): headers have already been sent
at System.Web.HttpResponse.set_StatusCode (System.Int32 value) [0x00012] in <d31574f4ab6745f49b1626160268508f>:0
at System.Web.HttpResponseWrapper.set_StatusCode (System.Int32 value) [0x00000] in <d31574f4ab6745f49b1626160268508f>:0
at Microsoft.Owin.Host.SystemWeb.OwinCallContext.Microsoft.Owin.Host.SystemWeb.CallEnvironment.AspNetDictionary.IPropertySource.SetResponseStatusCode (System.Int32 value) [0x00000] in <90ddfcf805444e2e8c4aafed95112b04>:0
at Microsoft.Owin.Host.SystemWeb.CallEnvironment.AspNetDictionary.set_ResponseStatusCode (System.Int32 value) [0x00000] in <90ddfcf805444e2e8c4aafed95112b04>:0
at Microsoft.Owin.Host.SystemWeb.CallEnvironment.AspNetDictionary.PropertiesTrySetValue (System.String key, System.Object value) [0x00257] in <90ddfcf805444e2e8c4aafed95112b04>:0
at Microsoft.Owin.Host.SystemWeb.CallEnvironment.AspNetDictionary.System.Collections.Generic.IDictionary<System.String,System.Object>.set_Item (System.String key, System.Object value) [0x00000] in <90ddfcf805444e2e8c4aafed95112b04>:0
at Microsoft.Owin.OwinResponse.Set[T] (System.String key, T value) [0x00006] in <0850b9daadb8416ca216d3d37f3983d1>:0
at Microsoft.Owin.OwinResponse.set_StatusCode (System.Int32 value) [0x00000] in <0850b9daadb8416ca216d3d37f3983d1>:0
at Microsoft.Owin.OwinResponse.Redirect (System.String location) [0x00000] in <0850b9daadb8416ca216d3d37f3983d1>:0
at Microsoft.Owin.Security.Google.GoogleOAuth2AuthenticationHandler.InvokeReplyPathAsync () [0x002c9] in <dcea7978bc3a4441882e0efa5daced72>:0
at Microsoft.Owin.Security.Google.GoogleOAuth2AuthenticationHandler.InvokeAsync () [0x00068] in <dcea7978bc3a4441882e0efa5daced72>:0
at Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware`1[TOptions].Invoke (Microsoft.Owin.IOwinContext context) [0x00109] in <1cc66b39b04f4b919683032a3a12cc4f>:0
at Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContextStage.RunApp (System.Func`2[T,TResult] entryPoint, System.Collections.Generic.IDictionary`2[TKey,TValue] environment, System.Threading.Tasks.TaskCompletionSource`1[TResult] tcs, Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.StageAsyncResult result) [0x0007e] in <90ddfcf805444e2e8c4aafed95112b04>:0
at Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware`1[TOptions].Invoke (Microsoft.Owin.IOwinContext context) [0x00183] in <1cc66b39b04f4b919683032a3a12cc4f>:0
at Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware`1[TOptions].Invoke (Microsoft.Owin.IOwinContext context) [0x00183] in <1cc66b39b04f4b919683032a3a12cc4f>:0
at Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContextStage.RunApp (System.Func`2[T,TResult] entryPoint, System.Collections.Generic.IDictionary`2[TKey,TValue] environment, System.Threading.Tasks.TaskCompletionSource`1[TResult] tcs, Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.StageAsyncResult result) [0x0007e] in <90ddfcf805444e2e8c4aafed95112b04>:0
at Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.DoFinalWork (Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.StageAsyncResult result) [0x0007d] in <90ddfcf805444e2e8c4aafed95112b04>:0
at Microsoft.Owin.Host.SystemWeb.Infrastructure.ErrorState.Rethrow () [0x00000] in <90ddfcf805444e2e8c4aafed95112b04>:0
at Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.StageAsyncResult.End (System.IAsyncResult ar) [0x0001d] in <90ddfcf805444e2e8c4aafed95112b04>:0
at Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.EndFinalWork (System.IAsyncResult ar) [0x00006] in <90ddfcf805444e2e8c4aafed95112b04>:0
at System.Web.AsyncInvoker.<doAsyncCallback>b__8_0 (System.Object ores) [0x00007] in <d31574f4ab6745f49b1626160268508f>:0
I am using mono on linux, and I'm guessing it has something to do with the system web.config or routing. I've seen similar questions/answers but nothing I've read relates to this exact error. Is there a module I need to unregister or some other option that could be causing this?

MySql Connection. Value cannot be null. Parameter name: type

When I run my code below, I get this error at runtime:
Value cannot be null. Parameter name: type
And here is the full exception:
MySql.Data.MySqlClient.MySqlException: Unable to create plugin for authentication method 'mysql_native_password'.
Please see inner exception for details. --->
System.ArgumentNullException: Value cannot be null.
Parameter name: type
at System.Activator.CreateInstance (System.Type type, System.Boolean nonPublic) [0x00006] in /Users/builder/data/lanes/3511/77cb8568/source/mono/mcs/class/referencesource/mscorlib/system/activator.cs:192
at System.Activator.CreateInstance (System.Type type) [0x00000] in /Users/builder/data/lanes/3511/77cb8568/source/mono/mcs/class/referencesource/mscorlib/system/activator.cs:134
at MySql.Data.MySqlClient.Authentication.AuthenticationPluginManager.CreatePlugin (System.String method) [0x00019] in <4adf5733b5f24682b339d246b115a2af>:0
--- End of inner exception stack trace ---
at MySql.Data.MySqlClient.Authentication.AuthenticationPluginManager.CreatePlugin (System.String method) [0x0003c] in <4adf5733b5f24682b339d246b115a2af>:0
at MySql.Data.MySqlClient.Authentication.AuthenticationPluginManager.GetPlugin (System.String method) [0x0001e] in <4adf5733b5f24682b339d246b115a2af>:0
at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.GetPlugin (System.String method, MySql.Data.MySqlClient.NativeDriver driver, System.Byte[] authData) [0x0001f] in <4adf5733b5f24682b339d246b115a2af>:0
at MySql.Data.MySqlClient.NativeDriver.Authenticate (System.String authMethod, System.Boolean reset) [0x00029] in <4adf5733b5f24682b339d246b115a2af>:0
at MySql.Data.MySqlClient.NativeDriver.Open () [0x00223] in <4adf5733b5f24682b339d246b115a2af>:0
at MySql.Data.MySqlClient.Driver.Open () [0x0000b] in <4adf5733b5f24682b339d246b115a2af>:0
at MySql.Data.MySqlClient.Driver.Create (MySql.Data.MySqlClient.MySqlConnectionStringBuilder settings) [0x00027] in <4adf5733b5f24682b339d246b115a2af>:0
The error occured when I open the connection.
Here is my code:
public string connString()
{
MySqlConnectionStringBuilder builder = new MySqlConnectionStringBuilder();
builder.Server = "localhost";
builder.Port = 3306;
builder.UserID = "root";
builder.Password = "root1234";
builder.Database = "tips-db";
return builder.ToString();
}
public bool Connect()
{
conn = new MySqlConnection();
conn.ConnectionString = connString();
try
{
conn.Open();
}
catch (Exception e)
{
Toast.MakeText(Application.Context, e.InnerException.Message, ToastLength.Long).Show();
conn.Close();
return false;
}
conn.Close();
return true;
}

Cannot connect remote server to smartfox with unity3d

I'm trying to connect smartfoxserver with unity3d. local machine is working fine. But when I've tried on my server ip like xx.xx.xx.xx, given error like follow,
What should I do?
Http error creating http connection: System.Net.Sockets.SocketException: Connection refused
at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP, Boolean requireSocketPolicy) [0x00000] in <filename unknown>:0
at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP) [0x00000] in <filename unknown>:0
at System.Net.Sockets.TcpClient.Connect (System.Net.IPEndPoint remote_end_point) [0x00000] in <filename unknown>:0
at System.Net.Sockets.TcpClient.Connect (System.Net.IPAddress[] ipAddresses, Int32 port) [0x00000] in <filename unknown>:0
UnityEngine.Debug:Log(Object)
SFS2X_Connect:OnConnection(BaseEvent) (at Assets/SFS2X_Connect.cs:31)
Sfs2X.Core.EventDispatcher:DispatchEvent(BaseEvent)
Sfs2X.SmartFox:ProcessEvents()
SFS2X_Connect:Update() (at Assets/SFS2X_Connect.cs:37)
connection code is shown below
public class SFS2X_Connect : MonoBehaviour {
public string ServerIP = "xxx.xxx.xxx.xxx";
public int ServerPort = 9933;
SmartFox sfs;
void Start () {
sfs = new SmartFox ();
sfs.ThreadSafeMode = true;
sfs.AddEventListener (SFSEvent.CONNECTION, OnConnection);
sfs.Connect (ServerIP, ServerPort);
}
void OnConnection(BaseEvent evt)
{
if ((bool)evt.Params ["success"]) {
Debug.Log ("Successfully Connected");
}
else {
Debug.Log ((string)evt.Params["errorMessage"]);
}
}
void Update () {
sfs.ProcessEvents();
}
}
Create a ConfigData then pass it to sfs for connection :
ConfigData cfg = new ConfigData();
cfg.Host = "x.x.x.x";
cfg.Port = 9932;
cfg.Zone = loginZone;
cfg.Debug = true;
smartFox.Connect(cfg);

WebClient: (System.Net.WebException) Error getting response stream (ReadDone1): ReceiveFailure

This is a MonoTouch application. I see errors out in the field with this exception. I see other SO quesitons, but nothing seems to be solving my issue. Could this be related to maxRequestLength on the server, or executionTimeout? I really have NO ideas...
I am not using a WebRequest, i'm using a WebClient. Please Help!
STACK TRACE
System.Net.WebException: Error getting response stream (ReadDone1): ReceiveFailure
at System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
at System.Net.HttpWebRequest.GetResponse () [0x00000] in <filename unknown>:0
at System.Net.WebClient.GetWebResponse (System.Net.WebRequest request) [0x00000] in <filename unknown>:0
at System.Net.WebClient.ReadAll (System.Net.WebRequest request, System.Object userToken) [0x00000] in <filename unknown>:0
at System.Net.WebClient.UploadFileCore (System.Uri address, System.String method, System.String fileName, System.Object userToken) [0x00000] in <filename unknown>:0
at System.Net.WebClient.UploadFile (System.Uri address, System.String method, System.String fileName) [0x00000] in <filename unknown>:0
Client Code (Monotouch)
public void UploadVideo(Guid organizationId, string path) {
WebClient wc = new WebClient();
var token = Convert.ToBase64String(Encoding.UTF8.GetBytes(string.Format("{0}:{1}", username, password)));
var authHeader = string.Format("Basic {0}", token);
wc.Headers.Add("Authorization", authHeader);
var resource = string.Format("/organizations/{0}/SyncVideo/", organizationId);
var fi = new FileInfo(path);
wc.UploadFile(restClient.BaseUrl + resource, "POST", path);
wc.Dispose();
}
Server Code (ASP.Net MVC3)
[HttpPost, Url("v3/organizations/{organizationId?}/SyncVideo/")]
public virtual JsonResult SyncVideo(HttpPostedFileBase file, Guid? organizationId) {
if (organizationId.IsNull()) throw new HttpNotFoundExecption();
if (organizationId != RESTContext.OrganizationId) throw new HttpNotAuthorizedException();
var basePath = RESTContext.Config.VideoPath;
using (new Impersonator(RESTContext.Config.VideoPathUsername, RESTContext.Config.VideoPathDomain,
RESTContext.Config.VideoPathPassword)) {
if (!Directory.Exists(basePath))
Directory.CreateDirectory(basePath);
file.SaveAs(basePath + #"\" + file.FileName);
}
return JsonSuccess();
}

Categories