0
Confirmed

2.0.0a10 Using type in global namespace as variable type breaks code generation

Jeremy TAN 2 years ago updated by Lazlo Bonin (Lead Developer) 2 years ago 8

Hi there, When using a Custom Class as a variable type in my Bolt Component, I can't generate or preview C# script and I get this error:

MyCustomClass.cs

Error Message:

ArgumentNullException: Value cannot be null.
Parameter name: name
Ludiq.EnsureThat.IsNotNull (System.String value) (at Assets/Ludiq/Ludiq.Core/Runtime/Ensure/EnsureThat.Strings.cs:47)
Ludiq.CodeDom.CodeUsing..ctor (System.String name) (at Assets/Ludiq/Ludiq.Core/Editor/CodeDom/Nodes/CodeUsing.cs:7)
Ludiq.Bolt.BoltGenerationUtility.AddNamespaces (Ludiq.Bolt.HybridType type, Ludiq.Bolt.DocumentGeneration document) (at Assets/Ludiq/Bolt.Core/Editor/Generation/BoltGenerationUtility.cs:55)
Ludiq.Bolt.BoltClassVariableGenerator.GenerateProperty (Ludiq.Bolt.PropertyGeneration property) (at Assets/Ludiq/Bolt.Core/Editor/Generation/Generators/BoltClassVariableGenerator.cs:88)
Ludiq.Bolt.PropertyGeneration.GenerateDeclaration () (at Assets/Ludiq/Bolt.Core/Editor/Generation/Generations/PropertyGeneration.cs:18)
Ludiq.Bolt.MemberGeneration`1[TDeclaration].Ludiq.Bolt.IMemberGeneration.GenerateDeclaration () (at Assets/Ludiq/Bolt.Core/Editor/Generation/Generations/MemberGeneration.cs:32)
Ludiq.Bolt.CompositeGeneration`1+<>c[TDeclaration].b__26_0 (Ludiq.Bolt.IMemberGeneration m) (at Assets/Ludiq/Bolt.Core/Editor/Generation/Generations/CompositeGeneration.cs:162)
System.Linq.Enumerable+SelectIListIterator`2[TSource,TResult].MoveNext () (at <351e49e2a5bf4fd6beabb458ce2255f3>:0)
System.Collections.Generic.List`1[T].InsertRange (System.Int32 index, System.Collections.Generic.IEnumerable`1[T] collection) (at <437ba245d8404784b9fbab9b439ac908>:0)
System.Collections.Generic.List`1[T].AddRange (System.Collections.Generic.IEnumerable`1[T] collection) (at <437ba245d8404784b9fbab9b439ac908>:0)
Ludiq.Bolt.BoltClassGenerator.GenerateDeclaration (Ludiq.Bolt.ClassGeneration classGeneration) (at Assets/Ludiq/Bolt.Core/Editor/Generation/Generators/BoltClassGenerator.cs:100)
Ludiq.Bolt.ClassGeneration.GenerateDeclaration () (at Assets/Ludiq/Bolt.Core/Editor/Generation/Generations/ClassGeneration.cs:25)
Ludiq.Bolt.TypeGeneration`1[TDeclaration].Ludiq.Bolt.ITypeGeneration.GenerateDeclaration () (at Assets/Ludiq/Bolt.Core/Editor/Generation/Generations/TypeGeneration.cs:11)
Ludiq.Bolt.DocumentGenerator.Generate (Ludiq.Bolt.DocumentGeneration generation) (at Assets/Ludiq/Bolt.Core/Editor/Generation/Generators/DocumentGenerator.cs:64)
Ludiq.Bolt.DocumentGeneration.Generate () (at Assets/Ludiq/Bolt.Core/Editor/Generation/Generations/DocumentGeneration.cs:33)
Ludiq.Bolt.RootGeneration.Generate () (at Assets/Ludiq/Bolt.Core/Editor/Generation/Generations/RootGeneration.cs:106)
Ludiq.Bolt.RootGeneration.GenerateAndWrite (Ludiq.CodeDom.ICodeWriterSystem writerSystem) (at Assets/Ludiq/Bolt.Core/Editor/Generation/Generations/RootGeneration.cs:128)
Ludiq.Bolt.CodePreviewWindow.Generate () (at Assets/Ludiq/Bolt.Core/Editor/Generation/CodePreviewWindow.cs:442)
UnityEngine.Debug:LogException(Exception)
Ludiq.Bolt.CodePreviewWindow:OnFailureGUI() (at Assets/Ludiq/Bolt.Core/Editor/Generation/CodePreviewWindow.cs:409)
Ludiq.Bolt.CodePreviewWindow:_OnGUI() (at Assets/Ludiq/Bolt.Core/Editor/Generation/CodePreviewWindow.cs:304)
Ludiq.LudiqEditorWindow:OnGUI() (at Assets/Ludiq/Ludiq.Core/Editor/Windows/LudiqEditorWindow.cs:140)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

Bolt Version:
2.0.0a10
Unity Version:
2019.3.5f1
Platform(s):
Scripting Backend:
Mono
.NET Version (API Compatibility Level):
.NET 4.x
Bolt 2 GFI

also, I can't Build too

Adding a constructor did the trick for me

there won't be a problem to add a contructor on a Monobehavior?

I just checked, a constructor isn't required when you inherit from monobehaviour however your myCustomClass does not inherit from anything.

I have the issue with Class who inherit from monobehaviour too, and adding a constructor to myCustomClass don't solve the issue for me

+1

Back with more discoveries. I had reproduced the same problem you were having. It turns out that the constructor is not the fix. The problem is that is in the global namespace. Once I moved the class out of the global namespace the error was gone. No constructor required.

Thanks, it's working.
It's a good hotfix, but if we use a complex unity asset not using namespace, it could be a headache to fix it this way, so I leave this as a bug if something can be done with the global namespace in the future.

Anyway, thanks I may be able to build my prototype ^^

+1
Confirmed

Hi everyone, thanks for the report. Looks like an easy fix, will work on it for next version!