NullReferenceException from CLI Generator

Posts   
 
    
yowl
User
Posts: 266
Joined: 11-Feb-2008
# Posted on: 17-Oct-2023 15:52:28   

Hi,

We have the CLi generator running in Azure Devops and most of the time it is fine, however sometimes we get this error

 LLBLGen Pro Command line code generator v5.10.0.0
 (c)2002-2023 Solutions Design bv. https://www.llblgen.com
 Generates code for LLBLGen Pro projects on the command line.
-----------------------------------------------------------------------
Initializing...
Initialization complete.
Loading project 'D:\a\1\s\src\TheHub.Entities.llblgenproj'

=====================
Exception caught.
=====================
Message: Object reference not set to an instance of an object.
Source: SD.LLBLGen.Pro.ApplicationCore
Stack trace:
   at SD.LLBLGen.Pro.ApplicationCore.Configuration.CoreState.GetModelValidator()
   at SD.LLBLGen.Pro.ApplicationCore.ProjectClasses.Project..ctor()
   at SD.LLBLGen.Pro.ApplicationCore.ProjectClasses.Project.Load(String filename, String additionalTypeConverterFolder)
   at SD.LLBLGen.Pro.Tools.CommandLineGenerator.Startup.StartProcess(CommandLineArgs parsedArgs)
   at SD.LLBLGen.Pro.Tools.CommandLineGenerator.Startup.Main(String[] args)

Could there be a race condition in there?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39617
Joined: 17-Aug-2003
# Posted on: 18-Oct-2023 10:07:39   

