Skip to content

Set CLSCompliant attribute where possible#705

Merged
baywet merged 3 commits into
microsoft:mainfrom
WolfgangHG:clscompliant
May 5, 2026
Merged

Set CLSCompliant attribute where possible#705
baywet merged 3 commits into
microsoft:mainfrom
WolfgangHG:clscompliant

Conversation

@WolfgangHG

Copy link
Copy Markdown
Contributor

We set "CLSCompliant" it to "true" in our projects because our application provides a VB.NET based scripting, and thus all libraries that could be accessed by the VB.NET code should be CLSCompliant (e.g. to avoid the situation "protected member variable and property for this variable with same name, only differing in casing").
After having added the first Kiota generated REST client, I had to disable the "not CLSCompliant" warnings for this client with a ".editorconfig" file.

This pull request tries to make Kiota CLSCompliant.

It is not possible for the project "Microsoft.Kiota.Authentication.Azure" because it has public api using classes from Azure.Core that is also not CLSCompliant. That's why I set the attribute per project.

Only problem:
IParseNode defines a propery of type "sbyte" that is not CLSCompliant:

/// <summary>
/// Gets the sbyte value of the node.
/// </summary>
/// <returns>The sbyte value of the node.</returns>
sbyte? GetSbyteValue();

To my understanding, I can make the projects CLSCompliant anyway, and I just have to disable the warning for all code parts that are not CLS compliant.
This is done by setting [CLSCompliant(false)] where possible. Only the IParseNode interface requires a #pragma warning disable CS3002 because the attribute is not allowed on interface members.

In project "Microsoft.Kiota.Serialization.Json", there was a warning \obj\Debug\netstandard2.1\System.Text.Json.SourceGeneration\System.Text.Json.SourceGeneration.JsonSourceGenerator\MySerialKiotaJsonSerializationContext.SByte.g.cs(19,84,19,89): warning CS3003: Type of 'KiotaJsonSerializationContext.SByte' is not CLS-compliant. that was not suppressible with a ".editconfig" file - it does not accept paths in the "obj" directory.
I first created a roslyn issue (https://www.github.com/dotnet/roslyn/issues/83232), and the bot pointed me to a workaround (https://www.github.com/dotnet/roslyn/issues/47384#issuecomment-3529305512): add a ".globalconfig" file in the project that disables the warning:

dotnet_diagnostic.CS3003.severity = silent

This affects also generated files.

Then add a ".editorconfig" file that enabled the warning again:

[*.{cs}]
dotnet_diagnostic.CS3003.severity = warning

This file does NOT affect generated files, so the warning from them is still suppressed by ".globalconfig".

As there was also a suppression workaorund for "CS1591: Missing XML comment..." in "Microsoft.Kiota.Serialization.Json" that should probably also affect only generated files, I moved this suppression also to the new files.

Roslyn already contains a fix (https://www.github.com/dotnet/roslyn/pull/82224) so that you can specify suppressions for generated paths in ".editorconfig", but this fix does not seem to be released.

Hope my idea is acceptable ;-)

@WolfgangHG WolfgangHG requested a review from a team as a code owner April 22, 2026 19:40

@baywet baywet left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution!

Comment thread src/abstractions/serialization/IParseNode.cs
Comment thread src/serialization/json/.editorconfig
Comment thread src/serialization/json/.globalconfig
@github-project-automation github-project-automation Bot moved this to In Progress 🚧 in Kiota Apr 24, 2026
@baywet baywet enabled auto-merge (squash) April 24, 2026 15:23
@baywet baywet merged commit f6c21e4 into microsoft:main May 5, 2026
7 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress 🚧 to Done ✔️ in Kiota May 5, 2026
Copilot AI added a commit that referenced this pull request May 5, 2026
- Add CLSCompliant assembly attribute to abstractions and http projects
- Retain central package management (no explicit versions)
- Retain updated TFM conditions without net5.0
- Pick up CLSCompliant changes from main (fix: Set CLSCompliant attribute where possible #705)

Co-authored-by: MIchaelMainer <8527305+MIchaelMainer@users.noreply.github.com>
github-actions Bot pushed a commit to EelcoLos/nx-tinkering that referenced this pull request May 12, 2026
Updated
[Microsoft.Kiota.Abstractions](https://github.com/microsoft/kiota-dotnet)
from 1.22.0 to 1.22.2.

<details>
<summary>Release notes</summary>

_Sourced from [Microsoft.Kiota.Abstractions's
releases](https://github.com/microsoft/kiota-dotnet/releases)._

## 1.22.2

##
[1.22.2](microsoft/kiota-dotnet@v1.22.1...v1.22.2)
(2026-05-05)


### Bug Fixes

* Set CLSCompliant attribute where possible
([#​705](microsoft/kiota-dotnet#705))
([f6c21e4](microsoft/kiota-dotnet@f6c21e4))

## 1.22.1

##
[1.22.1](microsoft/kiota-dotnet@v1.22.0...v1.22.1)
(2026-03-19)


### Bug Fixes

* adds missing parentheses in pattern matching
([#​671](microsoft/kiota-dotnet#671))
([50d535e](microsoft/kiota-dotnet@50d535e))
* performance issue with enum parsing during deserialization
([#​670](microsoft/kiota-dotnet#670))
([3a09234](microsoft/kiota-dotnet@3a09234))

Commits viewable in [compare
view](microsoft/kiota-dotnet@v1.22.0...v1.22.2).
</details>

[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=Microsoft.Kiota.Abstractions&package-manager=nuget&previous-version=1.22.0&new-version=1.22.2)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Eelco Los <5102501+EelcoLos@users.noreply.github.com>
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

Successfully merging this pull request may close these issues.

3 participants