stride
stride copied to clipboard
Adding scripts by dragging
Release Type: Official Release
Version: 4.1.0.1734
Platform(s): Windows
Describe the bug Dragging the script to add it to an entity is blocked by the message: "No scripts inheriting from ScriptComponent found in asset..." This is the same message if I drag it to the entity tree or the component list.
To Reproduce Steps to reproduce the behavior:
- Start a new project
- Create a new SyncScript
- Drag the script onto the Entity view or the component list.
Expected behavior According to this page, dragging is supported.
The error message claims that there are no scripts inheriting from ScriptComponent. The code does inherit from SyncScript which in a few steps inherit from ScriptComponent.
The script can be added using the "Add component" button.
I've tracked down the issue to:
https://github.com/stride3d/stride/blob/7e836297cb5930c01e6dfa0183e7f3cc64748fb6/sources/editor/Stride.Assets.Presentation/AssetEditors/ScriptSourceCodeResolver.cs#L88
where assemblyFullName is "MyGame, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" and x.FullName is "MyGame, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" resulting in null assembly and ignoring all types
Was this ever resolved? I get the same error when trying to drag and drop an EntityComponent script onto an entity.
The problem seems to reside in the fact that Roslyn from the CodeAnalysis returns a wrong version (0.0.0.0) with .NET 6.0 projects that have an autogenerated AssemblyInfo.cs file while loading the compiled assembly actually uses the correct version (1.0.0.0). I am trying to see if it is possible to find the assemblies by other means.
I'm wondering if checking the version here is necessary. Ideally yes, but I imagine it would be rare for a Stride project to load two versions of the same assembly in normal scenarios. In general we can't prevent users from referencing multiple 3rd party library versions (in the course of some complicated dependency tree), but doing so will render errors in the editor anyways in some scenarios (i.e. having 2 versions of a third-party script on two entities, when user defines another script which takes that 3rd party script as a reference I imagine the editor would permit only one of those to be dragged over and lead to confusion).
@manio143 I have my own branch with a check by name only but now I am facing another issue: the compilation given by Roslyn in that case, unfortunately, does not return any symbol for the script class so when checking for the base type it always return false. I am no expert in Roslyn but it seems that it cannot find any referenced nuget package.
I took a better look at this method and have the following ideas:
- is the referenced version of Roslyn up to date enough to support .NET 6?
- if we keep iterating over symbols I had a situation where base type was null and had to call
OriginalDefinition
on it - not sure if it would help here - lastly, why not iterate over types and use reflection
IsAssignableFrom
(or however that method is called exactly) and then map to the symbol to find the file path
I wanted to try to update to Microsoft.CodeAnalysis 4.4.0 but faced issues with Roslynpad that does not work (even after adapting the code it seems that it cannot find the Microsoft.CodeAnalysis.Diagnostics.IDiagnosticService that should be injected by MEF in the constructor of RoslynPad IDiagnosticService). It still returns 0.0.0.0 as a version for the assembly so I guess that it is not possible to rely on the full name:
About using Reflection I have far more experience than Roslyn but I cannot find how to map Roslyns ISymbols
to types but I can investigate further.
If we manage to get RoslynPad working using 4.4.0 as packages are available maybe we can move to 4.4.0 of CodeAnalysis. The problem is that I am not sure it is gonna solve the issue. I may try using another sample project in the coming days but it may take some time/
You can use the GetTypeByMetadataName
on the compilation object with FullName of a type (namespace qualified) to get the symbol for it.
Thank you for looking into this!
Opened a PR containing a fix for the problem. Wanted to add some Unit Tests but I am still learning the codebase
The error persists in version 4.1.0.1822 .Net 6.0.5. Will there be correction?
This should have been fixed, but if it is occurring still it needs further debugging.
This should have been fixed, but if it is occurring still it needs further debugging.
Sorry, I was in dotnet 6.0.3. Updating to 6.0.4 it's worked.