Bug 60350 - System.TypeInitializationException when using large automatically generated resrouce files
Summary: System.TypeInitializationException when using large automatically generated r...
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: General ()
Version: 5.4 (2017-06)
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: 15.7
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-10-24 15:40 UTC by Ammar Mheir
Modified: 2018-04-23 18:55 UTC (History)
11 users (show)

Tags: bugpool-archive
Is this bug a regression?: ---
Last known good build:


Attachments
Sample Project (3.60 MB, application/x-zip-compressed)
2017-10-24 15:40 UTC, Ammar Mheir
Details
Sample w\ Console app included. (3.63 MB, application/zip)
2017-11-09 15:04 UTC, Chris Hamons
Details
Reduced Sample App (7.34 MB, application/zip)
2017-11-10 18:59 UTC, Alexander Köplinger [MSFT]
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Ammar Mheir 2017-10-24 15:40:26 UTC
Created attachment 25419 [details]
Sample Project

##Overview

When compiling and running a Xamarin.Mac project that has large automatically generate resource files (around 6mb each), VS for Mac will compile successfully however will crash upon deploying the app with an error: System.TypeInitializationException

The same project used to compile and run successfully when using Xamarin Studio version 6.1.5. 


##Steps to replicate

1). Download attached sample project
2). compile and run on Mac
3). error should appear as soon as the app attempts to run 


##Observed results 

The application would immediately crash upon deploying with the following error: 

>Unhandled Exception:
>System.TypeInitializationException: The type initializer for 'SampleLibrary.NSampleClass' threw an exception. ---> System.TypeInitializationException: The type initializer for 'Nevron.Nov.DataStructures.NHashHelpers' threw an exception. ---> System.TypeLoadException: Failure has occurred while loading a type.
>   --- End of inner exception stack trace ---
>  at SampleLibrary.NSampleClass..cctor () [0x00000] in /Users/amamac/Downloads/SampleApp/SampleLibrary/NSampleClass.cs:7 
>   --- End of inner exception stack trace ---
>  at (wrapper managed-to-native) System.Object:__icall_wrapper_mono_generic_class_init (intptr)
>  at SampleApp.MainClass.Main (System.String[] args) [0x00007] in /Users/amamac/Downloads/SampleApp/Main.cs:13 
>[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: The type initializer for 'SampleLibrary.NSampleClass' threw an exception. ---> System.TypeInitializationException: The type initializer for 'Nevron.Nov.DataStructures.NHashHelpers' threw an exception. ---> System.TypeLoadException: Failure has occurred while loading a type.
>   --- End of inner exception stack trace ---
>  at SampleLibrary.NSampleClass..cctor () [0x00000] in /Users/amamac/Downloads/SampleApp/SampleLibrary/NSampleClass.cs:7 
>   --- End of inner exception stack trace ---
>  at (wrapper managed-to-native) System.Object:__icall_wrapper_mono_generic_class_init (intptr)
>  at SampleApp.MainClass.Main (System.String[] args) [0x00007] in /Users/amamac/Downloads/SampleApp/Main.cs:13 


##Expected Results

The project will compile and deploy successfully as it has when using Xamarin Studio 6.1.5.
 

##Additional Information

The current workaround that seems to work is to refactor the code to generate many more resource files however with much smaller size for each. Although this seems to work on Xamarin Studio without having to generate smaller resource files.


##Version Information 

=== Visual Studio Enterprise 2017 for Mac ===

Version 7.2 (build 636)
Installation UUID: 1621b137-c1b7-473d-9609-23de9d4cac12
Runtime:
	Mono 5.4.0.201 (2017-06/71277e78f6e) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 504000201

=== .NET Core ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Version: 2.0.0
SDK: /usr/local/share/dotnet/sdk/2.0.0/Sdks
SDK Version: 2.0.0
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.4.0/lib/mono/msbuild/15.0/bin/Sdks

=== Apple Developer Tools ===

Xcode 9.0 (13247)
Build 9A235

=== Xamarin.iOS ===

Version: 11.2.0.11 (Visual Studio Enterprise)
Hash: 2f8bbec0
Branch: d15-4-xi
Build date: 2017-10-05 20:56:05-0400

=== Xamarin.Mac ===

Version: 3.8.0.49 (Visual Studio Enterprise)

=== Build Information ===

Release ID: 702000636
Git revision: b349c8fc0c2e1aab0179917d56eed75eb3a03337
Build date: 2017-10-06 15:20:04-04
Xamarin addins: a8da992c78f7eb65b3cdb3f951c34a30337cab35
Build lane: monodevelop-lion-d15-4

=== Operating System ===

Mac OS X 10.12.6
Darwin 16.7.0 Darwin Kernel Version 16.7.0
    Thu Jun 15 17:36:27 PDT 2017
    root:xnu-3789.70.16~2/RELEASE_X86_64 x86_64
Comment 2 David Karlaš 2017-11-09 05:37:14 UTC
I can reproduce this hence confirming, but I think this is Xamarin.Mac bug since exception is thrown at runtime execution...
Comment 3 Chris Hamons 2017-11-09 15:03:35 UTC
This appears to be either a mono runtime bug or a bug in the resource tool, as you can create a simple .NET Console application, do this:

		public static void Main (string [] args)
		{
			var c = new NSampleClass ();

			Console.WriteLine (c);
		}


and see the same exact crash.
Comment 4 Chris Hamons 2017-11-09 15:04:11 UTC
Created attachment 25621 [details]
Sample w\ Console app included.
Comment 5 Alexander Köplinger [MSFT] 2017-11-10 18:58:19 UTC
I was able to strip a lot out from the sample app and make a minimal repro project with just a .NET Console + normal .NET library.

If you run remove one item from the array in FailTrigger.cs it works, otherwise it crashes with:

> Unhandled Exception:
> System.TypeInitializationException: The type initializer for 'BigResources.FailTrigger' threw an exception. ---> System.TypeLoadException: Failure has occurred while loading a type.
>    --- End of inner exception stack trace ---
> [ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: The type initializer for 'BigResources.FailTrigger' threw an exception. ---> System.TypeLoadException: Failure has occurred while loading a type.
>    --- End of inner exception stack trace ---
Comment 6 Alexander Köplinger [MSFT] 2017-11-10 18:59:37 UTC
Created attachment 25645 [details]
Reduced Sample App
Comment 7 Ludovic Henry 2017-11-10 19:10:10 UTC
I can reproduce with Mono 5.8.0.40 (2017-10/ce494e3d152)
Comment 8 Rodrigo Kumpera 2017-11-14 23:21:50 UTC
I can reproduce with 5.4 but I can't with master from today.
Comment 9 Alexander Köplinger [MSFT] 2017-11-14 23:24:24 UTC
@kumpera ist there a specific fix we should backport to 2017-10?