BusinessCentral.LinterCop icon indicating copy to clipboard operation
BusinessCentral.LinterCop copied to clipboard

Rule0032ClearCodeunitSingleInstance

Open fvet opened this issue 1 year ago • 9 comments

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

fvet avatar Jan 29 '24 12:01 fvet

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

Arthurvdv avatar Jan 29 '24 16:01 Arthurvdv

@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.

Arthurvdv avatar Feb 15 '24 16:02 Arthurvdv

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.

fvet avatar Feb 16 '24 14:02 fvet

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 avatar Feb 17 '24 11:02 Arthurvdv

@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

Arthurvdv avatar Feb 26 '24 14:02 Arthurvdv

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

fvet avatar Mar 05 '24 22:03 fvet

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 avatar Mar 06 '24 09:03 Arthurvdv

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

Arthurvdv avatar Mar 14 '24 11:03 Arthurvdv

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

Arthurvdv avatar Mar 30 '24 14:03 Arthurvdv

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

Arthurvdv avatar Jul 15 '24 07:07 Arthurvdv