This is Xamarin's bug tracking system. For product support, please use the support links listed in your Xamarin Account.
Bug 37313 - SIGABRT on System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor
Summary: SIGABRT on System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: JIT (show other bugs)
Version: 4.2.0 (C6)
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Aleksey Kliger
URL:
Depends on:
Blocks:
 
Reported: 2015-12-29 08:30 UTC by dkempf
Modified: 2016-01-02 04:28 UTC (History)
5 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments

Description dkempf 2015-12-29 08:30:16 UTC
compute_class_bitmap: Invalid type 13 for field RCC.Child`1[T]:Field

Stacktrace:

  at <unknown> <0xffffffff>
  at (wrapper managed-to-native) System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor (intptr) <0xffffffff
>
  at System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor (System.RuntimeTypeHandle) <0x00031>
  at RCC.Program.Main (string[]) <0x00073>
  at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <0xffffffff>

Native stacktrace:

        mono() [0x49cf0c]
        /lib/x86_64-linux-gnu/libpthread.so.0(+0xf0a0) [0x7f9fda2f90a0]
        /lib/x86_64-linux-gnu/libc.so.6(gsignal+0x35) [0x7f9fd9f91165]
        /lib/x86_64-linux-gnu/libc.so.6(abort+0x180) [0x7f9fd9f943e0]
        mono() [0x62a329]
        mono() [0x62a537]
        mono() [0x62a5e2]
        mono() [0x5a5b1d]
        mono() [0x5a635f]
        mono() [0x537a05]
        [0x4115f152]

Debug info from gdb:


=================================================================
Got a SIGABRT 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

---

From the following code running on Docker mono:latest (4.2.1 (Stable 4.2.1.102/6dd2d0d Thu Nov 12 09:52:44 UTC 2015)), and which works fine on Windows:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RCC
{
	class Program
	{
		static void Main(string[] args) {			
			try {
				System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(typeof(Parent).TypeHandle);
				System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(typeof(Child<>).TypeHandle);
				Console.WriteLine("Ran class constructors");
			}
			catch (Exception ex) {
				Console.WriteLine(ex.GetType().Name + ": " + ex.Message);
				Console.WriteLine("StackTrace:\r\n" + ex.StackTrace);
			}
			Console.ReadKey();
		}
	}

	class Parent
	{
	}

	class Child<T> : Parent
	{
		protected T Field;
	}
}
Comment 1 dkempf 2015-12-29 08:35:53 UTC
Parent class not required. Delete or comment out.
Comment 2 Alex Rønne Petersen 2015-12-30 05:37:16 UTC
We definitely shouldn't crash on this (rather ignore the request) but just for the record, `RunClassConstructor (typeof (SomeGenericClass<>))` will not actually do anything, even on MS.NET. Since it's not a fully instantiated type, it wouldn't make sense if it actually invoked the class constructor. You can verify this behavior by creating a class constructor in `Parent` and `Child` and putting a `Console.WriteLine ()` in each. Only the `Parent` one will run.
Comment 3 dkempf 2015-12-30 06:57:03 UTC
Thanks Alex. I've modified my usage of the method to check:

if (!t.IsGenericTypeDefinition)						System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(t.TypeHandle);

I began using this method to ensure that static constructors get called. Apparently they don't necessarily get called on type load under MS.Net, but rather on first instantiation.
Comment 4 dkempf 2015-12-30 07:16:11 UTC
BTW, I'm thinking about porting this MS.Net app I have to run under Mono. There seem to be a massive number of hurdles to overcome. Your prompt reply makes me think it could be possible and perhaps worth the effort.

Out of 4 web interfaces it has, only one runs out of the box on Mono! Well, at least one does (WCF w/DataContractSerializer).

Now I'm blocked with a thoroughly confusing Console.WriteLine statement that won't write to the console. I'm not developing on Linux, just running existing app from shared folder, and debugging with that age old technique.
Comment 5 Zoltan Varga 2016-01-02 04:28:46 UTC
Fixed in mono master 92efab91abc0c298450eb244fe688ce6be19a021.

Note You need to log in before you can comment on or make changes to this bug.