godotengine / godot

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

Failed to create c# project #70468

Open L2750558108 opened 1 year ago

L2750558108 commented 1 year ago

Godot version

4.0(beta 9)

System information

windows10

Issue description

I tried to create a new C# script and I got a error window said "Failed to create C# project" with some error message in console like these

Transient parent has another exclusive child. modules/mono/glue/runtime_interop.cpp:1223 - System.BadImageFormatException: 试图加载格式不正确的程序。 (0x8007000B) at GodotTools.ProjectEditor.ProjectGenerator.GenAndSaveGameProject(String dir, String name) at GodotTools.CsProjOperations.GenerateGameProject(String dir, String name) in /root/godot/modules/mono/editor/GodotTools/GodotTools/CsProjOperations.cs:line 13 Transient parent has another exclusive child.

I make sure I have the newest .net version.

Steps to reproduce

no

Minimal reproduction project

It is a new project

raulsntos commented 1 year ago

Can you show the output of running the dotnet --info command in a console?

Also, did you get any other output in the console? Try running godot with the --verbose flag.

L2750558108 commented 1 year ago

Godot Engine v4.0.beta9.mono.official.e780dc332 - https://godotengine.org OpenGL Renderer: GeForce MX250/PCIe/SSE2

Editing project: D:/Data/Godot/Project/Temp2 Godot Engine v4.0.beta9.mono.official.e780dc332 - https://godotengine.org Vulkan API 1.2.133 - Using Vulkan Device #0: NVIDIA - GeForce MX250

WARNING: Property not found: dotnet/project/assembly_name at: _get (core/config/project_settings.cpp:348) WARNING: Blend file import is enabled in the project settings, but no Blender path is configured in the editor settings. Blend files will not be imported. at: _editor_init (modules/gltf/register_types.cpp:61) ERROR: Transient parent has another exclusive child. at: (scene/main/window.cpp:685) ERROR: System.BadImageFormatException: Could not load file or assembly 'Microsoft.Build, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. File name: 'Microsoft.Build, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' ---> System.BadImageFormatException: (0x8007000B) at System.Runtime.Loader.AssemblyLoadContext.LoadFromPath(IntPtr ptrNativeAssemblyLoadContext, String ilPath, String niPath, ObjectHandleOnStack retAssembly) at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath) at System.Reflection.Assembly.LoadFrom(String assemblyFile) at Microsoft.Build.Locator.MSBuildLocator.<>cDisplayClass15_0.gTryLoadAssembly|1(AssemblyName assemblyName) at Microsoft.Build.Locator.MSBuildLocator.<>cDisplayClass15_0.b0(AssemblyLoadContext assemblyLoadContext, AssemblyName assemblyName) at System.Runtime.Loader.AssemblyLoadContext.GetFirstResolvedAssemblyFromResolvingEvent(AssemblyName assemblyName) at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingEvent(AssemblyName assemblyName) at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingResolvingEvent(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName) at GodotTools.ProjectEditor.ProjectGenerator.GenAndSaveGameProject(String dir, String name) at GodotTools.CsProjOperations.GenerateGameProject(String dir, String name) in /root/godot/modules/mono/editor/GodotTools/GodotTools/CsProjOperations.cs:line 13 at: godotsharp_pusherror (modules/mono/glue/runtime_interop.cpp:1223) ERROR: Transient parent has another exclusive child. at: (scene/main/window.cpp:685)

raulsntos commented 1 year ago

Seems like you are missing the Microsoft.Build assembly, can you show the output of dotnet --info to check which SDKs and runtimes you have installed? Make sure you have the .NET 6 SDK installed and that the path reported by dotnet --info is not an empty directory.

L2750558108 commented 1 year ago

Windows PowerShell 版权所有 (C) Microsoft Corporation。保留所有权利。

尝试新的跨平台 PowerShell https://aka.ms/pscore6

PS C:\Users\User> dotnet --info .NET SDK: Version: 7.0.101 Commit: bb24aafa11

运行时环境: OS Name: Windows OS Version: 10.0.19045 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\7.0.101\

Host: Version: 7.0.1 Architecture: x64 Commit: 97203d38ba

.NET SDKs installed: 6.0.404 [C:\Program Files\dotnet\sdk] 7.0.101 [C:\Program Files\dotnet\sdk]

.NET runtimes installed: Microsoft.AspNetCore.App 6.0.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 6.0.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 6.0.12 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found: x86 [C:\Program Files (x86)\dotnet] registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables: Not set

global.json file: Not found

Learn more: https://aka.ms/dotnet/info

Download .NET: https://aka.ms/dotnet/download

