ThreadPool or Timers tasks are not waiting properly - c#

After updating Android's Support Libraries (v28.0+) to get targeted with monoandroid90, the app crashes sometimes with the stack trace I provided bellow. If there are breakpoints active this won't happen.
Different versions of Xamarin.Android were tested, the current one I'm using is the latest 9.4 that comes with the default vs19. I was not able to reproduce this on a fresh install of the vs17 with the default XA that comes with it (9.1.7.0)
The following stack trace shows the current problem I'm facing.
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () <0x00007>
at (wrapper runtime-invoke) <Module>.runtime_invoke_bool (object,intptr,intptr,intptr) [0x0002b] in <ff07eae8184a40a08e79049bbcb31a0e>:0
"Finalizer"08-06 16:26:25.748 E/mono (11487): Full thread dump:
"Thread Pool Worker" at <unknown> <0xffffffff>
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () <0x00007>
at (wrapper runtime-invoke) <Module>.runtime_invoke_bool (object,intptr,intptr,intptr) [0x0002b] in <ff07eae8184a40a08e79049bbcb31a0e>:0
"Debugger agent"
"Timer-Scheduler" at <unknown> <0xffffffff>
at (wrapper managed-to-native) System.Threading.WaitHandle.Wait_internal (intptr*,int,bool,int) <0x00007>
at System.Threading.WaitHandle.WaitOneNative (System.Runtime.InteropServices.SafeHandle,uint,bool,bool) [0x0001f] in <ff07eae8184a40a08e79049bbcb31a0e>:0
at System.Threading.WaitHandle.InternalWaitOne (System.Runtime.InteropServices.SafeHandle,long,bool,bool) [0x00019] in <ff07eae8184a40a08e79049bbcb31a0e>:0
at System.Threading.WaitHandle.WaitOne (long,bool) [0x00010] in <ff07eae8184a40a08e79049bbcb31a0e>:0
at System.Threading.WaitHandle.WaitOne (int,bool) [0x0001d] in <ff07eae8184a40a08e79049bbcb31a0e>:0
at System.Threading.WaitHandle.WaitOne (int) [0x00003] in <ff07eae8184a40a08e79049bbcb31a0e>:0
at System.Threading.Timer/Scheduler.SchedulerThread () [0x00043] in <ff07eae8184a40a08e79049bbcb31a0e>:0
at System.Threading.ThreadHelper.ThreadStart_Context (object) [0x0001f] in <ff07eae8184a40a08e79049bbcb31a0e>:0
at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext,System.Threading.ContextCallback,object,bool) [0x00073] in <ff07eae8184a40a08e79049bbcb31a0e>:0
at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext,System.Threading.ContextCallback,object,bool) [0x00004] in <ff07eae8184a40a08e79049bbcb31a0e>:0
at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext,System.Threading.ContextCallback,object) [0x0002f] in <ff07eae8184a40a08e79049bbcb31a0e>:0
at System.Threading.ThreadHelper.ThreadStart () [0x00014] in <ff07eae8184a40a08e79049bbcb31a0e>:0
at (wrapper runtime-invoke) object.runtime_invoke_void__this__ (object,intptr,intptr,intptr) [0x00067] in <ff07eae8184a40a08e79049bbcb31a0e>:0
"<unnamed thread>"
08-06 16:26:35.755 I/libc (11487): Requested dump for tid 11487 (ler.challengeme)
Anybody else has ever faced this issue and is aware of a possible solution?

Related

Xamarin camera2 api is in background not working

