System.IO.FileNotFoundException when using CSharpScript in Blazor wasm - c#

I'm trying to use CSharpScript in a Blazor wasm application, testing with a simple EvaluateAsync:
var result = await CSharpScript.EvaluateAsync<int>("1 + 1");
Throws: System.IO.FileNotFoundException: Could not find file "/mscorlib.dll"
I'm using Blazor wasm 3.2.0-preview3.20168.3
Edit:
Here's the full code in index.razor:
#code{
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
Console.WriteLine("Initializing...");
var result = await CSharpScript.EvaluateAsync<int>("1 + 1");
}
}
And here's the console output:
Initializing...
blazor.webassembly.js:1 crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: Could not find file "/mscorlib.dll"
System.IO.FileNotFoundException: Could not find file "/mscorlib.dll"
File name: '/mscorlib.dll'
at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.Boolean anonymous, System.IO.FileOptions options) <0x3ba83f8 + 0x002b4> in <filename unknown>:0
at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share) <0x3b987a0 + 0x0001c> in <filename unknown>:0
at System.IO.File.OpenRead (System.String path) <0x3b986d0 + 0x0000a> in <filename unknown>:0
at Roslyn.Utilities.FileUtilities.OpenFileStream (System.String path) [0x0001c] in /_/src/Compilers/Core/Portable/FileSystem/FileUtilities.cs:416
at Microsoft.CodeAnalysis.MetadataReference.CreateFromAssemblyInternal (System.Reflection.Assembly assembly, Microsoft.CodeAnalysis.MetadataReferenceProperties properties, Microsoft.CodeAnalysis.DocumentationProvider documentation) [0x0005a] in /_/src/Compilers/Core/Portable/MetadataReference/MetadataReference.cs:329
at Microsoft.CodeAnalysis.MetadataReference.CreateFromAssemblyInternal (System.Reflection.Assembly assembly) [0x00000] in /_/src/Compilers/Core/Portable/MetadataReference/MetadataReference.cs:271
at Microsoft.CodeAnalysis.Scripting.Script.GetReferencesForCompilation (Microsoft.CodeAnalysis.CommonMessageProvider messageProvider, Microsoft.CodeAnalysis.DiagnosticBag diagnostics, Microsoft.CodeAnalysis.MetadataReference languageRuntimeReferenceOpt) [0x0001a] in /_/src/Scripting/Core/Script.cs:252
at Microsoft.CodeAnalysis.CSharp.Scripting.CSharpScriptCompiler.CreateSubmission (Microsoft.CodeAnalysis.Scripting.Script script) [0x00021] in /_/src/Scripting/CSharp/CSharpScriptCompiler.cs:40
at Microsoft.CodeAnalysis.Scripting.Script.GetCompilation () [0x00008] in /_/src/Scripting/Core/Script.cs:144
at Microsoft.CodeAnalysis.Scripting.Script`1[T].GetExecutor (System.Threading.CancellationToken cancellationToken) [0x00008] in /_/src/Scripting/Core/Script.cs:361
at Microsoft.CodeAnalysis.Scripting.Script`1[T].RunAsync (System.Object globals, System.Func`2[T,TResult] catchException, System.Threading.CancellationToken cancellationToken) [0x0001b] in /_/src/Scripting/Core/Script.cs:465
at Microsoft.CodeAnalysis.Scripting.Script`1[T].RunAsync (System.Object globals, System.Threading.CancellationToken cancellationToken) [0x00000] in /_/src/Scripting/Core/Script.cs:439
at Microsoft.CodeAnalysis.CSharp.Scripting.CSharpScript.RunAsync[T] (System.String code, Microsoft.CodeAnalysis.Scripting.ScriptOptions options, System.Object globals, System.Type globalsType, System.Threading.CancellationToken cancellationToken) [0x00000] in /_/src/Scripting/CSharp/CSharpScript.cs:93
at Microsoft.CodeAnalysis.CSharp.Scripting.CSharpScript.EvaluateAsync[T] (System.String code, Microsoft.CodeAnalysis.Scripting.ScriptOptions options, System.Object globals, System.Type globalsType, System.Threading.CancellationToken cancellationToken) [0x00000] in /_/src/Scripting/CSharp/CSharpScript.cs:123
at ScriptPlayground.Pages.Index.OnInitializedAsync () [0x0008a] in C:\Users\sarma\source\repos\ScriptPlayground\Pages\Index.razor:17
at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync () <0x36de968 + 0x0013a> in <filename unknown>:0
Edit 2:
After digging deeper into the issue, we traced it down to these lines in Script.cs:
/// <summary>
/// Gets the references that need to be assigned to the compilation.
/// This can be different than the list of references defined by the <see cref="ScriptOptions"/> instance.
/// </summary>
internal ImmutableArray<MetadataReference> GetReferencesForCompilation(
CommonMessageProvider messageProvider,
DiagnosticBag diagnostics,
MetadataReference languageRuntimeReferenceOpt = null)
{
var resolver = Options.MetadataResolver;
var references = ArrayBuilder<MetadataReference>.GetInstance();
try
{
if (Previous == null)
{
var corLib = MetadataReference.CreateFromAssemblyInternal(typeof(object).GetTypeInfo().Assembly);
references.Add(corLib);
No matter what options we pass, this will always be called on compilation, MetadataReference.CreateFromAssemblyInternal tries to load a file from disk. So it appears that loading assemblies from disk is hardcoded into the process. We're looking for a clean way of overriding this.
We were already successful in loading assemblies from streams using HttpClient:
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
{
var name = assembly.GetName().Name + ".dll";
references.Add(
MetadataReference.CreateFromStream(
await this.HttpClient.GetStreamAsync("/_framework/_bin/" + name)));
}
But this doesn't matter as long as CSharpScript is loading another set of assemblies during compilation from disk

The CsharpScript API unfortunately has been built with a dependency on looking up assemblies on the local filesystem. If you dig deep enough in the MetadataReference.CreateFromStream source, you will see the culprit being a call to File.OpenRead()
I spent some time myself looking into any possible extensibility of the API where one could supply an alternative assembly resolution strategy. There is a path via the supply of a custom MetaDataReferenceResolver in the ScriptOptions however the baking in of the line you discovered
var corLib = MetadataReference.CreateFromAssemblyInternal(typeof(object).GetTypeInfo().Assembly);
effectively creates the hard dependency on the file system which kills the idea.
The resolution of mscorlib is done this way above, but then all other asemblies use the Options.MetaDataReferences list. Why I have no idea....
As a pure hack I even had a crack at capturing the call to File.OpenRead() and returing my own stream from HttpClient. The injection works in a desktop process, but something was going wrong in wasm. In the end I gave up too in favour of rolling an alternative such as this approach or this one.
Here was the trial hack for anyone who is interested.
//Using the Pose library https://github.com/tonerdo/pose
var client = new HttpClient() { BaseAddress = new Uri(navigationManager.BaseUri) };
Shim fileShim = Shim.Replace(() => System.IO.File.OpenRead(Is.A<string>())).With(delegate (string assembly)
{
var fs = new System.IO.FileStream(assembly, System.IO.FileMode.Open);
client.GetStreamAsync($"_framework/_bin/{assembly}").Result.CopyTo(fs);
return fs;
});
PoseContext.Isolate(() => Text = CSharpScript.EvaluateAsync<string>("hello").Result, fileShim);
HTH

Related

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?

Strange UriFormatException when using mono

I'm currently working on a project which has to run on mono.
Normally, everything works just fine. But when I try to run it in a separate screen on my ubuntu 14.04 server, it won't start after crashing once. The error that occurs is the following:
System.UriFormatException: Invalid URI: The URI scheme is not valid.
at System.Uri.Parse (UriKind kind, System.String uriString) <0x40141e70 + 0x000b3> in <filename unknown>:0
at System.Uri.ParseUri (UriKind kind) <0x40141d50 + 0x00023> in <filename unknown>:0
at System.Uri..ctor (System.String uriString, Boolean dontEscape) <0x401459e0 + 0x001b7> in <filename unknown>:0
at System.Uri..ctor (System.String uriString) <0x401459b0 + 0x00013> in <filename unknown>:0
at System.Xml.XmlResolver.ResolveUri (System.Uri baseUri, System.String relativeUri) <0x401403f0 + 0x0010b> in <filename unknown>:0
at System.Xml.XmlUrlResolver.ResolveUri (System.Uri baseUri, System.String relativeUri) <0x401403c0 + 0x00017> in <filename unknown>:0
at System.Xml.XmlTextReaderImpl..ctor (System.String uriStr, System.Xml.XmlReaderSettings settings, System.Xml.XmlParserContext context, System.Xml.XmlResolver uriResolver) <0x4013e610 + 0x00060> in <filename unknown>:0
at System.Xml.XmlReaderSettings.CreateReader (System.String inputUri, System.Xml.XmlParserContext inputContext) <0x4013e4a0 + 0x0008f> in <filename unknown>:0
at System.Xml.XmlReader.Create (System.String inputUri, System.Xml.XmlReaderSettings settings, System.Xml.XmlParserContext inputContext) <0x4013e420 + 0x0005f> in <filename unknown>:0
at System.Xml.XmlReader.Create (System.String inputUri, System.Xml.XmlReaderSettings settings) <0x4013e3c0 + 0x00013> in <filename unknown>:0
at Project.Server.Settings..ctor () <0x4013c1f0 + 0x0006f> in <filename unknown>:0
This seems very strange to me, as the code that produces the error is the following:
private XDocument configFile;
public Settings()
{
var readerSettings = new XmlReaderSettings { CheckCharacters = false };
using (var reader = XmlReader.Create("config.xml", readerSettings))
{
configFile = XDocument.Load(reader);
}
}
As mentioned before, everything works just fine when run the first time. But after it crashed once, it won't start and crashes with this error. More strangely, I can fix the problem by terminating the screen and making a new one and running the exact same command.
Has anybody encountered something like this before? Is this something that can be prevented?

Sporadic failure of System.Net.FtpClient.FileExists

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.

Azure Offline Sync. Can't add item "Query execution failed with result: 'MISMATCH'."

I am programming an app currently i want to add a new item to the local SQLLite Database:
public async Task SaveTaskAsync(Fault item)
{
try
{
if (item.Id == null)
{
await FaultTable.InsertAsync(item);
}
else
{
await FaultTable.UpdateAsync(item);
}
}
catch (Exception ex)
{
}
}
But the Statement await FaultTable.InsertAsync(item); is ending up with following error:
"Microsoft.WindowsAzure.MobileServices.Sync.MobileServiceLocalStoreException: Failed to perform operation on local store."
Inner Exception:
"SQLitePCL.SQLiteException Query execution failed with result: 'MISMATCH'."
Stacktrace of Inner Exception:
at Microsoft.WindowsAzure.MobileServices.SQLiteStore.MobileServiceSQLiteStore.ValidateResult (SQLiteResult result) [0x00023] in <filename unknown>:0
at Microsoft.WindowsAzure.MobileServices.SQLiteStore.MobileServiceSQLiteStore.ExecuteNonQuery (System.String sql, IDictionary`2 parameters) [0x00057] in <filename unknown>:0
at Microsoft.WindowsAzure.MobileServices.SQLiteStore.MobileServiceSQLiteStore.BatchInsert (System.String tableName, IEnumerable`1 items, System.Collections.Generic.List`1 columns) [0x000f5] in <filename unknown>:0
at Microsoft.WindowsAzure.MobileServices.SQLiteStore.MobileServiceSQLiteStore+<>c__DisplayClass10_0.<UpsertAsyncInternal>b__0 (System.Threading.Tasks.Task t) [0x00058] in <filename unknown>:0
at System.Threading.Tasks.ContinuationTaskFromTask.InnerInvoke () [0x00027] in /Users/builder/data/lanes/2923/52635947/source/mono/external/referencesource/mscorlib/system/threading/Tasks/TaskContinuation.cs:63
at System.Threading.Tasks.Task.Execute () [0x00016] in /Users/builder/data/lanes/2923/52635947/source/mono/external/referencesource/mscorlib/system/threading/Tasks/Task.cs:2502
MISMATCH indicates that the SQL statement (that is generated from the model) is trying to insert data that does not match the schema of the table stored in the database. Did you change the model recently? If so, you will need to fix the database. You can do that either under the covers (by using a SQLite editor) or
by wiping out the database and then re-syncing the data.

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