Reading mp3 track duration on Android - c#

On Android I am getting this error Java.Lang.IllegalArgumentException:
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000b] in /Users/builder/data/lanes/2058/58099c53/source/mono/mcs/class/corlib/System.Runtime.ExceptionServices/ExceptionDispatchInfo.cs:61
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.m__0 (object) [0x00000] in /Users/builder/data/lanes/2058/58099c53/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1006
at Android.App.SyncContext/c__AnonStorey0.<>m__0 () [0x00000] in /Users/builder/data/lanes/2058/58099c53/source/monodroid/src/Mono.Android/src/Android.App/SyncContext.cs:18
at Java.Lang.Thread/RunnableImplementor.Run () [0x0000b] in /Users/builder/data/lanes/2058/58099c53/source/monodroid/src/Mono.Android/src/Java.Lang/Thread.cs:36
at Java.Lang.IRunnableInvoker.n_Run (intptr,intptr) [0x00009] in /Users/builder/data/lanes/2058/58099c53/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Java.Lang.IRunnable.cs:71
at (wrapper dynamic-method) object.7dac782f-30e4-45cb-a248-e0c4c79fbcad (intptr,intptr)
--- End of managed exception stack trace --- java.lang.IllegalArgumentException at
android.media.MediaMetadataRetriever.setDataSource(MediaMetadataRetriever.java:169) at dalvik.system.NativeStart.run(Native Method)
using this code to retrive *.mp3 file duration:
public async Task<string> GetTrackDuration(string pathToFile)
{
MediaMetadataRetriever reader = new MediaMetadataRetriever();
await reader.SetDataSourceAsync (global::Android.App.Application.Context, Android.Net.Uri.Parse (pathToFile));
return reader.ExtractMetadata(MetadataKey.Duration).ToString();
}
where is the problem? I have tried all of the posible constructors

Related

Can't run "System.Windows.Forms application" while testing a Hello World code after fresh installation