raulsntos commented 1 year ago

Can you check the contents of the C:\Program Files\dotnet\sdk\6.0.404 directory?

L2750558108 commented 1 year ago

image

raulsntos commented 1 year ago

The System.BadImageFormatException exception can be due to a mismatch in the SDK bits, it sounds like it may be trying to load the 32-bit version of the Microsoft.Build assembly instead of the 64-bit version because that's the version registered by Microsoft.Build.Locator.

Can you run Godot with the --verbose flag to see what .NET SDK is found by Godot? The message should look like this:

Found .NET Sdk version '{sdkVersion}': {sdkPath}

In your dotnet --info there's this part that says you have installed the 32-bit .NET SDK:

Other architectures found:
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

My suggestion would be to uninstall the 32-bit .NET SDK. I suspect that would resolve the issue, but let me know if this solution is not acceptable.

L2750558108 commented 1 year ago

This is the result of running godot with "--verbose" image And uninstall .net x86 doesnt solve the problem.This is the console after uninstalling .net x86:

Godot Engine v4.0.beta9.mono.official.e780dc332 - https://godotengine.org OpenGL Renderer: GeForce MX250/PCIe/SSE2

Editing project: D:/Data/Godot/Project/test4.0 Godot Engine v4.0.beta9.mono.official.e780dc332 - https://godotengine.org Vulkan API 1.2.133 - Using Vulkan Device #0: NVIDIA - GeForce MX250

WARNING: Blend file import is enabled in the project settings, but no Blender path is configured in the editor settings. Blend files will not be imported. at: _editor_init (modules/gltf/register_types.cpp:61) ERROR: Transient parent has another exclusive child. at: (scene/main/window.cpp:685) ERROR: System.BadImageFormatException: Could not load file or assembly 'Microsoft.Build, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. 试图加载格式不正确的程序。 File name: 'Microsoft.Build, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' ---> System.BadImageFormatException: 试图加载格式不正确的程序。 (0x8007000B) at System.Runtime.Loader.AssemblyLoadContext.LoadFromPath(IntPtr ptrNativeAssemblyLoadContext, String ilPath, String niPath, ObjectHandleOnStack retAssembly) at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath) at System.Reflection.Assembly.LoadFrom(String assemblyFile) at Microsoft.Build.Locator.MSBuildLocator.<>cDisplayClass15_0.gTryLoadAssembly|1(AssemblyName assemblyName) at Microsoft.Build.Locator.MSBuildLocator.<>cDisplayClass15_0.b0(AssemblyLoadContext assemblyLoadContext, AssemblyName assemblyName) at System.Runtime.Loader.AssemblyLoadContext.GetFirstResolvedAssemblyFromResolvingEvent(AssemblyName assemblyName) at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingEvent(AssemblyName assemblyName) at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingResolvingEvent(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName) at GodotTools.ProjectEditor.ProjectGenerator.GenAndSaveGameProject(String dir, String name) at GodotTools.CsProjOperations.GenerateGameProject(String dir, String name) in /root/godot/modules/mono/editor/GodotTools/GodotTools/CsProjOperations.cs:line 13 at: godotsharp_pusherror (modules/mono/glue/runtime_interop.cpp:1223) ERROR: Transient parent has another exclusive child. at: (scene/main/window.cpp:685)

danielanywhere commented 1 year ago

Direct illumination of the issue has just been provided coincidentally by tebjan over at Stride3d. I have tested it on Godot 4 beta 9 and everything works fine.

Summary: A recent Visual Studio update with default settings purposely replaces .NET 6.0 SDK with .NET 7.0 SDK. By itself, .NET 7.0 SDK is incompatible with this game engine and re-installing the .NET 6.0 SDK side-by-side may allow the engine to behave as expected when it accesses the MSBUILD tools.

The specific SDK version that needs to be present on your PC is located at https://dotnet.microsoft.com/en-us/download/dotnet/6.0

Select the x64 version.

L2750558108 commented 1 year ago

This error no longer appears after I use the x64 version. But the x86 version should not report an error, and the x64 system should be able to run x86 programs

danielanywhere commented 1 year ago

@L2750558108 I think I may have tracked down a full workaround. This only applies to the Mono versions of Godot and has not been tested for the base versions.

First, you need to install or verify that you have a full .NET 6.0 SDK layer for every Godot executable architecture you are using. For example, if you develop on Godot Mono x64, you need the .NET 6.0 x64 SDK. If you develop on Godot Mono win32 you need the .NET 6.0 x86 SDK. If you develop on both, you need both the x86 and x64 versions of the .NET 6.0 SDK installed on your PC. The remainder of this post assumes that you have installed both versions of Godot Mono and both versions of the .NET 6.0 SDK.

