Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't build Mono projects in 3.4 beta 1: "The type initializer for 'Sys' threw an exception" #50486

Closed
Miziziziz opened this issue Jul 15, 2021 · 14 comments

Comments

@Miziziziz
Copy link

Godot version

v3.4.beta1.mono.official

System information

Windows 10

Issue description

I'm using MSBuild, installed from Visual Studio Build Tools 2017 15.9.36
In editor, this error is thrown whenever I try to run a scene:

modules/mono/mono_gd/gd_mono_utils.cpp:369 - System.TypeInitializationException: The type initializer for 'Sys' threw an exception.
editor/editor_node.cpp:5369 - An EditorPlugin build callback failed.

command line shows this:

Unhandled Exception:
System.TypeInitializationException: The type initializer for 'Sys' threw an exception. ---> System.DllNotFoundException: System.Native assembly: type: member:(null)
at (wrapper managed-to-native) Interop+Sys.LChflagsCanSetHiddenFlag()
at Interop+Sys..cctor () [0x00000] in <2606d1e3191f45969af1cc6149da86d0>:0
--- End of inner exception stack trace ---
at System.IO.FileSystem.FileExists (System.ReadOnlySpan1[T] fullPath, System.Int32 fileType, Interop+ErrorInfo& errorInfo) [0x00007] in <2606d1e3191f45969af1cc6149da86d0>:0 at System.IO.FileSystem.FileExists (System.ReadOnlySpan1[T] fullPath) [0x00006] in <2606d1e3191f45969af1cc6149da86d0>:0
at System.IO.File.Exists (System.String path) [0x00043] in <2606d1e3191f45969af1cc6149da86d0>:0
at GodotTools.Utils.File.Exists (System.String path) [0x00006] in <0e2b1c349f7744a5a9e5c0be7d677bc5>:0
at GodotTools.Build.BuildManager.EditorBuildCallback () [0x00005] in <0e2b1c349f7744a5a9e5c0be7d677bc5>:0
at GodotTools.GodotSharpEditor.Build () [0x00000] in <0e2b1c349f7744a5a9e5c0be7d677bc5>:0
ERROR: System.TypeInitializationException: The type initializer for 'Sys' threw an exception.
at: debug_send_unhandled_exception_error (modules/mono/mono_gd/gd_mono_utils.cpp:369)
ERROR: An EditorPlugin build callback failed.
at: call_build (editor/editor_node.cpp:5369)

Steps to reproduce

run any scene

Minimal reproduction project

No response

@akien-mga
Copy link
Member

Which build tool do you have configured in Editor Settings > Mono > Builds > Build Tool?

@akien-mga akien-mga changed the title can't run any projects in 3.4 beta "The type initializer for 'Sys' threw an exception" can't run any projects in 3.4 beta 1 "The type initializer for 'Sys' threw an exception" Jul 15, 2021
@akien-mga akien-mga changed the title can't run any projects in 3.4 beta 1 "The type initializer for 'Sys' threw an exception" Can't build Mono projects in 3.4 beta 1: "The type initializer for 'Sys' threw an exception" Jul 15, 2021
@Miziziziz
Copy link
Author

it just says '1' lol
looks like it's an integer field now instead of the old dropdown
image

@akien-mga
Copy link
Member

That's weird, here on Linux I get the drop-down as expected:
Screenshot_20210715_172146

Might be worth trying to backup and then delete/rename your editor settings to see if you get the same bug with a vanilla config (in %appdata%/Godot/editor_settings-3.tres).

@bruvzg
Copy link
Member

bruvzg commented Jul 15, 2021

it just says '1' lol

This happens if editor fail to load one main Mono libraries (libmono-native and libMonoPosixHelper).

@Miziziziz
Copy link
Author

it just says '1' lol

This happens if editor fail to load one main Mono libraries (libmono-native and libMonoPosixHelper).

oh how do I fix that?

@akien-mga
Copy link
Member

Indeed GodotSharp/Mono/lib/ seems to be missing important libs, which are present in the Linux and macOS builds. Seems like my Windows build container is missing some stuff.