I am interested in Xamarin and I search, how I can take a photo from camera without device's native camera application. And I found Camera2 API, then I search sample app and I found this sample app: https://learn.microsoft.com/en-us/samples/xamarin/monodroid-samples/android50-camera2basic/
It worked very well when I tried it in the foreground but it gives an error when I put it in the background.
How can I get it running in the background?
Camera2BasicFragment.cs codes: https://paste.ubuntu.com/p/CqDkyMx8qW/
Exceptions:
Exception image 1
Exception image 2
Exception Text:
{Java.Lang.IllegalStateException: CameraDevice was already closed at Java.Interop.JniEnvironment+InstanceMethods.CallIntMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x0006e] in <dac4c5a4b77f4e61a5e6d9d3050dfb9f>:0 at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeAbstractInt32Method (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x00014] in <dac4c5a4b77f4e61a5e6d9d3050dfb9f>:0 at Android.Hardware.Camera2.CameraCaptureSessionInvoker.Capture (Android.Hardware.Camera2.CaptureRequest request, Android.Hardware.Camera2.CameraCaptureSession+CaptureCallback listener, Android.OS.Handler handler) [0x0006e] in /Users/builder/azdo/_work/204/s/xamarin-android/src/Mono.Android/obj/Release/monoandroid10/android-27/mcw/Android.Hardware.Camera2.CameraCaptureSession.cs:969 at Camera2Basic.Camera2BasicFragment.LockFocus () [0x00020] in C:\Users\Harun\Desktop\x\Camera2Basic\Camera2BasicFragment.cs:576 at Camera2Basic.Camera2BasicFragment.TakePicture () [0x00001] in C:\Users\Harun\Desktop\x\Camera2Basic\Camera2BasicFragment.cs:563 at Camera2Basic.Camera2BasicFragment.OnClick (Android.Views.View v) [0x00013] in C:\Users\Harun\Desktop\x\Camera2Basic\Camera2BasicFragment.cs:676 at Android.Views.View+IOnClickListenerInvoker.n_OnClick_Landroid_view_View_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_v) [0x00010] in /Users/builder/azdo/_work/204/s/xamarin-android/src/Mono.Android/obj/Release/monoandroid10/android-27/mcw/Android.Views.View.cs:2176 at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.19(intptr,intptr,intptr) --- End of managed Java.Lang.IllegalStateException stack trace ---java.lang.IllegalStateException: CameraDevice was already closed at android.hardware.camera2.impl.CameraDeviceImpl.checkIfCameraClosedOrInError(CameraDeviceImpl.java:1997) at android.hardware.camera2.impl.CameraDeviceImpl.submitCaptureRequest(CameraDeviceImpl.java:844) at android.hardware.camera2.impl.CameraDeviceImpl.capture(CameraDeviceImpl.java:741) at android.hardware.camera2.impl.CameraCaptureSessionImpl.capture(CameraCaptureSessionImpl.java:179) at crc64b678081366886b9e.Camera2BasicFragment.n_onClick(Native Method) at crc64b678081366886b9e.Camera2BasicFragment.onClick(Camera2BasicFragment.java:77) at android.view.View.performClick(View.java:5721) at android.widget.TextView.performClick(TextView.java:10936) 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:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:7406) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)}

Realm Xamarin - Error on GetInstance()

