Repository: godot
Issue: Custom HTML5 export template of Godot Mono 3.4.4-stable fails to launch, complaining 'The assembly 'GodotSharp' is out of sync.' and 'unreachable'
Labels: bug,platform:web,topic:dotnet,topic:export

### Godot version

3.4.4.stable.mono

### System information

Linux 5.15.32-1-MANJARO (AMD Zen with Vega Mobile Graphics)

### Issue description

I'm trying to build custom export template in version `3.4.4.stable` which I will remove various of unused modules and enable `optimize=speed` option. The build process seems to go smoothly until I put it in custom template and export it on `3.4.4.stable` editor and test run it. After loading process finishes, canvas only shows `unreachable` label, and debugging panel shows below (`>` represents each line of text)
```
> ERROR: The assembly 'GodotSharp' is out of sync.
>    at: _load_api_assemblies (modules/mono/mono_gd/gd_mono.cpp:954) - The assembly 'GodotSharp' is out of sync.
> ERROR: FATAL: Method failed.
>    at: _load_api_assemblies (modules/mono/mono_gd/gd_mono.cpp:965) - FATAL: Method failed.
> exception thrown: RuntimeError: unreachable,RuntimeError: unreachable
    at wasm://wasm/0412fade:wasm-function[63154]:0xcfcf3d
    at wasm://wasm/0412fade:wasm-function[63155]:0xcfcf69
    at wasm://wasm/0412fade:wasm-function[65413]:0xd54255
    at wasm://wasm/0412fade:wasm-function[32205]:0x5d8c1d
    at wasm://wasm/0412fade:wasm-function[29433]:0x52dc1e
    at wasm://wasm/0412fade:wasm-function[29469]:0x53285b
    at wasm://wasm/0412fade:wasm-function[14679]:0x2aaf29
    at wasm://wasm/0412fade:wasm-function[30750]:0x5930ee
    at Module._main (http://192.168.1.18:8080/GodotMonoHelloWorld/index.js:9:403460)
    at Object.callMain (http://192.168.1.18:8080/GodotMonoHelloWorld/index.js:9:415776)
> unreachable
```
![image](https://user-images.githubusercontent.com/17522480/167175420-9e206379-8d58-49d9-b867-bd9d4eb70920.png)

This happen even if I have used bare-bone command to build the template and got approximately same size of template file compared to official build.

This is custom build one:
![image](https://user-images.githubusercontent.com/17522480/167175484-582787cd-447d-46fe-8ca7-b0cddfe5802f.png)

And, this is official build:
![image](https://user-images.githubusercontent.com/17522480/167175536-a1fca29d-0cbc-49df-84eb-7019a6739c2e.png)

Ps: While building glue, there are some errors produced but it seems like the glue generator just ignored it. There are possibly more errors but my terminal got overflow and couldn't display all of them, but here's some example:
![Screenshot_20220506_212100](https://user-images.githubusercontent.com/17522480/167176882-19ccf3ee-fb8e-434a-b324-9588aecb9c5b.png)


### Steps to reproduce

Environment:
- Linux 5.15.32-1-MANJARO (AMD Zen with Vega Mobile Graphics)
- Mono 6.12.0.122-1
- Mono MSBuild 16.10.1.xamarinxplat.2021.05.26.14.00-2
- Emscripten 1.39.9 (configured with `emsdk install 1.39.9` and `emsdk activate 1.39.9`)
- .NET SDK 6.0.2.sdk102-1 (packages including `dotnet-host`, `dotnet-runtime`, `dotnet-sdk`, `dotnet-targeting-pack` installed from official Manjaro repository)
- `godot-mono-builds` official build version `1cc1257` and `df330ce`
- `godot-mono-builds`'s Base Class Library matching each versions.
- Godot Mono test project, built with `dotnet CLI` option. (I had absolutely no luck with `MSBuild (Mono)` even though I satisfied all requirements but it keeps showing `Parameter "AssemblyFiles" has invalid value "/usr/lib/mono/4.7.2-api/mscorlib.dll". Could not load file or assembly 'System.Reflection.Metadata, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.`)

Steps:
1) Cloning project to local with `git clone https://github.com/godotengine/godot .` (I'm already in separated directory)
2) Switching branch to `3.4.4-stable` with `git checkout 3.4.4-stable`
3) Start building Mono glue generator with:
```
scons p=x11 tools=yes module_mono_enabled=yes mono_glue=no -j 7
```
4) Start generating Mono glue with:
```
./bin/godot.x11.tools.64.mono --generate-mono-glue modules/mono/glue
```
5) Start building export template with command:
```bash
#!/bin/bash
source $HOME/EmscriptenSDK/emsdk_env.sh
cd $HOME/Godot.Source
emsdk activate 1.39.9
scons p=javascript --clean
scons profile=$HOME/Godot.Build.Profiles/JsMono.py -j 8 module_mono_enabled=yes mono_glue=yes mono_static=yes mono_prefix=$HOME/Godot.Mono.Releases/wasm-runtime-release
```
This is content of custom build file (`$HOME/Godot.Mono.Releases/JsMono.py`)
```py
# Core
p="javascript"
tools="no"
target="release"
optimize="size"
use_lto="no"
disable_3d="no"
disable_advanced_gui="no"

```
6) Start building project with the build, in `release` mode.
7) Serving the game with Node.JS's `http-server` installed from `npm`.
8) Launching URL from site running on (7) in Chromium Web Browser as `Guest`.
9) Error occurs.

### Minimal reproduction project

Example project:
[GodotMonoHelloWorld.Source.zip](https://github.com/godotengine/godot/files/8642296/GodotMonoHelloWorld.Source.zip)v

Export template built (1cc1257):
[godot.javascript.opt.mono.zip](https://github.com/godotengine/godot/files/8642288/godot.javascript.opt.mono.zip)

Export template built (df330ce):
[godot.javascript.opt.mono.zip](https://github.com/godotengine/godot/files/8642359/godot.javascript.opt.mono.zip)

Example exported project with the template (1cc1257):
[GodotMonoHelloWorld.Exported.zip](https://github.com/godotengine/godot/files/8642297/GodotMonoHelloWorld.Exported.zip)

Example exported project with the template (df330ce)
[GodotMonoHelloWorld.df330ce.zip](https://github.com/godotengine/godot/files/8642362/GodotMonoHelloWorld.df330ce.zip)