I might need to go back to using Wine for the build if it's the reason why it failed to build those libs (and didn't tell me :|). godotengine/build-containers@428340a

@akien-mga
Copy link
Member

akien-mga commented Jul 15, 2021

@neikeq I do have the relevant libs in my build container, but with .a and .dll.a extension. I guess the build scripts don't handle that properly?

[root@9e7bdcb00a55 ~]# ls mono-installs/desktop-windows-x86_64-release/lib/
libMonoPosixHelper.a  libMonoPosixHelper.dll.a  libMonoPosixHelper.la  libmono-2.0.a  libmono-2.0.dll.a  libmono-2.0.la  libmonosgen-2.0.a  libmonosgen-2.0.dll.a  libmonosgen-2.0.la  mono  pkgconfig

@bruvzg
Copy link
Member

bruvzg commented Jul 15, 2021

Log (using wine):

DllImport attempting to load: 'System.Native'. (in domain Mono, info)
DllImport error loading library 'Z:/Users/bruv/Downloads/Godot_v3.4-beta1_mono_win64/GodotSharp/Mono/lib/mono/4.5\System.Native': 'File not found.
'. (in domain Mono, info)
DllImport error loading library 'Z:/Users/bruv/Downloads/Godot_v3.4-beta1_mono_win64/GodotSharp/Mono/lib/mono/4.5\System.Native.dll': 'File not found.
'. (in domain Mono, info)
DllImport error loading library 'Z:/Users/bruv/Downloads/Godot_v3.4-beta1_mono_win64/GodotSharp/Mono/lib/mono/4.5\System.Native.dll': 'File not found.
'. (in domain Mono, info)

This file is missing, but it was not present in 3.3.2 either. MonoPosixHelper.dll is in the GodotSharp/Mono/bin folder.

@akien-mga
Copy link
Member

Hm indeed the libs are compiled statically so they're not present in 3.3.2 either. Here's the full diff between the files in 3.3.2-stable and 3.4-beta1's GodotSharp:

--- list_3.3.2-stable-s 2021-07-15 17:44:58.715765109 +0200
+++ list_3.4-beta1-s    2021-07-15 17:45:06.487727939 +0200
@@ -42,8 +42,6 @@
 ./Mono/etc/mono/4.5/web.config
 ./Mono/etc/mono/browscap.ini
 ./Mono/etc/mono/config
-./Mono/etc/mono/mconfig
-./Mono/etc/mono/mconfig/config.xml
 ./Mono/lib
 ./Mono/lib/mono
 ./Mono/lib/mono/4.5
@@ -199,25 +197,27 @@
 ./Mono/lib/mono/4.5/Microsoft.Build.Framework.dll
 ./Mono/lib/mono/4.5/Microsoft.Build.Tasks.v4.0.dll
 ./Mono/lib/mono/4.5/Microsoft.Build.Utilities.v4.0.dll
-./Mono/lib/mono/4.5/Microsoft.CodeAnalysis.CSharp.dll
-./Mono/lib/mono/4.5/Microsoft.CodeAnalysis.CSharp.Scripting.dll
-./Mono/lib/mono/4.5/Microsoft.CodeAnalysis.dll
-./Mono/lib/mono/4.5/Microsoft.CodeAnalysis.Scripting.dll
-./Mono/lib/mono/4.5/Microsoft.CodeAnalysis.VisualBasic.dll
 ./Mono/lib/mono/4.5/Microsoft.CSharp.dll
 ./Mono/lib/mono/4.5/Microsoft.VisualC.dll
 ./Mono/lib/mono/4.5/Microsoft.Web.Infrastructure.dll
+./Mono/lib/mono/4.5/Mono.Btls.Interface.dll
+./Mono/lib/mono/4.5/Mono.C5.dll
 ./Mono/lib/mono/4.5/Mono.Cairo.dll
+./Mono/lib/mono/4.5/Mono.Cecil.dll
+./Mono/lib/mono/4.5/Mono.Cecil.Mdb.dll
 ./Mono/lib/mono/4.5/Mono.CodeContracts.dll
 ./Mono/lib/mono/4.5/Mono.CompilerServices.SymbolWriter.dll
