Mono Bug : Magic number is wrong: 542 - c#

I am trying to compile a C# Hello World application in Rider on Linux.
When I try to run the app, I am promted the following exception:
Unhandled Exception:
System.TypeInitializationException: The type initializer for 'System.Console' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.ConsoleDriver' threw an exception. ---> System.Exception: Magic number is wrong: 542
at System.TermInfoReader.ReadHeader (System.Byte[] buffer, System.Int32& position) [0x00028] in <a84b655e5e6a49ee96b338ec792f5580>:0
at System.TermInfoReader..ctor (System.String term, System.String filename) [0x0005f] in <a84b655e5e6a49ee96b338ec792f5580>:0
at System.TermInfoDriver..ctor (System.String term) [0x00055] in <a84b655e5e6a49ee96b338ec792f5580>:0
at System.ConsoleDriver.CreateTermInfoDriver (System.String term) [0x00000] in <a84b655e5e6a49ee96b338ec792f5580>:0
at System.ConsoleDriver..cctor () [0x0004d] in <a84b655e5e6a49ee96b338ec792f5580>:0
--- End of inner exception stack trace ---
at System.Console.SetupStreams (System.Text.Encoding inputEncoding, System.Text.Encoding outputEncoding) [0x00007] in <a84b655e5e6a49ee96b338ec792f5580>:0
at System.Console..cctor () [0x0008e] in <a84b655e5e6a49ee96b338ec792f5580>:0
--- End of inner exception stack trace ---
at TestCaseApp.Program.Main (System.String[] args) [0x00001] in <662667bfa1e4443ea031df076247d2d3>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: The type initializer for 'System.Console' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.ConsoleDriver' threw an exception. ---> System.Exception: Magic number is wrong: 542
at System.TermInfoReader.ReadHeader (System.Byte[] buffer, System.Int32& position) [0x00028] in <a84b655e5e6a49ee96b338ec792f5580>:0
at System.TermInfoReader..ctor (System.String term, System.String filename) [0x0005f] in <a84b655e5e6a49ee96b338ec792f5580>:0
at System.TermInfoDriver..ctor (System.String term) [0x00055] in <a84b655e5e6a49ee96b338ec792f5580>:0
at System.ConsoleDriver.CreateTermInfoDriver (System.String term) [0x00000] in <a84b655e5e6a49ee96b338ec792f5580>:0
at System.ConsoleDriver..cctor () [0x0004d] in <a84b655e5e6a49ee96b338ec792f5580>:0
--- End of inner exception stack trace ---
at System.Console.SetupStreams (System.Text.Encoding inputEncoding, System.Text.Encoding outputEncoding) [0x00007] in <a84b655e5e6a49ee96b338ec792f5580>:0
at System.Console..cctor () [0x0008e] in <a84b655e5e6a49ee96b338ec792f5580>:0
--- End of inner exception stack trace ---
at TestCaseApp.Program.Main (System.String[] args) [0x00001] in <662667bfa1e4443ea031df076247d2d3>:0
I am using Antergos (Linux) and JetBrains Rider 2017.3.1
Build #RD-173.3994.2442
I have am using Mono 5.4.1.7-2
I did some research about this bug and I found:
https://github.com/mono/mono/issues/6752#issuecomment-365212655
Mono compiler // Terminal emulator issue
Everything mentioned in these threads didn't help me to fix this issue. What can I do?

Did you not follow the instructions on that page? You need to set your TERM environmental variable to xterm as a fix:
export TERM=xterm
Then verify it is changed with:
echo $TERM

The means exactly this: "I want to run your script, but you need to specify the terminal you want me to use"
In GoG version of Stardew Valley, the script in question is: ./start.sh
Launching this causes the above error.
If instead:
export 'TERM=roxterm' && ./start.sh
then it works because I have the roxterm terminal installed on my system and the script can use it to execute. What I do know is the global parameter in Ubuntu that tells scrips use this unless it is: Default Applications
Looking at snippet of the script, originally it is:
run_game() {
echo "Running ${GAME_NAME}"
cd game
chmod +x *
./"StardewValley"
}
Corrected for roxterm it would be:
run_game() {
echo "Running ${GAME_NAME}"
cd game
chmod +x *
export 'TERM=roxterm' && ./"StardewValley"
}
The latter solution works with application launchers and is thus superior.

Related

RestSharp RestRequest Constructor throwing OverflowException