I'm a linux (Slackware 14.2) user and needed to install mono for a work project on my computer. After installing the slackbuild I ran the code from https://www.mono-project.com/docs/getting-started/mono-basics/ which worked great until I tried to use 'System.Windows.Forms' as follow:
using System;
using System.Windows.Forms;
public class HelloWorld : Form
{
static public void Main ()
{
Application.Run (new HelloWorld ());
}
public HelloWorld ()
{
Text = "Hello Mono World";
}
}
After compiling and running I get:
$ mono hello.exe
Unhandled Exception:
System.TypeInitializationException: The type initializer for 'System.Windows.Forms.WindowsFormsSynchronizationContext' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.Windows.Forms.ThemeEngine' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.Windows.Forms.ThemeWin32Classic' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.Drawing.KnownColors' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.Drawing.GDIPlus' threw an exception. ---> System.DllNotFoundException: libgdiplus.so.0
at (wrapper managed-to-native) System.Drawing.GDIPlus:GdiplusStartup (ulong&,System.Drawing.GdiplusStartupInput&,System.Drawing.GdiplusStartupOutput&)
at System.Drawing.GDIPlus..cctor () [0x000ab] in <ac0a7ab7ad9c4534aa7b9d68ccc688c1>:0
--- End of inner exception stack trace ---
at System.Drawing.KnownColors..cctor () [0x0001a] in <ac0a7ab7ad9c4534aa7b9d68ccc688c1>:0
--- End of inner exception stack trace ---
at System.Drawing.Color.get_Black () [0x00000] in <ac0a7ab7ad9c4534aa7b9d68ccc688c1>:0
at System.Windows.Forms.ThemeWin32Classic..cctor () [0x00000] in <cfc91f7a5a0243dda6f0da9f9f2bd749>:0
--- End of inner exception stack trace ---
at System.Windows.Forms.ThemeEngine..cctor () [0x0002f] in <cfc91f7a5a0243dda6f0da9f9f2bd749>:0
--- End of inner exception stack trace ---
at System.Windows.Forms.SystemInformation.get_MenuAccessKeysUnderlined () [0x00000] in <cfc91f7a5a0243dda6f0da9f9f2bd749>:0
at System.Windows.Forms.Control..ctor () [0x000e4] in <cfc91f7a5a0243dda6f0da9f9f2bd749>:0
at (wrapper remoting-invoke-with-check) System.Windows.Forms.Control:.ctor ()
at System.Windows.Forms.WindowsFormsSynchronizationContext..cctor () [0x00000] in <cfc91f7a5a0243dda6f0da9f9f2bd749>:0
--- End of inner exception stack trace ---
at System.Windows.Forms.Control..ctor () [0x00014] in <cfc91f7a5a0243dda6f0da9f9f2bd749>:0
at System.Windows.Forms.ScrollableControl..ctor () [0x00000] in <cfc91f7a5a0243dda6f0da9f9f2bd749>:0
at System.Windows.Forms.ContainerControl..ctor () [0x0000e] in <cfc91f7a5a0243dda6f0da9f9f2bd749>:0
at System.Windows.Forms.Form..ctor () [0x00012] in <cfc91f7a5a0243dda6f0da9f9f2bd749>:0
at HelloWorld..ctor () [0x00000] in <ebd84f70eef34e1bac9228a36ebc3550>:0
at (wrapper remoting-invoke-with-check) HelloWorld:.ctor ()
at HelloWorld.Main () [0x00001] in <ebd84f70eef34e1bac9228a36ebc3550>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: The type initializer for 'System.Windows.Forms.WindowsFormsSynchronizationContext' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.Windows.Forms.ThemeEngine' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.Windows.Forms.ThemeWin32Classic' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.Drawing.KnownColors' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.Drawing.GDIPlus' threw an exception. ---> System.DllNotFoundException: libgdiplus.so.0
at (wrapper managed-to-native) System.Drawing.GDIPlus:GdiplusStartup (ulong&,System.Drawing.GdiplusStartupInput&,System.Drawing.GdiplusStartupOutput&)
at System.Drawing.GDIPlus..cctor () [0x000ab] in <ac0a7ab7ad9c4534aa7b9d68ccc688c1>:0
--- End of inner exception stack trace ---
at System.Drawing.KnownColors..cctor () [0x0001a] in <ac0a7ab7ad9c4534aa7b9d68ccc688c1>:0
--- End of inner exception stack trace ---
at System.Drawing.Color.get_Black () [0x00000] in <ac0a7ab7ad9c4534aa7b9d68ccc688c1>:0
at System.Windows.Forms.ThemeWin32Classic..cctor () [0x00000] in <cfc91f7a5a0243dda6f0da9f9f2bd749>:0
--- End of inner exception stack trace ---
at System.Windows.Forms.ThemeEngine..cctor () [0x0002f] in <cfc91f7a5a0243dda6f0da9f9f2bd749>:0
--- End of inner exception stack trace ---
at System.Windows.Forms.SystemInformation.get_MenuAccessKeysUnderlined () [0x00000] in <cfc91f7a5a0243dda6f0da9f9f2bd749>:0
at System.Windows.Forms.Control..ctor () [0x000e4] in <cfc91f7a5a0243dda6f0da9f9f2bd749>:0
at (wrapper remoting-invoke-with-check) System.Windows.Forms.Control:.ctor ()
at System.Windows.Forms.WindowsFormsSynchronizationContext..cctor () [0x00000] in <cfc91f7a5a0243dda6f0da9f9f2bd749>:0
--- End of inner exception stack trace ---
at System.Windows.Forms.Control..ctor () [0x00014] in <cfc91f7a5a0243dda6f0da9f9f2bd749>:0
at System.Windows.Forms.ScrollableControl..ctor () [0x00000] in <cfc91f7a5a0243dda6f0da9f9f2bd749>:0
at System.Windows.Forms.ContainerControl..ctor () [0x0000e] in <cfc91f7a5a0243dda6f0da9f9f2bd749>:0
at System.Windows.Forms.Form..ctor () [0x00012] in <cfc91f7a5a0243dda6f0da9f9f2bd749>:0
at HelloWorld..ctor () [0x00000] in <ebd84f70eef34e1bac9228a36ebc3550>:0
at (wrapper remoting-invoke-with-check) HelloWorld:.ctor ()
at HelloWorld.Main () [0x00001] in <ebd84f70eef34e1bac9228a36ebc3550>:0
Is there anything I did wrong (or didn't do)?
Didn't notice I had a 32-bit lib installed. Perfectly working now.
Thanks Stefan Becker.

WebAPI POST without data causes application to crash

I have a simple OWIN self-hosted application with a controller extending ApiController. The problem is, when I send a POST request with no data to the controller (the method doesn't have parameters), it returns:
Length Required
And then the application crashes with an unhandled ObjectDisposedException (full stack trace below). If the POST request contains data then all is well.
I removed all controller logic from the equation by replicating with this simple method:
[HttpPost]
public void MyMethod()
{
return;
}
Therefore I'm guessing it's something to do with routing? But my routes are only set up as the default:
config.Routes.MapHttpRoute("My Service", "{controller}/{action}/{id}", new { id = RouteParameter.Optional });
Why would my application be behaving in this manner?
To send the requests I use curl:
curl --request POST http://localhost/mycontroller/mymethod
Stack trace:
Unhandled Exception: System.ObjectDisposedException: Cannot access a
disposed object. Object name: 'System.Net.HttpListenerResponse'. at
System.Net.HttpListenerResponse.set_StatusCode (System.Int32 value)
[0x00016] in <59be416de143456b88b9988284f43350>:0 at
Microsoft.Owin.Host.HttpListener.RequestProcessing.OwinHttpListenerResponse.End
() [0x0001c] in <5086711574984403b242554b11c41440>:0 at
Microsoft.Owin.Host.HttpListener.RequestProcessing.OwinHttpListenerContext.End
() [0x00010] in <5086711574984403b242554b11c41440>:0 at
Microsoft.Owin.Host.HttpListener.RequestProcessing.OwinHttpListenerContext.End
(System.Exception ex) [0x0001e] in
<5086711574984403b242554b11c41440>:0 at
Microsoft.Owin.Host.HttpListener.OwinHttpListener+d__5.MoveNext
() [0x001f9] in <5086711574984403b242554b11c41440>:0
--- End of stack trace from previous location where exception was thrown --- at
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw ()
[0x0000c] in :0 at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess
(System.Threading.Tasks.Task task) [0x0004e] in
:0 at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification
(System.Threading.Tasks.Task task) [0x0002e] in
:0 at
System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd
(System.Threading.Tasks.Task task) [0x0000b] in
:0 at
System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in
:0 at
Microsoft.Owin.Host.HttpListener.OwinHttpListener+d__0.MoveNext
() [0x00202] in <5086711574984403b242554b11c41440>:0
--- End of stack trace from previous location where exception was thrown --- at
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw ()
[0x0000c] in :0 at
System.Runtime.CompilerServices.AsyncMethodBuilderCore.m__1
(System.Object state) [0x00000] in
:0 at
System.Threading.QueueUserWorkItemCallback.WaitCallback_Context
(System.Object state) [0x0000e] in
:0 at
System.Threading.ExecutionContext.RunInternal
(System.Threading.ExecutionContext executionContext,
System.Threading.ContextCallback callback, System.Object state,
System.Boolean preserveSyncCtx) [0x0008d] in
:0 at
System.Threading.ExecutionContext.Run
(System.Threading.ExecutionContext executionContext,
System.Threading.ContextCallback callback, System.Object state,
System.Boolean preserveSyncCtx) [0x00000] in
:0 at
System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem
() [0x0002a] in :0 at
System.Threading.ThreadPoolWorkQueue.Dispatch () [0x00096] in
:0 at
System.Threading._ThreadPoolWaitCallback.PerformWaitCallback ()
[0x00000] in :0
Maybe if you show all your controller class I can help you a little more.
Try to make your post like this.
Make one class every get/post
for example in folder Controllers/Api/MyFunction.cs
in WebApiConfig.cs
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "API/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
in your "MyFunction.cs"
public class MyFunction : ApiController
{
public string Get()
{
return "hello";
}
public bool Post(string param1)
{
return 1;
}
}

'Failed to decode image. The provided image must be a Bitmap' - SetIcon on Google Map Marker throwing an error

I'm getting the following error when trying to set an icon on a Google Maps Map Marker:
[ERR] 26/06/2018 10:02:25 a.m. : Failed to decode image. The provided
image must be a Bitmap. [ERR] 26/06/2018 10:02:25 a.m. : at
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw ()
[0x0000c] in <0711a0626e0e4d58a44e8ca32787a4a9>:0 at
Java.Interop.JniEnvironment+InstanceMethods.CallVoidMethod
(Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo
method, Java.Interop.JniArgumentValue* args) [0x00069] in
:0 at
Android.Runtime.JNIEnv.CallVoidMethod (System.IntPtr jobject,
System.IntPtr jmethod, Android.Runtime.JValue* parms) [0x0000e] in
<5680b8d3acca4700bde9a113c467e3e5>:0 at
Android.Runtime.JNIEnv.CallVoidMethod (System.IntPtr jobject,
System.IntPtr jmethod, Android.Runtime.JValue[] parms) [0x00017] in
<5680b8d3acca4700bde9a113c467e3e5>:0 at
Android.Gms.Maps.Model.Marker.SetIcon
(Android.Gms.Maps.Model.BitmapDescriptor icon) [0x0004b] in
<51f505f20f3f4c27854ba8f47994abdb>:0 at
AMCS.Mobile.Mapping.Android.MarkerManager.UpdateMarker
(AMCS.Mobile.Entity.Mapping.IMarker markerInfo) [0x00083] in
:0 at
AMCS.Mobile.Mapping.Android.MapHelper.UpdateMarker
(AMCS.Mobile.Entity.Mapping.IMarker markerInfo) [0x00000] in
:0 at
AMCS.Mobile.AMCSMobile.Client.Android.CollectionRouteView.b__462_0
() [0x00000] in <1d292c66dbaa42139a432bad3cbbbc7b>:0 at
Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in
<5680b8d3acca4700bde9a113c467e3e5>:0 at
Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr
native__this) [0x00008] in <5680b8d3acca4700bde9a113c467e3e5>:0 at
(wrapper dynamic-method)
System.Object:6aee8cf7-156f-44a9-94d5-15cb0790d815 (intptr,intptr)
--- End of managed Java.Lang.RuntimeException stack trace --- com.google.maps.api.android.lib6.common.apiexception.b: Failed to
decode image. The provided image must be a Bitmap. at
com.google.maps.api.android.lib6.impl.n.a(:com.google.android.gms.dynamite_dynamitemodulesb#12685024#12.6.85
(040406-197041431):12) at
com.google.maps.api.android.lib6.impl.o.a(:com.google.android.gms.dynamite_dynamitemodulesb#12685024#12.6.85
(040406-197041431):7) at
com.google.maps.api.android.lib6.impl.cy.a(:com.google.android.gms.dynamite_dynamitemodulesb#12685024#12.6.85
(040406-197041431):186) at
com.google.android.gms.maps.model.internal.q.onTransact(:com.google.android.gms.dynamite_dynamitemodulesb#12685024#12.6.85
(040406-197041431):87) at android.os.Binder.transact(Binder.java:507)
at com.google.android.gms.maps.model.internal.l$a$a.n(Unknown Source)
at com.google.android.gms.maps.model.Marker.setIcon(Unknown Source)
at mono.java.lang.RunnableImplementor.n_run(Native Method) at
mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:30)
at android.os.Handler.handleCallback(Handler.java:751) at
android.os.Handler.dispatchMessage(Handler.java:95) at
android.os.Looper.loop(Looper.java:154) at
android.app.ActivityThread.main(ActivityThread.java:6780) at
java.lang.reflect.Method.invoke(Native Method) at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)
I can see that it's failing in the UpdateMarker method which looks like the following:
public void UpdateMarker(IMarker markerInfo)
{
// _markerLookup is a dictionary defined earlier as:
// private Dictionary<IMarker,Android.Gms.Maps.Model.Marker> _markerLookup = new Dictionary<IMarker, Android.Gms.Maps.Model.Marker>();
// It is populated elsewhere
// Check if the dictionary contains a key for the given value
if (_markerLookup.ContainsKey(markerInfo))
{
Android.Gms.Maps.Model.Marker marker = _markerLookup[markerInfo];
marker.Position = new LatLng(markerInfo.MapCoordinate.Lat, markerInfo.MapCoordinate.Lng);
marker.Draggable = markerInfo.MarkerOptions.IsDraggable;
// Create BitmapDescriptor from Resource - Blue_Vehicle definitely exists and is a .png image
BitmapDescriptor bitmapDesc =
BitmapDescriptorFactory.FromResource(Resource.Drawable.Blue_Vehicle);
if (bitmapDesc != null)
{
marker.SetIcon(bitmapDesc);
}
}
}
The marker.SetIcon method is looking for a BitMapDescriptor which as described above is created from an image resource.
I don't understand why it's throwing an exception.
I would greatly appreciate if someone could shed some light on the issue.