The project ctor instantiates the entity model validator, by calling CoreStateSingleton.GetInstance().GetModelValidator(). The GetInstance() returns the instance created by the static ctor on CoreStateSingleton (the CoreStateSingleton class contains a static member which is initialized by default, the static ctor in that class makes sure it's initialized before anything else).

So there's little else going on that this, it's not deferred to any thread, it's all executed on the main thread. Not sure what azure devops is doing tho...

Frans Bouma | Lead developer LLBLGen Pro
yowl
User
Posts: 266
Joined: 11-Feb-2008
# Posted on: 18-Oct-2023 16:06:35   

Thanks, I suppose it could be failing to verify the license, that looks like it would cause a NRE. Not sure what the CLI generator registers for messageReporterFunc, errorReporterFunc, or noLicenseFoundReporterFunc. Couldn't quickly find that code.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39617
Joined: 17-Aug-2003
# Posted on: 19-Oct-2023 09:35:01   

yowl wrote:

Thanks, I suppose it could be failing to verify the license, that looks like it would cause a NRE. Not sure what the CLI generator registers for messageReporterFunc, errorReporterFunc, or noLicenseFoundReporterFunc. Couldn't quickly find that code.

The stacktrace you posted fails on the line

internal void SetModelValidator()
{
    _modelValidator = CoreStateSingleton.GetInstance().GetModelValidator();
}

which to me leads to the conclusion the GetInstance() method returns null, but that's technically not possible, unless the current thread has no context of the static variables. GetInstance returns the instance set by the static ctor, so I don't see how that can fail.

Frans Bouma | Lead developer LLBLGen Pro
yowl
User
Posts: 266
Joined: 11-Feb-2008
# Posted on: 19-Oct-2023 12:01:01   

I believe it fails in GetModelValidator().

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39617
Joined: 17-Aug-2003
# Posted on: 20-Oct-2023 09:28:35   

Ah right, I misinterpreted the stacktrace (as the call is inlined, I thought it was that call). That function is indeed verifying the license info (or whether: if it is there), which should have been read when the CoreState is initialized, which is done in Startup.StartProcess in the cligenerator. Thing is: if the license wasn't there, it would already reported it there through the lambda it passed in and the output should have shown that no license file was found...

As the message isn't displayed in the text you quoted, the file therefore was found. However apparently it's not read properly, but that too is weird, as the license loader will verify the file if it's there. So in the case of the azure file system being 'temporarily unavailable' it will report on that, but everything was ok.

Frans Bouma | Lead developer LLBLGen Pro
yowl
User
Posts: 266
Joined: 11-Feb-2008
# Posted on: 25-Oct-2023 05:25:24   

Thanks, guess it's somewhere else. I've built the CLI generator in debug mode, but on reflection that probably isn't going to get me anywhere as the faulting module is SD.LLBLGen.Pro.ApplicationCore and I don't think there is a pdb for that?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39617
Joined: 17-Aug-2003
# Posted on: 25-Oct-2023 08:42:24   

I've attached a debug build with pdb for application core for 5.10

Attachments
Filename File size Added on Approval
ApplicationCore510.zip 1,354,406 25-Oct-2023 08:42.35 Approved
Frans Bouma | Lead developer LLBLGen Pro
yowl
User
Posts: 266
Joined: 11-Feb-2008
# Posted on: 25-Oct-2023 15:08:06   

Thank you! I will update if and when it happens again.

yowl
User
Posts: 266
Joined: 11-Feb-2008
# Posted on: 27-Oct-2023 21:49:32   

I now have a more informative stack trace, does it help narrow things down?

-----------------------------------------------------------------------
 LLBLGen Pro Command line code generator v0.0.0.0
 (c)2002-2023 Solutions Design bv. https://www.llblgen.com
 Generates code for LLBLGen Pro projects on the command line.
-----------------------------------------------------------------------
Initializing...
Initialization complete.
Loading project 'D:\a\1\s\src\TheHub.Entities.llblgenproj'

=====================
Exception caught.
=====================
Message: Object reference not set to an instance of an object.
Source: SD.LLBLGen.Pro.ApplicationCore
Stack trace:
   at SD.LLBLGen.Pro.ApplicationCore.Configuration.CoreState.GetModelValidator() in C:\MyProjects\VS.NET Projects\LLBLGen Pro v5.10\Designer\ApplicationCore\Configuration\CoreState.cs:line 519
   at SD.LLBLGen.Pro.ApplicationCore.EntityModel.EntityModelGraph.SetModelValidator() in C:\MyProjects\VS.NET Projects\LLBLGen Pro v5.10\Designer\ApplicationCore\EntityModel\EntityModelGraph.cs:line 1150
   at SD.LLBLGen.Pro.ApplicationCore.ProjectClasses.Project..ctor() in C:\MyProjects\VS.NET Projects\LLBLGen Pro v5.10\Designer\ApplicationCore\ProjectClasses\Project.cs:line 134
   at SD.LLBLGen.Pro.ApplicationCore.ProjectClasses.Project.Load(String filename, String additionalTypeConverterFolder) in C:\MyProjects\VS.NET Projects\LLBLGen Pro v5.10\Designer\ApplicationCore\ProjectClasses\Project.cs:line 168
   at SD.LLBLGen.Pro.ApplicationCore.ProjectClasses.Project.Load(String filename) in C:\MyProjects\VS.NET Projects\LLBLGen Pro v5.10\Designer\ApplicationCore\ProjectClasses\Project.cs:line 149
   at SD.LLBLGen.Pro.Tools.CommandLineGenerator.Startup.StartProcess(CommandLineArgs parsedArgs) in C:\Users\ScottWaye\Downloads\LLBLGen10.2\CLIGenerator\Startup.cs:line 152
   at SD.LLBLGen.Pro.Tools.CommandLineGenerator.Startup.Main(String[] args) in C:\Users\ScottWaye\Downloads\LLBLGen10.2\CLIGenerator\Startup.cs:line 92

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39617
Joined: 17-Aug-2003
# Posted on: 28-Oct-2023 09:53:59   

The LicenseInfo isn't loaded at that point, it's null.

switch(_loadedLicenseInfo.TypeOfLicense)

So your suspicion about the license is correct.

Frans Bouma | Lead developer LLBLGen Pro