Occasionally the following line throws a System.OverflowException:
var request = new RestRequest("", Method.GET, DataFormat.Json);
This is running on a Raspbian OS using the Mono Runtime.
The Exception never happened on Windows where the application was developed.
Full Stacktrace:
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: The type initializer for 'RestSharp.RestRequest' threw an exception. --->
System.TypeInitializationException: The type initializer for 'System.Text.RegularExpressions.Regex' threw an exception. --->
System.OverflowException: TimeSpan overflowed because the duration is too long.
at System.TimeSpan.Interval (System.Double value, System.Int32 scale) <0xb4a01520 + 0x0010c> in <d0a5e45894084fd7b6ea7e0fe6ac414c>:0
at System.TimeSpan.FromMilliseconds (System.Double value) <0xb4a0165c + 0x0001b> in <d0a5e45894084fd7b6ea7e0fe6ac414c>:0
at System.Text.RegularExpressions.Regex..cctor () [0x0001c] in <c0e40d34c25e4827874530676d4126b9>:0
--- End of inner exception stack trace ---
at (wrapper managed-to-native) System.Object.__icall_wrapper_mono_generic_class_init(intptr)
at RestSharp.RestRequest..cctor () [0x00000] in <bc58aa49caeb486c80c16d44db0069c3>:0

Strange Unhandled Exception from mono

We use mono 4.8.0 for our product. When running particular testings on different kinds of Linux, we got unhandled exception triggered occasionally. More specifically AppDomain.UnhandledException event triggered. But we can't figure out which line of our code triggered the exception. I'm wondering is this a defect of mono?
[ERROR] FATAL UNHANDLED EXCEPTION: System.ExecutionEngineException: ExecutionContext_ExceptionInAsyncLocalNotification ---> System.Threading.ThreadAbortException
at System.Collections.Generic.ObjectEqualityComparer'1[T].Equals (T x, T y) <0x7f0f20aa1e80 + 0x00000> in :0
at System.Collections.Generic.Dictionary'2[TKey,TValue].FindEntry (TKey key) [0x0005d] in :0
at System.Collections.Generic.Dictionary'2[TKey,TValue].TryGetValue (TKey key, TValue& value) [0x00000] in :0
at System.Threading.ExecutionContext.OnAsyncLocalContextChanged (System.Threading.ExecutionContext previous, System.Threading.ExecutionContext current) [0x00119] in ...../mono/mono/mcs/class/referencesource/mscorlib/system/threading/executioncontext.cs:749
--- End of inner exception stack trace ---
at System.Environment.FailFast (System.String message, System.Exception exception) [0x00000] in ...../mono/mono/mcs/class/corlib/System/Environment.cs:929
at System.Threading.ExecutionContext.OnAsyncLocalContextChanged (System.Threading.ExecutionContext previous, System.Threading.ExecutionContext current) [0x00164] in ..../mono/mono/mcs/class/referencesource/mscorlib/system/threading/executioncontext.cs:758
at System.Threading.ExecutionContext.SetExecutionContext (System.Threading.ExecutionContext executionContext, System.Boolean preserveSyncCtx) [0x0005f] in ..../mono/mono/mcs/class/referencesource/mscorlib/system/threading/executioncontext.cs:1028
Thanks
Try <AppContextSwitchOverrides value="Switch.System.Globalization.NoAsyncCurrentCulture=true" /> and avoid using AsyncLocal<T>

Mono compiler // Terminal emulator issue