+./Mono/lib/mono/4.5/Mono.Configuration.Crypto.dll
 ./Mono/lib/mono/4.5/Mono.CSharp.dll
 ./Mono/lib/mono/4.5/Mono.Data.Sqlite.dll
 ./Mono/lib/mono/4.5/Mono.Data.Tds.dll
 ./Mono/lib/mono/4.5/Mono.Debugger.Soft.dll
+./Mono/lib/mono/4.5/monodoc.dll
 ./Mono/lib/mono/4.5/Mono.Http.dll
 ./Mono/lib/mono/4.5/Mono.Management.dll
 ./Mono/lib/mono/4.5/Mono.Messaging.dll
 ./Mono/lib/mono/4.5/Mono.Messaging.RabbitMQ.dll
+./Mono/lib/mono/4.5/Mono.Options.dll
 ./Mono/lib/mono/4.5/Mono.Parallel.dll
 ./Mono/lib/mono/4.5/Mono.Posix.dll
 ./Mono/lib/mono/4.5/Mono.Profiler.Log.dll
@@ -232,7 +232,6 @@
 ./Mono/lib/mono/4.5/PEAPI.dll
 ./Mono/lib/mono/4.5/RabbitMQ.Client.dll
 ./Mono/lib/mono/4.5/SMDiagnostics.dll
-./Mono/lib/mono/4.5/System.Collections.Immutable.dll
 ./Mono/lib/mono/4.5/System.ComponentModel.Composition.dll
 ./Mono/lib/mono/4.5/System.ComponentModel.DataAnnotations.dll
 ./Mono/lib/mono/4.5/System.Configuration.dll
@@ -261,7 +260,6 @@
 ./Mono/lib/mono/4.5/System.Json.dll
 ./Mono/lib/mono/4.5/System.Json.Microsoft.dll
 ./Mono/lib/mono/4.5/System.Management.dll
-./Mono/lib/mono/4.5/System.Memory.dll
 ./Mono/lib/mono/4.5/System.Messaging.dll
 ./Mono/lib/mono/4.5/System.Net.dll
 ./Mono/lib/mono/4.5/System.Net.Http.dll
@@ -281,7 +279,6 @@
 ./Mono/lib/mono/4.5/System.Reactive.Windows.Forms.dll
 ./Mono/lib/mono/4.5/System.Reactive.Windows.Threading.dll
 ./Mono/lib/mono/4.5/System.Reflection.Context.dll
-./Mono/lib/mono/4.5/System.Reflection.Metadata.dll
 ./Mono/lib/mono/4.5/System.Runtime.Caching.dll
 ./Mono/lib/mono/4.5/System.Runtime.CompilerServices.Unsafe.dll
 ./Mono/lib/mono/4.5/System.Runtime.DurableInstancing.dll
@@ -297,7 +294,6 @@
 ./Mono/lib/mono/4.5/System.ServiceModel.Web.dll
 ./Mono/lib/mono/4.5/System.ServiceProcess.dll
 ./Mono/lib/mono/4.5/System.Threading.Tasks.Dataflow.dll
-./Mono/lib/mono/4.5/System.Threading.Tasks.Extensions.dll
 ./Mono/lib/mono/4.5/System.Transactions.dll
 ./Mono/lib/mono/4.5/System.Web.Abstractions.dll
 ./Mono/lib/mono/4.5/System.Web.ApplicationServices.dll
@@ -314,6 +310,7 @@
 ./Mono/lib/mono/4.5/System.Web.RegularExpressions.dll
 ./Mono/lib/mono/4.5/System.Web.Routing.dll
 ./Mono/lib/mono/4.5/System.Web.Services.dll
+./Mono/lib/mono/4.5/SystemWebTestShim.dll
 ./Mono/lib/mono/4.5/System.Web.WebPages.Deployment.dll
 ./Mono/lib/mono/4.5/System.Web.WebPages.dll
 ./Mono/lib/mono/4.5/System.Web.WebPages.Razor.dll
