godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.04k stars 21.11k forks source link

System.Runtime.Loader errors out after adding in a new csharp script #53951

Open Nukiloco opened 2 years ago

Nukiloco commented 2 years ago

Godot version

v3.4.beta6.mono.official [3e2bb415a]

System information

Windows 10, Nvidia GTX 750 Ti

Issue description

Before you ask, yes this builds and runs. Though as soon as I add in a new csharp script and click back into Godot, Godot crashes with this error:

ERROR: Mono: FATAL ERROR '* Assertion at /root/mono-6.12.0.147/mono/metadata/class.c:2834, condition `is_ok (error)' not met, function:mono_class_get, Could not load file or assembly 'System.Runtime.Loader, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.
 (in domain , error)', ABORTING! Logfile: 'C:/Users/caleb/AppData/Roaming/Godot/mono/mono_logs/2021-10-18_04.11.58_42468.log'.

Note that I'm not using version 4.1.1.0, I'm using version 4.3.1

csproj

<Project Sdk="Godot.NET.Sdk/3.3.0">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="System.Runtime" Version="4.3.1" />
  </ItemGroup>
  <ItemGroup>
    <Compile Remove="Addon\**" />
    <Content Include="Addon\**" />
  </ItemGroup>
</Project>

Steps to reproduce

  1. Get one of your csharp files to use System.Runtime.Loader.
  2. Build project in Godot.
  3. Run project in Godot.
  4. See that there is no errors and it runs fine.
  5. Add new csharp file to Godot.
  6. Godot crashes.
  7. Project will keep crashing every time you open it until you remove .mono/temp and restore your project.

Minimal reproduction project

No response

akien-mga commented 2 years ago

A minimal reproduction project would be appreciated, especially if the conditions to reproduce the error are to set a custom PackageReference and TargetFramework in the solution.

raulsntos commented 2 years ago

~The Godot C# project is a library so netcoreapp3.1 is not a valid framework. You have to use netstandard.~ Nevermind I got confused.

Nukiloco commented 2 years ago

A minimal reproduction project would be appreciated, especially if the conditions to reproduce the error are to set a custom PackageReference and TargetFramework in the solution.

Currently making one right now.

The Godot C# project is a library so netcoreapp3.1 is not a valid framework. You have to use netstandard.

Will also try to switch to a netstandard to see if that works.

Nukiloco commented 2 years ago

netstandard uses net framework which system.runtime.loader only exists on net core, that's why I was using netcoreapp3.1 earlier

again though using netcoreapp3.1 did work and did build successfully until i added a new script still working on the minimal reproduction project

Edit: actually now searching it up again, i don't think what I said about netstandard was true

Nukiloco commented 2 years ago

https://stackoverflow.com/questions/60982315/assemblydependencyresolver-not-resolving

From searching it up, yea I can't use netstandard here, I can only use netcoreapp3.1

I assume I would have to find another way to load in dynamic c# code or see if I can load in assembly without using assembly dependency resolver

Nukiloco commented 2 years ago

Yea ok at this point, this seems like this is happening with any package that has to do with code compiling.

 modules/mono/csharp_script.cpp:2306 - Exception thrown from constructor of temporary MonoObject:
 modules/mono/mono_gd/gd_mono_utils.cpp:369 - System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.
 modules/mono/csharp_script.cpp:2306 - Exception thrown from constructor of temporary MonoObject:
 modules/mono/mono_gd/gd_mono_utils.cpp:369 - System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.CodeAnalysis, Version=3.11.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.

I installed a new package, got the same errors, and downgraded it, which I still got the same errors anyways. Though what seems strange is that on Version=4.0.0.0 the actual version was 4.0.0-5.final. It seems like its adding an extra .0 to every package that gets installed.

Note that the Godot console is complaining about this though there is no errors in the build output. I guess I will make a minimal example repository that includes this package instead since its doing every time.

jcweaver997 commented 2 years ago

This is probably related to my problem, since my problem involves MessagePack and PostSharp which both add compile steps. https://github.com/godotengine/godot/issues/53693