I get this error when I try to compile csharp or fsharp files. This happens when using gnome terminal or jetbrain rider.
It works fine in tty or termials like xterm and urxvt.
Also I am able to compile c, c++ and go code.
Btw, I am using Arch/Antergos and got this issue yesterday.
Unhandled Exception:
System.TypeInitializationException: The type initializer for 'System.Console' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.ConsoleDriver' threw an exception. ---> System.Exception: Magic number is wrong: 542
at System.TermInfoReader.ReadHeader (System.Byte[] buffer, System.Int32& position) [0x00028] in :0
at System.TermInfoReader..ctor (System.String term, System.String filename) [0x0005f] in :0
at System.TermInfoDriver..ctor (System.String term) [0x00055] in :0
at System.ConsoleDriver.CreateTermInfoDriver (System.String term) [0x00000] in :0
at System.ConsoleDriver..cctor () [0x0004d] in :0
--- End of inner exception stack trace ---
at System.Console.SetupStreams (System.Text.Encoding inputEncoding, System.Text.Encoding outputEncoding) [0x00007] in :0
at System.Console..cctor () [0x0008e] in :0
--- End of inner exception stack trace ---
at Mono.CSharp.Driver.Main (System.String[] args) [0x00019] in <2b1e99ce45b54209bdcdab138d9758ae>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: The type initializer for 'System.Console' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.ConsoleDriver' threw an exception. ---> System.Exception: Magic number is wrong: 542
at System.TermInfoReader.ReadHeader (System.Byte[] buffer, System.Int32& position) [0x00028] in :0
at System.TermInfoReader..ctor (System.String term, System.String filename) [0x0005f] in :0
at System.TermInfoDriver..ctor (System.String term) [0x00055] in :0
at System.ConsoleDriver.CreateTermInfoDriver (System.String term) [0x00000] in :0
at System.ConsoleDriver..cctor () [0x0004d] in :0
--- End of inner exception stack trace ---
at System.Console.SetupStreams (System.Text.Encoding inputEncoding, System.Text.Encoding outputEncoding) [0x00007] in :0
at System.Console..cctor () [0x0008e] in :0
--- End of inner exception stack trace ---
at Mono.CSharp.Driver.Main (System.String[] args) [0x00019] in <2b1e99ce45b54209bdcdab138d9758ae>:0

Xamarin.Android app crashes after user update on play store

Similar to this question
A workaround I found was to uninstall and re-install the app.
However, it may be difficult to convince users on the play store to do that, as they may not read the update change-log before downloading. (e.g. auto-update).
I narrowed down the cause to:
09-28 21:41:26.011: I/MonoDroid(6923): UNHANDLED EXCEPTION:
09-28 21:41:26.047: I/MonoDroid(6923): Java.Lang.RuntimeException: Binary XML file line #1: Error inflating class android.widget.ImageButton ---> Java.Lang.Exception: Exception of type 'Java.Lang.Exception' was thrown. ---> Java.Lang.RuntimeException: Resource is not a Drawable (color or path): TypedValue{t=0x2/d=0x7f010127 a=-1}
09-28 21:41:26.047: I/MonoDroid(6923): --- End of inner exception stack trace ---
09-28 21:41:26.047: I/MonoDroid(6923): --- End of inner exception stack trace ---
09-28 21:41:26.047: I/MonoDroid(6923): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <9ab6e5aa0dab475cab5597fa4269890c>:0
09-28 21:41:26.047: I/MonoDroid(6923): at Java.Interop.JniEnvironment+InstanceMethods.CallNonvirtualVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x00089] in <5e50b69e5a0e439f924bf0f2e8fcd52c>:0
09-28 21:41:26.047: I/MonoDroid(6923): at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0005d] in <5e50b69e5a0e439f924bf0f2e8fcd52c>:0
09-28 21:41:26.047: I/MonoDroid(6923): at Android.App.Activity.SetContentView (System.Int32 layoutResID) [0x00022] in <f051fcdec18c4806998a5576ba788eec>:0
09-28 21:41:26.047: I/MonoDroid(6923): at mypackagename.MainActivity+<OnCreate>d__33.MoveNext () [0x0004d] in <467e37befb3d49c788d8cebf5dfb11a2>:0
09-28 21:41:26.047: I/MonoDroid(6923): --- End of stack trace from previous location where exception was thrown ---
09-28 21:41:26.047: I/MonoDroid(6923): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <9ab6e5aa0dab475cab5597fa4269890c>:0
09-28 21:41:26.047: I/MonoDroid(6923): at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0 (System.Object state) [0x00000] in <9ab6e5aa0dab475cab5597fa4269890c>:0
09-28 21:41:26.047: I/MonoDroid(6923): at Android.App.SyncContext+<>c__DisplayClass2_0.<Post>b__0 () [0x00000] in <f051fcdec18c4806998a5576ba788eec>:0
09-28 21:41:26.047: I/MonoDroid(6923): at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <f051fcdec18c4806998a5576ba788eec>:0
09-28 21:41:26.047: I/MonoDroid(6923): at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00008] in <f051fcdec18c4806998a5576ba788eec>:0
09-28 21:41:26.047: I/MonoDroid(6923): at (wrapper dynamic-method) System.Object:471f272e-f7ed-4fdc-805d-59ce5a399fd4 (intptr,intptr)
09-28 21:41:26.047: I/MonoDroid(6923): --- End of managed Java.Lang.RuntimeException stack trace ---
09-28 21:41:26.047: I/MonoDroid(6923): android.view.InflateException: Binary XML file line #1: Error inflating class android.widget.ImageButton
Old apk was built using Xamarin.VisualStudio_4.5.0.486 on VS Community 2015.3
New apk was build using Xamarin.VisualStudio_4.6.3.4 on VS Community 2017
both apk targets Nougat 7.0, and minimum ICS 4.0.3
There was no change whatsoever to my axml layout files. That is also evident because after re-installation, the ImageButton inflates without any problem.
How can this issue be resolved?

The type initializer for 'Microsoft.WindowsAzure.Storage.CloudStorageAccount' threw an exception error in Xamarin.forms

I'm working on AzureStorage cloud solution provided by Xamarin.
https://developer.xamarin.com/guides/xamarin-forms/cloud-services/storage/azure-storage/
And this is what I got in GetContainer() method.
The type initializer for
'Microsoft.WindowsAzure.Storage.CloudStorageAccount' threw an
exception
I applied my connection string in the sample project and it worked, but not in my own project.
Has anyone ever faced this issue? Please help me.
Thanks in advance.
Error message :
System.TypeInitializationException: The type initializer for 'Microsoft.WindowsAzure.Storage.CloudStorageAccount' threw an exception. ---> System.NotImplementedException: The method or operation is not implemented.
at Microsoft.WindowsAzure.Storage.CloudStorageAccount.Setting (System.String name, System.String[] validValues) [0x00000] in <667a5fa37f124e50ab7a68ecb3437b13>:0
at Microsoft.WindowsAzure.Storage.CloudStorageAccount..cctor () [0x00000] in <667a5fa37f124e50ab7a68ecb3437b13>:0
--- End of inner exception stack trace ---
at MyTenantWorld.AzureStorage.GetContainer (MyTenantWorld.ContainerType containerType) [0x00020] in <9816076ee17d42efaf1050c5169a4310>:0
at MyTenantWorld.AzureStorage+<UploadFileAsync>d__3.MoveNext () [0x0001a] in <9816076ee17d42efaf1050c5169a4310>:0
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <3fd174ff54b146228c505f23cf75ce71>:0
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <3fd174ff54b146228c505f23cf75ce71>:0
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <3fd174ff54b146228c505f23cf75ce71>:0
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <3fd174ff54b146228c505f23cf75ce71>:0
at System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () [0x00000] in <3fd174ff54b146228c505f23cf75ce71>:0
at MyTenantWorld.SettingsPage+<SaveData>d__20.MoveNext () [0x00309] in <9816076ee17d42efaf1050c5169a4310>:0
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <3fd174ff54b146228c505f23cf75ce71>:0
at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0 (System.Object state) [0x00000] in <3fd174ff54b146228c505f23cf75ce71>:0
at Android.App.SyncContext+<>c__DisplayClass2_0.<Post>b__0 () [0x00000] in <d855bac285f44dda8a0d8510b679b1e2>:0
at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <d855bac285f44dda8a0d8510b679b1e2>:0
at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00008] in <d855bac285f44dda8a0d8510b679b1e2>:0
at at (wrapper dynamic-method) System.Object:a4fed05a-cd7a-4756-85bb-5dd975374042 (intptr,intptr)
As the GetContainer method defined under AzureStorage.cs as follows:
static CloudBlobContainer GetContainer(ContainerType containerType)
{
var account = CloudStorageAccount.Parse(Constants.StorageConnection);
var client = account.CreateCloudBlobClient();
return client.GetContainerReference(containerType.ToString().ToLower());
}
It seems that the error was thrown by CloudStorageAccount.Parse, but from BergQuester's link about CloudStorageAccount.Parse, we could find that this error is not from the predictable exceptions.
From your stack trace, we could find the error was thrown at Setting(string name, params string[] validValues) from CloudStorageAccount.cs. I used WindowsAzure.Storage 8.3.0 and tested it under my BruceChen_Mobile.UWP project and PCL project, it could work as expected with my azure storage connection string.
I applied my connection string in the sample project and it worked, but not in my own project.
I would recommend you checking the packages between your application and the xamarin-forms-samples. Or you could provide a reproducible sample project for us to narrow this issue.
I fixed this issue on mine by adding a reference to the WindowsAzure.Storage nuget package from my native projects (not just in the PCL project), as it requires some native implementations that are defined in these references.

Categories

Resources