sq / JSIL

CIL to Javascript Compiler
http://jsil.org/
Other
1.73k stars 241 forks source link

MonoGame "hello world" build failing (System.OverflowException: Value was either too large or too small for an Int64) #992

Open endel opened 8 years ago

endel commented 8 years ago

Hi there,

I'm trying to compile a simple "hello world" without success.

I'm under OSX (10.11.4), using Xamarin Studio to compile. Am I missing something? Should it work on my environment?

Hello world source code

Stack trace + error message:

$ mono JSILc.AnyCPU.exe "bin/Release/MonoGameTesting.exe"
// Applied settings from 'bin/defaults.jsilconfig'.
// Using .NET framework 4.0.30319.17020 in workstation GC mode. Tuned GC enabled.
// Loaded proxies from 'JSIL.Proxies.4.0'
// Loaded ../MonoGameTesting/MonoGameTesting/bin/Release/MonoGameTesting.exe (translate)
// Loaded bin/MonoGame.Framework.dll (translate)
// Loaded /usr/local/Cellar/mono/4.2.0.179/lib/mono/4.5/mscorlib.dll (stubbed)
// Loaded /usr/local/Cellar/mono/4.2.0.179/lib/mono/gac/System/4.0.0.0__b77a5c561934e089/System.dll (stubbed)
// Loaded bin/MonoMac.dll (translate)
// Loaded /usr/local/Cellar/mono/4.2.0.179/lib/mono/gac/System.Drawing/4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll (stubbed)
// Loaded /usr/local/Cellar/mono/4.2.0.179/lib/mono/gac/System.Runtime.Serialization/4.0.0.0__b77a5c561934e089/System.Runtime.Serialization.dll (stubbed)
// Loaded /usr/local/Cellar/mono/4.2.0.179/lib/mono/gac/System.Core/4.0.0.0__b77a5c561934e089/System.Core.dll (stubbed)
// Loaded bin/OpenTK.dll (translate)
// Loaded /usr/local/Cellar/mono/4.2.0.179/lib/mono/gac/Mono.Security/4.0.0.0__0738eb9f132ed756/Mono.Security.dll (translate)
// Loaded /usr/local/Cellar/mono/4.2.0.179/lib/mono/gac/System.Configuration/4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll (stubbed)
// Loaded /usr/local/Cellar/mono/4.2.0.179/lib/mono/gac/System.Xml/4.0.0.0__b77a5c561934e089/System.Xml.dll (stubbed)
// Loaded /usr/local/Cellar/mono/4.2.0.179/lib/mono/4.5/System.ServiceModel.Internals.dll (stubbed)
// Loaded /usr/local/Cellar/mono/4.2.0.179/lib/mono/gac/Mono.Posix/4.0.0.0__0738eb9f132ed756/Mono.Posix.dll (translate)
// Loaded /usr/local/Cellar/mono/4.2.0.179/lib/mono/4.5/System.Drawing.dll (stubbed)
// Loaded /usr/local/Cellar/mono/4.2.0.179/lib/mono/2.0/mscorlib.dll (stubbed)
// Loaded /usr/local/Cellar/mono/4.2.0.179/lib/mono/4.5/System.dll (stubbed)
// Loaded /usr/local/Cellar/mono/4.2.0.179/lib/mono/4.5/System.Xml.dll (stubbed)
// Decompiling  System.AggregateException: One or more errors occurred. ---> System.OverflowException: Value was either too large or too small for an Int64.
   at System.Convert.ToInt64 (UInt64 value) in <filename unknown>:line 0
   at System.UInt64.System.IConvertible.ToInt64 (IFormatProvider provider) in <filename unknown>:line 0
   at System.Convert.ToInt64 (System.Object value) in <filename unknown>:line 0
   at JSIL.Internal.TypeInfo..ctor (ITypeInfoSource source, JSIL.Internal.ModuleInfo module, Mono.Cecil.TypeDefinition type, JSIL.Internal.TypeInfo declaringType, JSIL.Internal.TypeInfo baseClass, TypeIdentifier identifier) in <filename unknown>:line 0
   at JSIL.TypeInfoProvider.ConstructTypeInformation (TypeIdentifier identifier, Mono.Cecil.TypeDefinition type, System.Collections.Generic.Dictionary`2 moreTypes) in <filename unknown>:line 0
   at JSIL.TypeInfoProvider._MakeTypeInfo (TypeIdentifier identifier, JSIL.MakeTypeInfoArgs args) in <filename unknown>:line 0
   at JSIL.Internal.ConcurrentCache`2[TKey,TValue].TryCreate[TUserData] (JSIL.Internal.TKey key, JSIL.Internal.TUserData userData, JSIL.Internal.CreatorFunction`1 creator, System.Predicate`1 shouldAdd) in <filename unknown>:line 0
   at JSIL.TypeInfoProvider.GetTypeInformation (Mono.Cecil.TypeReference type) in <filename unknown>:line 0
   at JSIL.AssemblyTranslator.ShouldTranslateMethods (Mono.Cecil.TypeDefinition typedef) in <filename unknown>:line 0
   at JSIL.AssemblyTranslator+<GetMethodsToAnalyze>c__AnonStorey6.<>m__0 (Int32 i, System.Threading.Tasks.ParallelLoopState loopState, System.Collections.Generic.List`1 typeList) in <filename unknown>:line 0
   at System.Threading.Tasks.Parallel+<ForWorker>c__AnonStorey3`1[TLocal].<>m__1 () in <filename unknown>:line 0
  --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional (Boolean includeTaskCanceledExceptions) in <filename unknown>:line 0
   at System.Threading.Tasks.Task.Wait (Int32 millisecondsTimeout, CancellationToken cancellationToken) in <filename unknown>:line 0
   at System.Threading.Tasks.Task.Wait () in <filename unknown>:line 0
   at System.Threading.Tasks.Parallel.ForWorker[TLocal] (Int32 fromInclusive, Int32 toExclusive, System.Threading.Tasks.ParallelOptions parallelOptions, System.Action`1 body, System.Action`2 bodyWithState, System.Func`4 bodyWithLocal, System.Func`1 localInit, System.Action`1 localFinally) in <filename unknown>:line 0
---> (Inner Exception #0) System.OverflowException: Value was either too large or too small for an Int64.
   at System.Convert.ToInt64 (UInt64 value) in <filename unknown>:line 0
   at System.UInt64.System.IConvertible.ToInt64 (IFormatProvider provider) in <filename unknown>:line 0
   at System.Convert.ToInt64 (System.Object value) in <filename unknown>:line 0
   at JSIL.Internal.TypeInfo..ctor (ITypeInfoSource source, JSIL.Internal.ModuleInfo module, Mono.Cecil.TypeDefinition type, JSIL.Internal.TypeInfo declaringType, JSIL.Internal.TypeInfo baseClass, TypeIdentifier identifier) in <filename unknown>:line 0
   at JSIL.TypeInfoProvider.ConstructTypeInformation (TypeIdentifier identifier, Mono.Cecil.TypeDefinition type, System.Collections.Generic.Dictionary`2 moreTypes) in <filename unknown>:line 0
   at JSIL.TypeInfoProvider._MakeTypeInfo (TypeIdentifier identifier, JSIL.MakeTypeInfoArgs args) in <filename unknown>:line 0
   at JSIL.Internal.ConcurrentCache`2[TKey,TValue].TryCreate[TUserData] (JSIL.Internal.TKey key, JSIL.Internal.TUserData userData, JSIL.Internal.CreatorFunction`1 creator, System.Predicate`1 shouldAdd) in <filename unknown>:line 0
   at JSIL.TypeInfoProvider.GetTypeInformation (Mono.Cecil.TypeReference type) in <filename unknown>:line 0
   at JSIL.AssemblyTranslator.ShouldTranslateMethods (Mono.Cecil.TypeDefinition typedef) in <filename unknown>:line 0
   at JSIL.AssemblyTranslator+<GetMethodsToAnalyze>c__AnonStorey6.<>m__0 (Int32 i, System.Threading.Tasks.ParallelLoopState loopState, System.Collections.Generic.List`1 typeList) in <filename unknown>:line 0
   at System.Threading.Tasks.Parallel+<ForWorker>c__AnonStorey3`1[TLocal].<>m__1 () in <filename unknown>:line 0<---
kg commented 8 years ago

The stack trace isn't providing much information, but it looks like one of the assemblies you're translating contains a UInt64 enum with a very large enumerant, maybe? I haven't ever tested with monomac.

iskiselev commented 8 years ago

@endel, please try to change JSIL/TypeInformation.cs around line 698. Please replace:

                    if (field.HasConstant)
                        enumValue = Convert.ToInt64(field.Constant);

with

                    if (field.HasConstant) {
                        if (field.Constant is ulong) {
                            enumValue = (long) (ulong) field.Constant;
                        } else {
                            enumValue = Convert.ToInt64(field.Constant);
                        }
                    }

Could you report if it'll help?

endel commented 8 years ago

Thanks for your quick reply @iskiselev and @kg.

@iskiselev it did compiled with this change! I just couldn't make it actually run in the browser. Maybe I'm missing something. I'll have a deep look during the weekend. Cheers!