@@ -351,6 +348,10 @@
 ./Tools/Microsoft.Build.dll
 ./Tools/Microsoft.Build.Framework.dll
 ./Tools/Microsoft.VisualStudio.Setup.Configuration.Interop.dll
+./Tools/Mono.Cecil.dll
+./Tools/Mono.Cecil.Mdb.dll
+./Tools/Mono.Cecil.Pdb.dll
+./Tools/Mono.Cecil.Rocks.dll
 ./Tools/MSBuild.exe
 ./Tools/Newtonsoft.Json.dll
 ./Tools/Semver.dll

@bruvzg
Copy link
Member

bruvzg commented Jul 15, 2021

Exported 3.4-beta1 Mono project (exported from macOS native editor) seems to be working fine, there are no extra dll's in it.

.
├── MonoTest.exe
├── MonoTest.pck
└── data_MonoTest
    └── Mono
        ├── bin
        │   └── MonoPosixHelper.dll
        └── etc
            └── mono
                ├── 2.0
                │   ├── Browsers
                │   │   └── Compat.browser
                │   ├── DefaultWsdlHelpGenerator.aspx
                │   ├── machine.config
                │   ├── settings.map
                │   └── web.config
                ├── 4.0
                │   ├── Browsers
                │   │   └── Compat.browser
                │   ├── DefaultWsdlHelpGenerator.aspx
                │   ├── machine.config
                │   ├── settings.map
                │   └── web.config
                ├── 4.5
                │   ├── Browsers
                │   │   └── Compat.browser
                │   ├── DefaultWsdlHelpGenerator.aspx
                │   ├── machine.config
                │   ├── settings.map
                │   └── web.config
                ├── browscap.ini
                └── config

@akien-mga
Copy link
Member

I can confirm the bug on Windows too with 3.4 beta 1 builds.

I made a test build from the latest 3.x branch using my 3.3.x containers (i.e. prior to the Mono and Windows container updates in godotengine/build-containers#84): https://downloads.tuxfamily.org/godotengine/testing/Godot_v3.4-beta-20210720_mono_win64.zip

This build seems to work fine, so that confirms that the issue comes from the updated containers and not changes in the 3.x Mono module itself.

Potential problems:

  • Mono was upgraded from 6.12.0.122 to 6.12.0.147 (unlikely to be the cause)
  • Base system was updated from Fedora 33 to Fedora 34 so we have a newer mingw version (unlikely to be the cause)
  • Builds now use godot-mono-builds windows.py to build Mono and the BCL, while previously we were running autotools directly and had to wrap things around with Wine to get a valid output. I had issues getting 6.12.0.147 to build with latest Wine from Fedora 34 so I gave the godot-mono-builds approach a shot, but seems like there's still something off? (likely to be the cause)

Seems it refers to missing System.Native dependency which is not supposed to be included on Windows IINM, it's very likely the same cross-compilation issue which had led us to use Wine as a workaround. So it seems like I'll have to go back to the old version and figure out how to work around Wine not working properly anymore.

@akien-mga
Copy link
Member

So yeah, basically with godotengine/build-containers#84 I removed the workaround from godotengine/build-containers#32 as a combination of:

  • Wine build was stalling with newest Wine on Fedora 34 and I couldn't figure out how to fix it
  • Wishful thinking that maybe the workaround was no longer needed

But the Mono buildsystem is still broken for cross-platform builds from Unix to Windows so the workaround needs to be added back.

@neikeq
Copy link
Contributor

neikeq commented Jul 20, 2021

As discussed on rocket.chat, the BCL seems to be being built against the unix profile instead of the win32 profile. I'll check the build-container changes tomorrow to see why that's happening.

@akien-mga
Copy link
Member

After spending a lot of time trying to go back to the previous buildsystem with a Wine workaround for cross-compilation bugs, I found the bug :) godotengine/godot-mono-builds#46

So I'm finally building 3.4 beta 2 which should have working Mono builds for Windows.

3.x release management automation moved this from Blockers / regressions to Done Jul 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

4 participants