-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
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
.NET: Failed to unload assemblies. Please check <this issue> for more information. #78513
Comments
Something was wrong with one of my [Tool] class in code after upgrade from 4.0 to 4.1 ("This class does not inherit from Node") and got this error. I just changed it to Node3D and back, and then the "cache" bug got fixed magicly? |
The workaround for this using this library is also copied below:
As far as I'm aware Godot doesn't provide an event for signalling when your dll/plugin is about to be unloaded, so you essentially need to call the above solution after every serialization/deserialization. |
You can use the normal |
Thanks for the info, I somehow missed that. As an FYI, I played around with your solution trying it on a My solution was to place the code within a
This ensures it is not dependent on any node(s) and is always registered only once, and re-registered upon reloading the assembly. |
I am not using The only library I am referencing is one I have authored. My
That project's csproj is dead simple, with no other project references. @RedworkDE, you mentioned "does not violate any guidelines"; what are these guidelines? Is there a documentation page? Something else? Thanks. |
It refers to Microsoft's docs page that was linked a bit further up: https://learn.microsoft.com/en-us/dotnet/standard/assembly/unloadability#troubleshoot-unloadability-issues Also all these really also have to apply to the library, but for most libraries there isn't too much you can do about it (except not use the library) |
I am hitting this issue and I'm fairly confident it is not my (direct) fault. I can reliably cause this error to appear in the console by running a C# rebuild while an offending Scene is loaded in the editor:
If I build again, I will get the "Failed to unload assemblies" error. If I close the offending scene and run the rebuild again, I rebuild without any issues and everything is fine. I've been trying to figure out precisely what's needed to get this problem to repro. It seems connected to the new |
You also seem to be using generic |
Yeah, it seems that's the root cause. That would be very unfortunate if true. I have a micro reproduction project and I'll write up another issue. It runs fine but for the occasional compilation issue. |
I have created that reproduction project: #79519 |
I don't know what is going on or why but I started getting this error today in Godot 4.1.1 .NET version. It's completely blocking me from doing any development. I've spent all day trying to hunt down weird behaviors. It seems that when this issue happens it's corrupting properties in the editor - or possibly inherited scenes are breaking. |
Slight update. I'm just guessing here, but I suspect the issue might be somehow related to the new GlobalClass. That's all I can think of. I got rid of the errors by deleting a node which had either been added via GlobalClass node or it was a regular node with the same script attached to it. Either way, I deleted it and the error was gone. I added it back in as GlobalClass node - the error stayed gone. |
I can absolutely understand that. The problems since 4.1 are unfortunately unexpected, varied and sometimes difficult to analyse. The new As described above, some problems are related to The simplest workaround is probably to close the problematic scene tabs (mostly Otherwise, try the code listed at the top. Surprisingly, the following worked for me:
With this code, the unload works after an incorrect attempt. |
I added generic nodes today, and I started getting this issue. |
I'm getting this issue in 4.1, and I'm not using any third-party libraries, nor am I using generic nodes, nor am I using the Well, OK. I used to have a C# script that had both of those attributes, but I've since rewritten it in GDScript, so it shouldn't be relevant anymore...right? Is there any chance that the ghost of the C# version of that script still lives on? Maybe in some cache somewhere? |
Also happens whenever I enable a C# editor plugin, and only goes away once I disable the plugin and restart the editor. |
The new
I will try today the method mentioned above by Quinn-L and put the unload handler in an |
Nope. We decided not to waste so much time with this problem and rewrite certain parts of the code in |
I think I figured out what was causing it for me. It wasn't editor plugins, global classes, or tool scripts. No, it's because I had more than one Node class in a single script file. namespace FlightSpeedway
{
public partial class Player : CharacterBody3D
{
private PlayerState _currentState;
private Vector3 _spawnPoint;
private Vector3 _spawnRotation;
public void ChangeState<TState>() where TState : PlayerState
{
GD.Print($"Changing state to {typeof(TState).Name}");
_currentState?.OnStateExited();
foreach (var state in States())
{
state.ProcessMode = ProcessModeEnum.Disabled;
}
_currentState = States().First(s => s is TState);
_currentState.ProcessMode = ProcessModeEnum.Inherit;
_currentState.OnStateEntered();
}
private IEnumerable<PlayerState> States()
{
for (int i = 0; i < GetChildCount(); i++)
{
var child = GetChild<Node>(i);
if (child is PlayerState state)
yield return state;
}
}
}
public partial class PlayerState : Node
{
protected Player _player => GetParent<Player>();
protected Node3D _model => GetNode<Node3D>("%Model");
public virtual void OnStateEntered() {}
public virtual void OnStateExited() {}
}
} Once I moved In case this is relevant, there are other node classes(such as |
|
I can't confirm, we have all classes in separate files and as soon as |
I'm not saying those scripts don't trigger the problem; I'm saying that multiple nodes in one file also triggers this problem. |
There are multiple causes of this problem. From the comments, there are at least three ways you can run into the issue.. |
This comment was marked as off-topic.
This comment was marked as off-topic.
Just ran into this issue but in a seemingly different way than described above. Failing code: [GlobalClass]
public partial class WeaponDefinition : Resource
{
[Export]
public InventoryItemDefinition InventoryItem { get; private set; } = new();
}
Fixed code: [GlobalClass]
public partial class WeaponDefinition : Resource
{
[Export]
public InventoryItemDefinition InventoryItem { get; private set; } = null!;
} |
I would not choose to do anything complex in an |
Can we please recentre on topic please? This thread is already very long, the future GDExtension implementation is unrelated to the issue at hand here. FWIW, the error you're experiencing is due to the deserialization of callables happening late after the state of your objects is restored. I have already started to look at how we could fix those timing issues during our assembly reload process last week. I need to run more tests on exactly how to improve this without changing the current behaviour. |
This issue has been bothering me for a long time. Today I found the root cause through continuous attempts. It is caused by the use of anonymous functions when binding signals! |
This issue has fixed in 4.3 you may try it out if the fix works. |
It's not in 4.3.dev5, it will be in dev6 which should release in a few days |
If possible, can you publish an issue about this, and, include a MRP (minimal reproducible project) for this issue you are encountering? Or, just share the code snippet that causes the issue? |
I'm very sorry, I found that I didn't compile the mono version of godot through the correct process. At present, I don't know how to compile GodotSharp, so I directly copied the old GodotSharp folder and used it with the new godot binary, so my test results is not credible. I will try again when 4.3-dev6 is officially released. This is my test code:
My testing process is:
|
See the .Net specific page for Compiling the Engine. |
Thank you! I can confirm that the new version has indeed fixed this issue. |
I encountered this error regularly in 4.2.2 as well. Running Godot Engine v4.3.dev.mono.custom_build.7529c0bec I no longer encounter the issue on any normal script, but I have a editor plugin that fails almost instantly as I run the project |
As stated in the original message: if you're encountering this error, think the issue is caused by Godot, and does not fall in the list of already reported causes (the list up top is edited and maintained up to date), please open a dedicated issue. Thank you. |
Hello, I encountered the issue by adding a static constructor on a node class (used to initialize a static variable to avoid having to declare it as a nullable). I initialized it in the node constructor and ignored the warning CS8618 as a workaround. |
@Tichau If possible, can you publish an issue about this, and, include a MRP (minimal reproducible project) for this issue you are encountering? Or, just share the code snippet that causes the issue? |
Hello, I received the same error message in version 4.2.2. When changing an EditorPlugin written in C#. More precisely, when a script was attached to the [Tool] attribute to use it in the EditorPlugin. Godot Engine v4.2.2.stable.mono.official (c) 2007-present Juan Linietsky, Ariel Manzur & Godot Contributors.
Good idea to write this in an error message. |
I thought I was done with these kind of issues (4.3.dev6 looked like it was good), but I'm getting this after upgrading to 4.3.beta1 (Windows 10, .NET).
No idea which of my source files is causing this, it doesn't say. I'm not sure if this is related, but it feels like it. |
#78513 (comment) |
Does anyone of those links explain the behaviour that the assembly unload stops working after a couple of reloads? I'm still on 4.2.2 but that's what I'm seeing: assembly reloading works a couple of times usually after which it stops working. I don't think any new code from my side that uses any of the things that are said to cause assembly unloading issues would run only after like the seconds or third time an assembly reload happens. |
4.2.x is suffering from all four major issues. These are bugs within the Godot Engine / .Net Module that a user will encounter regardless of whether they are creating Editor Tools or not. These issues are fixed in 4.3 but not (yet?) cherry-picked to 4.2 (or maybe never for #81903 because of this). |
I encounter this after compiling/running scene with another godot instance, mostly from command line after compiling new csharp scripts (IDE: Jetbrains Rider).
And then I go back to the editor, it pops up this thread. |
I would like to share my Theory. TL;DR; Multiple Resource classes that are "GlobalClass" and located in the same file are problematic and when you refactor all your resource into separated files, this issue disappear. The long version:I was having this issues through 4.2 until 4.3-RC1. Just before RC1 release, I had refactor a lot of my code and split files from multiple classes inside a single file to each class has it's own separated file. When RC1 release, I just finished that refactor and I was happy that the Engine was now working. I've though the issue was solve within RC1, while it wasn't mention though the changelog. RC1, RC2, RC3 and 4.3-stable were all improving my experience until I've start designing a new systems for my game. This issues that was uncleared to me but only allowed me to build my project once per "Godot execution" was back and worst. Then I though maybe I have found the culprit. Right now I can't confirm but I highly think I've found a reproductible pattern. When I had the issue, I had multiple Resource classes found in the same file at multiple location. I had this issues where my scenes where corrupted after running into this issues and saving my scene. (AKA: Running your game will save any opened and edited scene which were edited not by me, but by the compilation issue process. Resulting that after any build that has failed, the following build will corrupt your opened scene if this issues has happen. the C# meta data is corrupted and Godot will try using this new meta data, will find any node with a "Resource" [Export] property to be incorrect and will corrupt it with a null value...). All my tscn files changed and now having exported variable inserted to null instead of what it was before. Signal were corrupted and to have my build working again, I had to "reset" each exported variable that was corrupted. I've start connecting signals through my C# code due to that issues... But one of the things I notice is that all my "resource" exported variable where the Script value in the Inspector was "corrupted". (By memory) It look like: "res://src/SomethingComponent.cs::Resource_4go2v" the UUID at the end. I had to manually connect the Script to the Right C# file to fix the issues and it was reccuring like "Moe's kicking Barney out of his bar" meme. One thing I made sure to fix in the refactoring I have done prior to RC1 was that I had one file with like 10 Resource "GlobalClass" and one day I've decide to refactor all those classes into separated file for each Resource class. After fixing my .tres files, it didn't happen for like 3 weeks. Until I start working on my next systems, which I guess I start creating new Resource classes and put multiple resource classes inside the same file again. Now I am stuck with this issues which disappear for a short period. Pretty sure it's related to something like this. When I will tackle the refactoring, I will make sure to do a follow up about this theory. Until then, I encourage anybody to test this solution if it solved the issue. At least, if it doesn't solve the issues, it will reduced the Tech Debt in their game. Lol Those are example of visual distinction found when the bug happen. |
I don't think I've used any Godot resources at all. Other than the built-in ones of course. So I think my project contains zero resources with a C# script related to them. And I still see this issue (though I haven't updated to 4.3 yet as I've been busy the past week) so I don't think that can be the whole picture. Edit: I've now tried Godot 4.3 and I still got the same issue within about 5 minutes. |
Is it possible that the resourceformatsaver and resourceformatloader that you wrote yourself could cause this problem? |
@maxime4000 |
I had this error caused by using [Export] on an enum and assigning it to the MultiplayerSynchroniser. Not sure which part was the exact cause. |
This is not the case, at least not universally. I'm consistently seeing this issue in a project in which there are no shared |
Godot version
Any 4.x version
Issue description
Assembly reloading can fail for various reasons, usually because a library used in tools code is not compatible with assembly unloading.
After unloading has failed, C# scripts will be unavailable until the editor is restarted (in rare cases it may be possible to complete the unloading by re-building assemblies after some time).
If assembly unloading fails for your project check Microsoft's troubleshooting instructions and ensure that you are not using one of the libraries known to be incompatible:
If you know of additional libraries that cause issues, please leave a comment.
If your code doesn't use any libraries, doesn't violate any guidelines and you believe unloading is blocked by godot, please open a new issue. Already reported causes are:
Minimal reproduction project & Cleanup example
Footnotes
Bugsquad edit ↩ ↩2
The text was updated successfully, but these errors were encountered: