StefanMaron / BusinessCentral.LinterCop

Community driven code linter for AL (MS Dynamics 365 Business Central)
https://stefanmaron.com
MIT License
68 stars 27 forks source link

Rule0032ClearCodeunitSingleInstance #523

Closed fvet closed 2 days ago

fvet commented 5 months ago

I'm facing below error with BCLinterCop v0.1.6 / Prerelease

Analyzer 'BusinessCentral.LinterCop.Design.Rule0032ClearCodeunitSingleInstance' threw an exception of type 'System.InvalidCastException' with message 'System.InvalidCastException: Unable to cast object of type 'System.String' to type 'System.Boolean'.\r\n at BusinessCentral.LinterCop.Design.Rule0032ClearCodeunitSingleInstance.IsSingleInstanceCodeunitWithGlobalVars(ICodeunitTypeSymbol codeunitTypeSymbol)\r\n at BusinessCentral.LinterCop.Design.Rule0032ClearCodeunitSingleInstance.HasSingleInstanceCodeunitWithGlobalVars(IEnumerable1 variables, ISymbol& codeunit)\r\n at BusinessCentral.LinterCop.Design.Rule0032ClearCodeunitSingleInstance.ClearAllCodeunit(OperationAnalysisContext ctx)\r\n at Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock(DiagnosticAnalyzer analyzer, Action analyze, Nullable1 info) in D:\\a\\_work\\1\\s\\source\\Prod\\Microsoft.Dynamics.Nav.CodeAnalysis\\DiagnosticAnalyzer\\AnalyzerExecutor.cs:line 1079

Arthurvdv commented 5 months ago

Can you easily create a repo or do I need to add a LC0000 here?

Arthurvdv commented 5 months ago

@fvet I've added an extra check, and now will raise the LC0000 diagnostic in the pre-release v0.30.14 version of the LinterCop.

Would be great if you could share a code snippet that causes this error.

fvet commented 5 months ago

Creating a repo is not possible, it's a 600+ objects project.

I tried again to open my project using the latest AL prerelease, but it's just full of random errors, so I switched back to the latest release instead some weeks ago.

image

image

...

Will keep an eye on it though and if I encounter similar errors, maybe the LC0000 diagnostic might provide better insights.

Arthurvdv commented 5 months ago

I tried again to open my project using the latest AL prerelease, but it's just full of random errors, so I switched back to the latest release instead some weeks ago.

I've added the LC0000 rule to the pre-release of the LinterCop. You can try with the normale (stable) release version of the AL Language (v12.6) combined with the pre-release version of the LinterCop?

image

Arthurvdv commented 4 months ago

@fvet Did you had a change to look a this?

This is an interesting case though. If I understand the error the LinterCop is reporting, it seems that you have a value set for the SingleInstance property on a codeunit what isn't a boolean 🤔

image

fvet commented 4 months ago

@Arthurvdv I'll reopen this issue when the error occurs again.

Arthurvdv commented 4 months ago

I've added temporary Try/Catch for this issue, specific for this issue, where I would like to implement a permanent solution for this.

With the new release yesterday, the regular release version of the LinterCop should now also raise a LC0000 diagnostic on this. Would be great if you could prove a small sample of recreating this issue (not sure if you still have this issue on one of your projects). Or can I now completely remove this Try/Catch piece of code?

Arthurvdv commented 4 months ago

@fvet Just checking in to see if you had a moment to look into finding an LC0000 diagnostic on this.

Arthurvdv commented 3 months ago

@fvet, I'm a curious about this one/ Any chance you can provide a small code snippet to reproduce this error?

Arthurvdv commented 2 days ago

The version v0.30.28 of the LinterCop is now the latest release.