Skip to content
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

Null Ref exception when using Roslyn generator #534

Closed
eransh22 opened this issue Dec 27, 2017 · 6 comments
Closed

Null Ref exception when using Roslyn generator #534

eransh22 opened this issue Dec 27, 2017 · 6 comments

Comments

@eransh22
Copy link

eransh22 commented Dec 27, 2017

Hi,

We have found a bug which happens every time we generate code using Roslyn plugin.
The "doctor -v"command finish with this exception:

System.NullReferenceException: Object reference not set to an instance of an object.
   at Entitas.Roslyn.SymbolExtension.ToCompilableString(ISymbol symbol)
   at Entitas.Roslyn.CodeGeneration.Plugins.ContextsComponentDataProvider.GetContextNames(INamedTypeSymbol type)
   at Entitas.Roslyn.CodeGeneration.Plugins.ComponentDataProvider.hasContexts(INamedTypeSymbol type)
   at System.Linq.Enumerable.WhereArrayIterator`1.MoveNext()
   at System.Linq.Enumerable.<SelectManyIterator>d__16`2.MoveNext()
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at Entitas.Roslyn.CodeGeneration.Plugins.ComponentDataProvider.GetData()
   at DesperateDevs.CodeGeneration.CodeGenerator.CodeGenerator.generate(String messagePrefix, IPreProcessor[] preProcessors, IDataProvider[] dataProviders, ICodeGenerator[] codeGenerators, IPostProcessor[] postProcessors)
   at DesperateDevs.CodeGeneration.CodeGenerator.CodeGenerator.DryRun()
   at DesperateDevs.CodeGeneration.CodeGenerator.CLI.Doctor.run()
   at DesperateDevs.CodeGeneration.CodeGenerator.CLI.AbstractPreferencesCommand.Run(String[] args)

   at DesperateDevs.CLI.CLIProgram.runCommand(String[] args)


This is our preferences file:

CodeGenerator.SearchPaths = CodeGenerator/Plugins, \
                            CodeGenerator/Plugins/Entitas, \
                            CodeGenerator/Plugins/Entitas.Roslyn, \
                            CodeGenerator/Plugins/Jenny

CodeGenerator.Plugins = Entitas.CodeGeneration.Plugins, \
                        Entitas.VisualDebugging.CodeGeneration.Plugins, \
                        DesperateDevs.CodeGeneration.Plugins, \
                        Entitas.Roslyn.CodeGeneration.Plugins

CodeGenerator.DataProviders = Entitas.CodeGeneration.Plugins.ContextDataProvider, \
                              Entitas.Roslyn.CodeGeneration.Plugins.ComponentDataProvider, \
                              Entitas.Roslyn.CodeGeneration.Plugins.EntityIndexDataProvider

CodeGenerator.CodeGenerators = Entitas.CodeGeneration.Plugins.ComponentContextGenerator, \
                               Entitas.CodeGeneration.Plugins.ComponentEntityGenerator, \
                               Entitas.CodeGeneration.Plugins.ComponentEntityInterfaceGenerator, \
                               Entitas.CodeGeneration.Plugins.ComponentGenerator, \
                               Entitas.CodeGeneration.Plugins.ComponentMatcherGenerator, \
                               Entitas.CodeGeneration.Plugins.ComponentsLookupGenerator, \
                               Entitas.CodeGeneration.Plugins.ContextAttributeGenerator, \
                               Entitas.CodeGeneration.Plugins.ContextGenerator, \
                               Entitas.CodeGeneration.Plugins.ContextMatcherGenerator, \
                               Entitas.CodeGeneration.Plugins.ContextsGenerator, \
                               Entitas.CodeGeneration.Plugins.EntityGenerator, \
                               Entitas.CodeGeneration.Plugins.EntityIndexGenerator, \
                               Entitas.VisualDebugging.CodeGeneration.Plugins.ContextObserverGenerator, \
                               Entitas.VisualDebugging.CodeGeneration.Plugins.FeatureClassGenerator

CodeGenerator.PostProcessors = DesperateDevs.CodeGeneration.Plugins.AddFileHeaderPostProcessor, \
                               DesperateDevs.CodeGeneration.Plugins.CleanTargetDirectoryPostProcessor, \
                               DesperateDevs.CodeGeneration.Plugins.MergeFilesPostProcessor, \
                               DesperateDevs.CodeGeneration.Plugins.NewLinePostProcessor, \
                               DesperateDevs.CodeGeneration.Plugins.UpdateCSProjPostProcessor, \
                               DesperateDevs.CodeGeneration.Plugins.WriteToDiskPostProcessor, \
                               DesperateDevs.CodeGeneration.Plugins.ConsoleWriteLinePostProcessor

CodeGenerator.Server.Port = 3333
CodeGenerator.Client.Host = localhost
CodeGenerator.CLI.Ignore.UnusedKeys = 
DesperateDevs.CodeGeneration.Plugins.ProjectPath = Test.csproj
Entitas.CodeGeneration.Plugins.Contexts = Game, \
                                          Input

Entitas.CodeGeneration.Plugins.IgnoreNamespaces = true
DesperateDevs.CodeGeneration.Plugins.TargetDirectory = Assets/Scripts
CodeGenerator.PreProcessors = 

Cheers

@sschmid
Copy link
Owner

sschmid commented Dec 27, 2017

Ok I see, question: Do you have components with an context attribute like [MyContext] but the context has not been generated yet?

@eransh22
Copy link
Author

@sschmid Thank you for the quick answer 👍

Regarding your question, and after further investigation (we tried and succeeded reproducing it on a clean project), it seems that if you use the Roslyn plugin data providers for the very first code generation that you make - it will give you this exception, and therefor will not even generate the contexts themselves.. It seems like it needs the contexts to already be created before that.. but no code generation was done before that step. it's the very first time you try to generate..
However, if you use the normal plugin data providers for the first time - it will succeed in creating all contexts and then you can switch to Roslyn plugin and it will succeed in code generation every time afterwards, without the exception.

So I believe the question is then why it fails when using Roslyn for the first time code generation?

Thanks!

@sschmid
Copy link
Owner

sschmid commented Dec 28, 2017

@eransh22 great, that will help me a lot to find the issue. I will work on a fix for that. Thanks for the hints to reproduce

@jwvanderbeck
Copy link

I just ran into this as well and the cause was indeed trying to decorate a component with a context that hadn't yet been created. If it were not for this issue though I wouldn't have realized that was what I had done (It was a typo). Anyway to make the error more helpful?

@sschmid
Copy link
Owner

sschmid commented Dec 29, 2017

@eransh22 I just tried to reproduce, but unfortunately I cannot confirm. Generating the first time works great for me.

But: the next release contains a bugfix for the exception you posted, maybe your issue was related to that. I will release a new version soon, let's see if that solves your issue already.

@jwvanderbeck
The current version of the roslyn plugin can already handle resolving contexts that are not generated yet, given they are specified in the properties file.
Explanation:
Using an attribute that doesn't exist like [NonExistentAttribute] obviously cannot be resolved as I cannot infer if it is supposed to be an context attribute or something completely different. But: if the name between the braces (e.g. [NewContext]) matches any specified context in the properties file, I will just parse whatever text is found between the braces.

@sschmid
Copy link
Owner

sschmid commented Jan 10, 2018

Hi, there are some fixes in Entitas 0.47.0

@sschmid sschmid closed this as completed Jan 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

No branches or pull requests

3 participants