I set my main page in this way:
namespace MyNamepage
{
public partial class MyPage: ContentPage
{
private Realm realm;
public MyPage()
{
InitializeComponent();
this.realm = Realm.GetInstance();
}
}
}
Debugging the Android project i got this error and the app crash:
System.Reflection.TargetInvocationException: Exception has been thrown
by the target of an invocation.
I've installed "Realm" in PCL and in Droid Project using NuGet but it seems doesn't work.
If i remove the GetInstance() call, the app doesn't crash;
Stack trace:
10-17 10:36:31.935 I/MonoDroid(31518): UNHANDLED EXCEPTION:
10-17 10:36:31.955 I/MonoDroid(31518): System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.PlatformNotSupportedException: The PCL build of Realm is being linked which probably means you need to use NuGet or otherwise link a platform-specific Realm.dll to your main application.
10-17 10:36:31.955 I/MonoDroid(31518): at Realms.RealmPCLHelpers.ThrowProxyShouldNeverBeUsed () [0x00000] in <filename unknown>:0
10-17 10:36:31.955 I/MonoDroid(31518): at Realms.Realm.GetInstance (Realms.RealmConfiguration config) [0x00000] in <filename unknown>:0
10-17 10:36:31.955 I/MonoDroid(31518): at MyPack.SidePage.MyPage..ctor () [0x00008] in C:\Users\User\documents\visual studio 2015\Projects\MyPack\MyPack\MyPack\SidePage\MyPage.xaml.cs:14
10-17 10:36:31.955 I/MonoDroid(31518): at (wrapper managed-to-native) System.Reflection.MonoCMethod:InternalInvoke (System.Reflection.MonoCMethod,object,object[],System.Exception&)
10-17 10:36:31.955 I/MonoDroid(31518): at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00002] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:644
10-17 10:36:31.965 I/MonoDroid(31518): --- End of inner exception stack trace ---
10-17 10:36:31.965 I/MonoDroid(31518): at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00016] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:650
10-17 10:36:31.965 I/MonoDroid(31518): at System.RuntimeType.CreateInstanceMono (Boolean nonPublic) [0x000ca] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/mcs/class/corlib/ReferenceSources/RuntimeType.cs:115
10-17 10:36:31.965 I/MonoDroid(31518): at System.RuntimeType.CreateInstanceSlow (Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, System.Threading.StackCrawlMark& stackMark) [0x0001a] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/mcs/class/corlib/ReferenceSources/RuntimeType.cs:89
10-17 10:36:31.965 I/MonoDroid(31518): at System.RuntimeType.CreateInstanceDefaultCtor (Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, System.Threading.StackCrawlMark& stackMark) [0x0002a] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/external/referencesource/mscorlib/system/rttype.cs:5599
10-17 10:36:31.965 I/MonoDroid(31518): at System.Activator.CreateInstance (System.Type type, Boolean nonPublic) [0x00040] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/external/referencesource/mscorlib/system/activator.cs:201
10-17 10:36:31.965 I/MonoDroid(31518): at System.Activator.CreateInstance (System.Type type) [0x00000] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/external/referencesource/mscorlib/system/activator.cs:134
10-17 10:36:31.965 I/MonoDroid(31518): at MyPack.MainPage.OnItemSelected (System.Object sender, Xamarin.Forms.SelectedItemChangedEventArgs e) [0x00016] in C:\Users\User\documents\visual studio 2015\Projects\MyPack\MyPack\MyPack\MainPage.xaml.cs:24
10-17 10:36:31.965 I/MonoDroid(31518): at (wrapper delegate-invoke) System.EventHandler`1[Xamarin.Forms.SelectedItemChangedEventArgs]:invoke_void_object_TEventArgs (object,Xamarin.Forms.SelectedItemChangedEventArgs)
10-17 10:36:31.975 I/MonoDroid(31518): at Xamarin.Forms.ListView.OnSelectedItemChanged (Xamarin.Forms.BindableObject bindable, System.Object oldValue, System.Object newValue) [0x0001c] in <filename unknown>:0
10-17 10:36:31.975 I/MonoDroid(31518): at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindablePropertyContext context, System.Object value, Boolean currentlyApplying, SetValueFlags attributes, Boolean silent) [0x0010e] in <filename unknown>:0
10-17 10:36:31.975 I/MonoDroid(31518): at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes) [0x0014b] in <filename unknown>:0
10-17 10:36:31.975 I/MonoDroid(31518): at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, SetValueFlags attributes) [0x00000] in <filename unknown>:0
10-17 10:36:31.975 I/MonoDroid(31518): at Xamarin.Forms.ListView.NotifyRowTapped (Int32 groupIndex, Int32 inGroupIndex, Xamarin.Forms.Cell cell) [0x0004c] in <filename unknown>:0
10-17 10:36:31.975 I/MonoDroid(31518): at Xamarin.Forms.ListView.NotifyRowTapped (Int32 index, Xamarin.Forms.Cell cell) [0x00023] in <filename unknown>:0
10-17 10:36:31.975 I/MonoDroid(31518): at Xamarin.Forms.Platform.Android.ListViewAdapter.HandleItemClick (Android.Widget.AdapterView parent, Android.Views.View view, Int32 position, Int64 id) [0x00056] in <filename unknown>:0
10-17 10:36:31.975 I/MonoDroid(31518): at Xamarin.Forms.Platform.Android.CellAdapter.OnItemClick (Android.Widget.AdapterView parent, Android.Views.View view, Int32 position, Int64 id) [0x0002e] in <filename unknown>:0
10-17 10:36:31.975 I/MonoDroid(31518): at Android.Widget.AdapterView+IOnItemClickListenerInvoker.n_OnItemClick_Landroid_widget_AdapterView_Landroid_view_View_IJ (IntPtr jnienv, IntPtr native__this, IntPtr native_parent, IntPtr native_view, Int32 position, Int64 id) [0x00019] in /Users/builder/data/lanes/3415/7db2aac3/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.Widget.AdapterView.cs:215
10-17 10:36:31.975 I/MonoDroid(31518): at (wrapper dynamic-method) System.Object:585983a8-79f2-48a3-ac33-5b4c905219f1 (intptr,intptr,intptr,intptr,int,long)
10-17 10:36:31.995 D/Mono (31518): DllImport searching in: '__Internal' ('(null)').
10-17 10:36:31.995 D/Mono (31518): Searching for 'java_interop_jnienv_throw'.
10-17 10:36:31.995 D/Mono (31518): Probing 'java_interop_jnienv_throw'.
10-17 10:36:31.995 D/Mono (31518): Found as 'java_interop_jnienv_throw'.
An unhandled exception occured.
10-17 10:36:34.115 E/mono (31518):
10-17 10:36:34.115 E/mono (31518): Unhandled Exception:
10-17 10:36:34.115 E/mono (31518): System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.PlatformNotSupportedException: The PCL build of Realm is being linked which probably means you need to use NuGet or otherwise link a platform-specific Realm.dll to your main application.
10-17 10:36:34.115 E/mono (31518): at Realms.RealmPCLHelpers.ThrowProxyShouldNeverBeUsed () [0x00000] in <filename unknown>:0
10-17 10:36:34.115 E/mono (31518): at Realms.Realm.GetInstance (Realms.RealmConfiguration config) [0x00000] in <filename unknown>:0
10-17 10:36:34.115 E/mono (31518): at MyPack.SidePage.MyPage..ctor () [0x00008] in C:\Users\User\documents\visual studio 2015\Projects\MyPack\MyPack\MyPack\SidePage\MyPage.xaml.cs:14
10-17 10:36:34.115 E/mono (31518): at (wrapper managed-to-native) System.Reflection.MonoCMethod:InternalInvoke (System.Reflection.MonoCMethod,object,object[],System.Exception&)
10-17 10:36:34.115 E/mono (31518): at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00002] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:644
10-17 10:36:34.115 E/mono (31518): --- End of inner exception stack trace ---
10-17 10:36:34.115 E/mono (31518): at (wrapper dynamic-method) System.Object:585983a8-79f2-48a3-ac33-5b4c905219f1 (intptr,intptr,intptr,intptr,int,long)
10-17 10:36:34.115 E/mono (31518): at (wrapper native-to-managed) System.Object:585983a8-79f2-48a3-ac33-5b4c905219f1 (intptr,intptr,intptr,intptr,int,long)
10-17 10:36:34.115 E/mono-rt (31518): [ERROR] FATAL UNHANDLED EXCEPTION: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.PlatformNotSupportedException: The PCL build of Realm is being linked which probably means you need to use NuGet or otherwise link a platform-specific Realm.dll to your main application.
10-17 10:36:34.115 E/mono-rt (31518): at Realms.RealmPCLHelpers.ThrowProxyShouldNeverBeUsed () [0x00000] in <filename unknown>:0
10-17 10:36:34.115 E/mono-rt (31518): at Realms.Realm.GetInstance (Realms.RealmConfiguration config) [0x00000] in <filename unknown>:0
10-17 10:36:34.115 E/mono-rt (31518): at MyPack.SidePage.MyPage..ctor () [0x00008] in C:\Users\User\documents\visual studio 2015\Projects\MyPack\MyPack\MyPack\SidePage\MyPage.xaml.cs:14
10-17 10:36:34.115 E/mono-rt (31518): at (wrapper managed-to-native) System.Reflection.MonoCMethod:InternalInvoke (System.Reflection.MonoCMethod,object,object[],System.Exception&)
10-17 10:36:34.115 E/mono-rt (31518): at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00002] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:644
10-17 10:36:34.115 E/mono-rt (31518): --- End of inner exception stack trace ---
10-17 10:36:34.115 E/mono-rt (31518): at (wrapper dynamic-method) System.Object:585983a8-79f2-48a3-ac33-5b4c905219f1 (intptr,intptr,intptr,intptr,int,long)
10-17 10:36:34.115 E/mono-rt (31518): at (wrapper native-to-managed) System.Object:585983a8-79f2-48a3-ac33-5b4c905219f1 (intptr,intptr,intptr,intptr,int,long)
In mgmain JNI_OnLoad
As the stack trace indicates and the path you have posted in the comments shows. You have installed the PCL version into the platform specific projects. Which is why it throws the PlatformNotSupportedException exception you are getting.
Try reinstalling the NuGet in your platform specific projects. Alternatively you can manually change the reference to point at:
packages\Realm.0.78.1\lib\MonoAndroid44\Realm.dll
You shouldn't have any reference to the portable folder in your platform specific project.
I had a similar problem using Xamarin.Forms 3.4.0.1008975 with Realm 4.0.1
Unhandled Exception: System.TypeInitializationException: The type
initializer for 'Realms.SharedRealmHandle' threw an exception.
occurred
The solution was to completely uninstall the nuget Realm package from all projects in the solution and reinstall Realm back again. Also make sure that you have the FodyWeaver.xml file in all projects.

Missing method exception when referencing Google Maps class

I'm getting a System.MissingMethodException when I try to instantiate a Dictionary using the Android.Gms.Maps.Model.Marker class as follows:
Dictionary<Marker, MyInnerClass> _markers = new Dictionary<Marker, MyInnerClass>();
I suspect that somehow a needed dll is not being loaded but don't know why. The problem seems to be specific to my specific dev environment since other developers with the same code are not seeing this problem. I can reproduce the issue in Genymotion, an Asus Tablet and a GS4 all running Android 4.2.2.
Application output reports the following:
[] Missing method Android.Runtime.JNIEnv::AllocObject(Type) in assembly Mono.Android.dll, referenced in assembly GooglePlayServices.dll
Here's the stack trace:
System.MissingMethodException: Method not found: 'Android.Runtime.JNIEnv.AllocObject'.
at MyProduct.Maps.MyMapFragment..ctor () [0x00013] in /Users/me/code/my.domain/MyProduct/Maps/MyMapFragment.cs:48
at at (wrapper dynamic-method) object.ffa689fb-fdde-4e08-abd8-3bdf6ae641fb (intptr,object[]) <IL 0x00018, 0x00037>
at Java.Interop.TypeManager.n_Activate (intptr,intptr,intptr,intptr,intptr,intptr) [0x00070] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.8.2-branch/a25a31d0/source/monodroid/src/Mono.Android/src/Java.Interop/TypeManager.cs:141
at at (wrapper native-to-managed) Java.Interop.TypeManager.n_Activate (intptr,intptr,intptr,intptr,intptr,intptr) <IL 0x00020, 0x0007f>
at at (wrapper managed-to-native) object.wrapper_native_0xb65e0e20 (intptr,intptr,intptr,intptr,Android.Runtime.JValue[]) <0x00003>
at Android.Runtime.JNIEnv.CallNonvirtualVoidMethod (intptr,intptr,intptr,Android.Runtime.JValue[]) [0x00000] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.8.2-branch/a25a31d0/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:612
at Android.App.Activity.SetContentView (int) [0x00070] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.8.2-branch/a25a31d0/source/monodroid/src/Mono.Android/platforms/android-15/src/generated/Android.App.Activity.cs:3824
at MyProduct.MyListActivity.OnCreate (Android.OS.Bundle) [0x00079] in /Users/me/code/my.domain/MyProduct/MyListActivity.cs:83
at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (intptr,intptr,intptr) [0x00011] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.8.2-branch/a25a31d0/source/monodroid/src/Mono.Android/platforms/android-15/src/generated/Android.App.Activity.cs:1937
at at (wrapper dynamic-method) object.24a01956-09ee-4dec-9155-eff468f7249c (intptr,intptr,intptr) <IL 0x00017, 0x0001f>
Android.Runtime.JNIEnv.AllocObject() is a method that was added to Xamarin.Android 4.10.1.
It would seem that GooglePlayServices.dll was built against 4.10, while your app was packaged against 4.8 (which doesn't contain AllocObject()). This would explain the MissingMethodException.
Xamarin.Android 4.10.1 is now stable; please upgrade.

Problem with C# List when compiled in mono (homework-related)

I'll admit this is my homework. The task statement said I have to write a program that finds a topological order of a graph which would be inputted by standard input. Then I need to submit it to be graded on the professor's server.
Now it's not the algorithm problem. It's more of a technical problem. In my computer, I use .NET compiler (csc) while the professor's grading machine uses some form of mono.
It works well, until the grader said I got 30/100. A friend of mine suggested that I use the grader's "manual input system", so here I go, I made it create array-of-100000 lists for the adjacency list.
The grader, after a few seconds, reported that my program has crashed.
Stacktrace:
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0x00004>
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0xffffffff>
at System.Exception.ToString () <0x00026>
at (wrapper runtime-invoke) object.runtime_invoke_object__this__ (object,intptr,intptr,intptr) <0xffffffff>
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0x00004>
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0xffffffff>
at System.Exception.ToString () <0x00026>
at (wrapper runtime-invoke) object.runtime_invoke_object__this__ (object,intptr,intptr,intptr) <0xffffffff>
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0x00004>
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0xffffffff>
at System.Exception.ToString () <0x00026>
at (wrapper runtime-invoke) object.runtime_invoke_object__this__ (object,intptr,intptr,intptr) <0xffffffff>
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0x00004>
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0xffffffff>
at System.Exception.ToString () <0x00026>
at (wrapper runtime-invoke) object.runtime_invoke_object__this__ (object,intptr,intptr,intptr) <0xffffffff>
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0x00004>
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0xffffffff>
at System.Exception.ToString () <0x00026>
at (wrapper runtime-invoke) object.runtime_invoke_object__this__ (object,intptr,intptr,intptr) <0xffffffff>
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0x00004>
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0xffffffff>
at System.Exception.ToString () <0x00026>
at (wrapper runtime-invoke) object.runtime_invoke
This is kinda strange and unsettling to me, but I have yet to find an answer for this. Again, this program worked really fine on my PC.
This is my part of the program:
using System;
using System.Collections;
using System.Collections.Generic;
class topo{
public static void Main(){
string[] ST = Console.ReadLine().Split(' ');
int N=Convert.ToInt32(ST[0]), M=Convert.ToInt32(ST[1]);
int[] ins = new int[N]; //node's total in-degrees
List<int>[] E = new List<int>[N];
for(int n=0;n<N;n++)
E[n] = new List<int>();
for(int m=0;m<M;m++){
ST = Console.ReadLine().Split(' ');
int u = Convert.ToInt32(ST[0]);
int v = Convert.ToInt32(ST[1]);
E[u-1].Add(v-1);
ins[v-1]++;
}
Queue S = new Queue();
List<int> L = new List<int>(); //result list
for(int n=0;n<N;n++){
//add stranded nodes directly and don't process it
if(ins[n]==0 && E[n].Count==0)
L.Add(n);
//put into queue
else if(ins[n]==0)
S.Enqueue(n);
}
while(S.Count>0){
int n = (int) S.Dequeue();
L.Add(n);
foreach(int m in E[n])
if(--ins[m]==0)
S.Enqueue(m);
}
foreach(int n in L)
Console.WriteLine(n+1);
}
}
Thank you very much, and I appreciate any and every response.
Edit: I took another look at the grader's output to see if I missed anything, and indeed I did. It said "syscal: 2", but all I know about it is that "the program didn't exit normally."
Edit #2: I've tried making the program attempt to make various sizes of the array-of-list, ranging from 5000, 10000, etc. and after 40000 the "manual input system" said the program got a System.OutOfMemoryException. With further look into various parts of the grader that the students are allowed into, it seems that prof misconfigured his grading parameters and gave us less memory than announced. (He said "32MB", but the program crashes at about 16MB)
I've reported the error to him and he is (right now) looking into it.
The following code is going to fail if the value of u or v is less than 1.
for(int m=0;m<M;m++){
ST = Console.ReadLine().Split(' ');
int u = Convert.ToInt32(ST[0]);
int v = Convert.ToInt32(ST[1]);
E[u-1].Add(v-1);
ins[v-1]++;
}
Because u-1 or v-1 is going to be negative, and that will throw an exception.
Followup: This is anecdotal, self-answer, and very late because I just realized that it's okay to answer myself. I was later notified that I went over the memory limit enforced by the grading system. However, the exception was quite cryptic in my case and the grader did not report this issue. (It marked me only as incorrect.)
I was also quite careless to not realize that smaller inputs worked, and that's why I got 30/100 and not zero points.
For future readers: When programming in an automatic-grader environment, please make sure your program does not go over the memory limit, which may be there but may not be known to you (i.e. not written in problem statement).

How to debug a Mono project that builds but can't run?

How do I debug a mono project? I can't seem to run it. It builds perfectly. But running it is another issue altogether.
This is the output from running it.
$ mono SvnTest.exe update
Stacktrace:
at (wrapper managed-to-native) System.Runtime.InteropServices.Marshal.PtrToStringAnsi (intptr) <0x00045>
at (wrapper managed-to-native) System.Runtime.InteropServices.Marshal.PtrToStringAnsi (intptr) <0x00045>
at PumaCode.SvnDotNet.AprSharp.AprString.ToString () <0x0004b>
at PumaCode.SvnDotNet.SubversionSharp.SvnException.ExtractMessage (PumaCode.SvnDotNet.SubversionSharp.SvnError) <0x00033>
at PumaCode.SvnDotNet.SubversionSharp.SvnException..ctor (PumaCode.SvnDotNet.SubversionSharp.SvnError) <0x0001b>
at PumaCode.SvnDotNet.SubversionSharp.SvnClient.Update (PumaCode.SvnDotNet.SubversionSharp.SvnPath,PumaCode.SvnDotNet.SubversionSharp.SvnOptRevision,bool,PumaCode.SvnDotNet.SubversionSharp.SvnClientContext,PumaCode.SvnDotNet.AprSharp.AprPool) <0x000e3>
at PumaCode.SvnDotNet.SubversionSharp.SvnClient.Update (string,PumaCode.SvnDotNet.SubversionSharp.SvnRevision,bool) <0x0009f>
at PumaCode.SvnDotNet.SubversionSharp.SvnMockApp.UpdateCmd.Execute () <0x0015f>
at PumaCode.SvnDotNet.SubversionSharp.SvnMockApp.CmdBase.Run (PumaCode.SvnDotNet.SubversionSharp.SvnMockApp.Application/SubCommand,string[]) <0x00551>
at (wrapper runtime-invoke) <Module>.runtime_invoke_int__this___object_object (object,intptr,intptr,intptr) <0x00060>
at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke (object,object[],System.Exception&) <0x00057>
at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke (object,object[],System.Exception&) <0x00057>
at System.Reflection.MonoMethod.Invoke (object,System.Reflection.BindingFlags,System.Reflection.Binder,object[],System.Globalization.CultureInfo) <0x001ab>
at System.Reflection.MethodBase.Invoke (object,object[]) <0x0002d>
at PumaCode.SvnDotNet.SubversionSharp.SvnMockApp.Application.Run (string[]) <0x0034b>
at PumaCode.SvnDotNet.SubversionSharp.SvnMockApp.Application.Main (string[]) <0x00037>
at (wrapper runtime-invoke) <Module>.runtime_invoke_int_object (object,intptr,intptr,intptr) <0x00054>
Native stacktrace:
mono() [0x48419c]
mono() [0x4ce1bf]
/lib/libpthread.so.0(+0xee80) [0x7f64b72b2e80]
/lib/libc.so.6(strlen+0x12) [0x7f64b6d477c2]
mono(mono_string_new+0x1d) [0x57f80d]
[0x4047e705]
Debug info from gdb:
=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
=================================================================
Aborted
toString() method
public override string ToString()
{
if(IsNull)
return ("[apr_string:NULL]");
else
return (Marshal.PtrToStringAnsi(mString));
}
Clearly the mString member contains a garbage pointer. Judging from the call stack, you'll need help from the SubversionSharp team. Or find out somehow why it is trying to handle a Subversion error.
The last post at their web site dates from 2006, "We're not dead!". Their forum server looks pretty dead to me though. Good luck.

Categories

Resources