In your Windows Environment Variables / System Variables / Path, you will first need to verify that both SDK paths have been registered. Commonly, those are C:\Program Files\dotnet\ for x64 and C:\Program Files (x86)\dotnet\ for x86.

Most importantly, before you begin developing with Godot Mono win32, move the C:\Program Files (x86)\dotnet\ entry above the other one in your System Variables / Path list. Alternately, when you begin developing with Godot Mono x64, first move C:\Program Files\dotnet\ above the other one in your System Variables / Path. This switch can be automated with command lines, if you prefer.

For more information about x86 / x64 preference selection and using the System Variables / Path list, see Microsoft .NET Documentation - It was not possible to find any installed .NET Core SDKs

L2750558108 commented 1 year ago

I think it would be better to have a clearer error message, such as "No corresponding schema found. net" and remove the long list of strange error messages now @danielanywhere

theiwaz commented 1 year ago

@danielanywhere solved my problem not being able to create the c# project. Thank you

https://github.com/godotengine/godot/issues/70468#issuecomment-1374489084

derwaldgeist commented 1 year ago

Unity dev coming here for obvious reasons. This error message is super confusing. Why do you need to download the full SDK when Godot tells you to download the runtime (only)?

danielanywhere commented 1 year ago

@derwaldgeist Thanks for checking out Godot. I'm not exactly sure which doc page you are referring to, but just to be clear, I believe this issue is limited to early 4.x versions. I may be mistaken, but someone else watching may be able to confirm that 3.x (mono runtime) versions are immune.

I do understand there is confusion around this general subject, all of which will be cleared up shortly within what I believe will be the next couple of versions of Godot. You can find a good reference for getting a running 4.1 version of your development environment here: https://docs.godotengine.org/en/stable/tutorials/scripting/c_sharp/c_sharp_basics.html

As the article states, if you are going to be developing your game with the C# version of Godot, you will want to download and install the full Microsoft .NET 6.0 SDK because it contains the version of MSBUILD that is used to compile your game before running. There is a link to the official Microsoft .NET 6.0 SDK download page available in an earlier post on this thread.

More Information

Please note that Godot has both C# and non-C# versions, and this issue only applies to the C# version. Additionally, Godot has both 32-bit and 64-bit versions, and so does the .NET 6.0 SDK. If you are only going to use one hardware level or the other, you only need the one SDK matching the chosen Godot hardware level, for example, 32-bit .NET for 32-bit Godot or 64-bit .NET for 64-bit Godot. However, if you plan to develop for both 32-bit and 64-bit, you will need to make sure both levels are installed.

As a former Unity dev, please also note that according to the article in the above link, this version (as of 4.1) of the Godot C# system doesn't yet work with Android, iOS, or Web platforms. If you intend to publish to those platforms in the immediate future, please temporarily use the Godot 3 C# system for the time-being.

derwaldgeist commented 1 year ago

@danielanywhere Wow, thanks for the excellent response, highly appreciated. Wasn't aware that Godot 4 does not support mobile platforms (yet). We'll need AR support anyways, and as far as I can tell, this is not part of the platform right now? Still, keep up the good work. Many people lost trust in Unity now, this is a big chance for Godot!

akien-mga commented 1 year ago

Wasn't aware that Godot 4 does not support mobile platforms (yet).

FYI, Godot 4.2 beta 1 released yesterday adds support for Android and iOS for C# projects: https://godotengine.org/article/dev-snapshot-godot-4-2-beta-1/

IroConOx commented 1 year ago

@danielanywhere fixed the problem, thanks. What does that actually do though lmao. Is there anything else besides godot that would be affected by reordering these variables?

nrjohnstone commented 1 year ago

I'm currently using godot 4.1.2 with .NET 6.0 and 8.0 preview SDKs installed and it seems to pick .NET 8.0 on startup if the verbose messages are correct.

.NET: Initializing module... Found hostfxr: C:\Program Files\dotnet\host/fxr/8.0.0-preview.7.23375.6/hostfxr.dll .NET: hostfxr initialized .NET: GodotPlugins initialized

From dotnet --info

.NET SDKs installed: 6.0.415 [C:\Program Files\dotnet\sdk] 8.0.100-preview.7.23376.3 [C:\Program Files\dotnet\sdk]

I am also suffering the error about failing to create a C# project

Also tried with the latest beta "Godot_v4.2-beta1_mono_win64" and still the same error.

I work with multiple sdk's on various projects, so uninstalling 8.0 and only having 6.0.415 isn't really an option