You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With this setup, the view correctly prints the message.
From my understanding, I could remove the auto-inject of the View game object and use source generation. I followed the instructions above, but then I get this compilation error:
Assets\Test\View.cs(8,33): warning VCON0008: The [Inject] 'Service' does not have accessible to set from the same dll. It cannot support to inject by the source generator.
It's not really clear to me what this phrase means. Looking for this error in the source code I found this snippet:
Which seems to indicate that the following conditions must be met:
the property must have a setter
the setter must not be an init (maybe?)
and must have at least an "internal" level
That "init" part made me curious, so I changed the definition of the property from {get; set;} to {get; init;}, by adding the IsExternalInit which is missing according to Unity documentation, and at that point the source generator actually produced the code (even though the code seems to indicate the contrary), but then it obviously failed the compilation with the error VContainer.SourceGenerator\VContainer.SourceGenerator.VContainerIncrementalSourceGenerator\Test.ViewGeneratedInjector.g.cs(19,14): error CS8852: Init-only property or indexer 'View.Service' can only be assigned in an object initializer, or on 'this' or 'base' in an instance constructor or an 'init' accessor. because it needs a setter:
Hello,
I'm trying to use the Roslyn source generator approach on a Unity 6 project.
I've started from a minimal project that contains the following definitions:
Service.cs
View.cs
GameLifetimeScope.cs
And a simple hierarchy:
With this setup, the view correctly prints the message.
From my understanding, I could remove the auto-inject of the View game object and use source generation. I followed the instructions above, but then I get this compilation error:
It's not really clear to me what this phrase means. Looking for this error in the source code I found this snippet:
Which seems to indicate that the following conditions must be met:
That "init" part made me curious, so I changed the definition of the property from
{get; set;}
to{get; init;}
, by adding the IsExternalInit which is missing according to Unity documentation, and at that point the source generator actually produced the code (even though the code seems to indicate the contrary), but then it obviously failed the compilation with the errorVContainer.SourceGenerator\VContainer.SourceGenerator.VContainerIncrementalSourceGenerator\Test.ViewGeneratedInjector.g.cs(19,14): error CS8852: Init-only property or indexer 'View.Service' can only be assigned in an object initializer, or on 'this' or 'base' in an instance constructor or an 'init' accessor.
because it needs a setter:My suspect is that the IsInitOnly property is wrong in Unity 6, but I didn't dig any further in the code.
You can find my test project here: https://github.com/RedGlow/vcontainer-bug-report .
The text was updated successfully, but these errors were encountered: