question

JamesJ-9502 avatar image
0 Votes"
JamesJ-9502 asked cooldadtx answered

Getting compilation issue in VS 2019 v16.10.3

Hi,

We are getting compilation issue after freshly installs VS 2019 v16.10.3. The below code analysis error is not appearing in VS 2019 v16.8 or v16.9 during the compilation time. Is the CA treated as error in VS 2019 v16.10.x? If yes then share more details related to this.

error CA2004: Microsoft.Reliability : 'RefLambdaFunctionRunner<int>::RefLambdaFunctionRunner<int>(function<int __cdecl(void)>*)' contains one or more calls to GC.KeepAlive(object) that should be removed (after converting to SafeHandle to encapsulate the unmanaged resource).

Thanks,
James J

vs-generalvs-msbuild
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

cooldadtx avatar image
0 Votes"
cooldadtx answered

CA rules are only errors if you have configured your analyzers as such, in general. At least I'm not aware of any that will generate errors by default.

Analyzer rules can be configured in .editorconfig or the project file. Check your configuration settings to see if you have enabled this as an error and change to warning/suggestion/disabled as desired. Alternatively expand your Dependencies/Analyzers node in Solution Explorer and find the CA rule, right click and set the severity.

As for what the analyzer is saying that is documented here. As mentioned it is possible that this is a false positive so you can disable it in code if it isn't applicable here. Specifically it is saying that your RefLambdaFunctionRunner constructor is making a call to GC.KeepAlive. It should ideally instead use a SafeHandle. Again, if that isn't applicable to your type then use a pragma to disable the warning for this type.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.