How to post multipartformdata in xamarin ios?

I'm developing mobile app for IOS using Xamarin IOS and when I try to post image to server using xamarin PostAsync() method, unfortunately it raises an exception.
public async Task<string> PostCreatePlatform(Platform new_platform, Byte[] image)
{
new_platform.id = null;
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Add("Authorization", String.Format("Token {0}", TokenInit.Token));
var response = await client.PostAsync(b + "platforms/", new StringContent(JsonConvert.SerializeObject(new_platform, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }).ToString(),Encoding.UTF8, "application/json"));
if (response.IsSuccessStatusCode)
{
if (image != null)
{
var TempPlatform = await response.Content.ReadAsStringAsync();
var final = JsonConvert.DeserializeObject<Platform>(TempPlatform);
MultipartFormDataContent form = new MultipartFormDataContent();
new_platform.id = final.id.Value;
form.Add(new ByteArrayContent(image, 0, image.Count()), "file");
var response2 = await client.PostAsync(String.Format(b + "platform/{0}/attachments/upload/", new_platform.id.Value), form);
if (response2.IsSuccessStatusCode)
{
return "success";
}
else
{
return "failed";
}
}
return "success";
}
else
{
return "failed";
}
}
InnerException: System.ObjectDisposedException
System.AggregateException: One or more errors occurred. —-> System.AggregateException: One or more errors occurred. —-> System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'System.Net.Sockets.NetworkStream'.
at System.Net.WebConnectionStream.EndWrite (System.IAsyncResult r) [0x000b2] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.10.0.33/src/mono/mcs/class/System/System.Net/WebConnectionStream.cs:616
at System.IO.Stream+<>c.<BeginEndWriteAsync>b__53_1 (System.IO.Stream stream, System.IAsyncResult asyncResult) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.10.0.33/src/mono/mcs/class/referencesource/mscorlib/system/io/stream.cs:729
at at (wrapper delegate-invoke) System.Func`3[System.IO.Stream,System.IAsyncResult,System.Threading.Tasks.VoidTaskResult]:invoke_TResult_T1_T2 (System.IO.Stream,System.IAsyncResult)
at System.Threading.Tasks.TaskFactory`1+FromAsyncTrimPromise`1[TResult,TInstance].Complete (TInstance thisRef, System.Func`3[T1,T2,TResult] endMethod, System.IAsyncResult asyncResult, System.Boolean requiresSynchronization) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.10.0.33/src/mono/mcs/class/referencesource/mscorlib/system/threading/Tasks/FutureFactory.cs:1441
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.10.0.33/src/mono/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:151
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00037] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.10.0.33/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.10.0.33/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.10.0.33/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable+ConfiguredTaskAwaiter.GetResult () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.10.0.33/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:447
at System.Net.Http.MultipartContent+<SerializeToStreamAsync>d__8.MoveNext () [0x00265] in <eadf07f9d3724ef0a06ee9064ef34579>:0
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.10.0.33/src/mono/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:151
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00037] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.10.0.33/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.10.0.33/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.10.0.33/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable+ConfiguredTaskAwaiter.GetResult () [0x00000] in
/Library/Frameworks/Xamarin.iOS.framework/Versions/10.10.0.33/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:447
at System.Net.Http.HttpClientHandler+<SendAsync>d__63.MoveNext () [0x0031d] in <eadf07f9d3724ef0a06ee9064ef34579>:0
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.10.0.33/src/mono/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:151
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00037] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.10.0.33/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.10.0.33/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.10.0.33/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.10.0.33/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:535
at System.Net.Http.HttpClient+<SendAsyncWorker>d__48.MoveNext () [0x000ca] in <eadf07f9d3724ef0a06ee9064ef34579>:0
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.10.0.33/src/mono/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:151
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00037] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.10.0.33/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.10.0.33/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.10.0.33/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128
at System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.10.0.33/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:357
at FirstApp.ApiInteracting+<PostCreatePlatform>d__7.MoveNext () [0x003e2] in /Users/team1/Downloads/testiOSbayards2-6d24bc43fee6abd445ebcaea12b76c61649468a6/FirstApp/API/ApiInteracting.cs:176
—- End of inner exception stack trace —-
at System.Threading.Tasks.Task.ThrowIfExceptional (System.Boolean includeTaskCanceledExceptions) [0x00011] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.10.0.33/src/mono/mcs/class/referencesource/mscorlib/system/threading/Tasks/Task.cs:2157
at System.Threading.Tasks.Task`1[TResult].GetResultCore (System.Boolean waitCompletionNotification) [0x0002b] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.10.0.33/src/mono/mcs/class/referencesource/mscorlib/system/threading/Tasks/Future.cs:562
at System.Threading.Tasks.Task`1[TResult].get_Result () [0x00000] in
/Library/Frameworks/Xamarin.iOS.framework/Versions/10.10.0.33/src/mono/mcs/class/referencesource/mscorlib/system/threading/Tasks/Future.cs:532
at FirstApp.AddPlatformTableViewController+<>c__DisplayClass247_0.<CreatePlatformButtonUpInside>b__0 () [0x00000] in /Users/team1/Downloads/testiOSbayards2-6d24bc43fee6abd445ebcaea12b76c61649468a6/FirstApp/UIClasses/AddPlatformTableViewController.cs:115
at System.Threading.Tasks.Task`1[TResult].InnerInvoke () [0x0000f] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.10.0.33/src/mono/mcs/class/referencesource/mscorlib/system/threading/Tasks/Future.cs:680
at System.Threading.Tasks.Task.Execute () [0x00010] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.10.0.33/src/mono/mcs/class/referencesource/mscorlib/system/threading/Tasks/Task.cs:2502
—- End of inner exception stack trace —-
at System.Threading.Tasks.Task.ThrowIfExceptional (System.Boolean includeTaskCanceledExceptions) [0x00011] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.10.0.33/src/mono/mcs/class/referencesource/mscorlib/system/threading/Tasks/Task.cs:2157
at System.Threading.Tasks.Task`1[TResult].GetResultCore (System.Boolean waitCompletionNotification) [0x0002b] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.10.0.33/src/mono/mcs/class/referencesource/mscorlib/system/threading/Tasks/Future.cs:562
at System.Threading.Tasks.Task`1[TResult].get_Result () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.10.0.33/src/mono/mcs/class/referencesource/mscorlib/system/threading/Tasks/Future.cs:532
at FirstApp.AddPlatformTableViewController+<>c__DisplayClass247_1.<CreatePlatformButtonUpInside>b__2 () [0x00001] in /Users/team1/Downloads/testiOSbayards2-6d24bc43fee6abd445ebcaea12b76c61649468a6/FirstApp/UIClasses/AddPlatformTableViewController.cs:119
at Foundation.NSActionDispatcher.Apply () [0x00000] in /Users/builder/data/lanes/4691/3e5ac5ff/source/xamarin-macios/src/Foundation/NSAction.cs:57
at at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Users/builder/data/lanes/4691/3e5ac5ff/source/xamarin-macios/src/UIKit/UIApplication.cs:79
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Users/builder/data/lanes/4691/3e5ac5ff/source/xamarin-macios/src/UIKit/UIApplication.cs:63
at FirstApp.Application.Main (System.String[] args) [0x00001] in /Users/team1/Downloads/testiOSbayards2-6d24bc43fee6abd445ebcaea12b76c61649468a6/FirstApp/Main.cs:12
Moreover, I reproduced this method using .NET C# compiler(not Mono) and manually with web debugging tool(Fiddler) and everything is ok.
Update:
The problem was resolved. Size of image was too big - 18mb.
Try following code. it works for me. Hope it helps.
public class PostImageData
{
public int success { get; private set; }
public async Task postData(string username, string password,string documentid, StreamContent streamContent)
{
UploadPhoto details = new UploadPhoto();
try
{
System.Diagnostics.Debug.WriteLine("uplod done");
var clinet = new HttpClient();
var content = new MultipartFormDataContent();
content.Add(streamContent, "file", "test.jpeg");
System.Net.Http.HttpResponseMessage r =await clinet.PostAsync(YOUR_URL, content);
string json =await r.Content.ReadAsStringAsync();
details = JsonConvert.DeserializeObject<UploadPhoto>(json);
if (details.message == "Upload success")
{
success = 200;
}
success = 200;
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
success = 400;
}
}
public class UploadPhoto
{
public string message { get; set; }
}
}

Xamarin.iOS SQLiteException: Corrupt

I'm building an application with Xamarin.Forms and a Portable Class Library.The app can be used on Android, iOS and UWP.
I've been building a database which now works on both Android and UWP. When I use the same code and run it on iOS it gives me some errors.
This is the exception message:
Unhandled Exception: SQLite.SQLiteException: Corrupt
This is the StackTrace:
at SQLite.PreparedSqlLiteInsertCommand.ExecuteNonQuery (System.Object[] source) [0x00116] in /Users/fak/Dropbox/Projects/sqlite-net/src/SQLite.cs:2480
at SQLite.SQLiteConnection.Insert (System.Object obj, System.String extra, System.Type objType) [0x0010e] in /Users/fak/Dropbox/Projects/sqlite-net/src/SQLite.cs:1381
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/3818/ad1cd42d/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00047] in /Users/builder/data/lanes/3818/ad1cd42d/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/3818/ad1cd42d/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/3818/ad1cd42d/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128
at System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () [0x00000] in /Users/builder/data/lanes/3818/ad1cd42d/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:357
at App2.Model.Database.FormDAO+<InsertItem>d__2.MoveNext () [0x00066] in D:\SourceTree\App2\App2\Model\Database\FormDAO.cs:25
This is the code where the unhandled exception is:
public async void InsertItem(Form Form)
{
try
{
var result = await Task.Factory.StartNew(() => database.Insert(Form)); //this line
} catch(Exception e)
{
Debug.WriteLine("e.message" + e.Message + ";;;;" + e.StackTrace);
}
}
The function InsertItem(form) is called about 1000 times from another async method.
Why does this code not work on iOS?
Edit:
Other error I get is:
SQLite.SQLiteException: IOError
StackTrace:
at SQLite.PreparedSqlLiteInsertCommand.ExecuteNonQuery (System.Object[] source) [0x00116] in /Users/fak/Dropbox/Projects/sqlite-net/src/SQLite.cs:2480
at SQLite.SQLiteConnection.Insert (System.Object obj, System.String extra, System.Type objType) [0x0010e] in /Users/fak/Dropbox/Projects/sqlite-net/src/SQLite.cs:1381
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/3818/ad1cd42d/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00047] in /Users/builder/data/lanes/3818/ad1cd42d/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/3818/ad1cd42d/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/3818/ad1cd42d/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128
at System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () [0x00000] in /Users/builder/data/lanes/3818/ad1cd42d/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:357
at App2.Model.Database.CourseDAO+<InsertItem>d__2.MoveNext () [0x00055] in D:\SourceTree\App2\App2\Model\Database\CourseDAO.cs:26
This exception is throwed when using almost the same method but then with this line:
var result = await Task.Factory.StartNew(() => database.Insert(Course));
The problem were the async calls to the database as Yuri S and SushiHangover pointed out in the comments.
First I didn't thought that the problem were the async calls to the database because it did work on Android and UWP. But when I made all the calls synchronised the database did work on all the three platforms: UWP, Android, iOS.
Thanks!

Categories