Skip to content

.NET: Update analyzers for .NET 10 SDK - #2611

Merged
Stephen Toub (stephentoub) merged 1 commit into
microsoft:mainfrom
stephentoub:net10analyzers
Dec 10, 2025
Merged

.NET: Update analyzers for .NET 10 SDK#2611
Stephen Toub (stephentoub) merged 1 commit into
microsoft:mainfrom
stephentoub:net10analyzers

Conversation

@stephentoub

Copy link
Copy Markdown
Member

No description provided.

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the codebase to leverage .NET 10 SDK analyzers and modern C# language features. The changes primarily focus on adopting collection expressions, pattern matching enhancements, switch expressions, and performance improvements through logging guard clauses.

Key Changes:

  • Updated AnalysisLevel from latest/AllEnabledByDefault to 10.0-all for .NET 10 SDK compatibility
  • Modernized collection initialization syntax using collection expressions ([] instead of new List<T>(), Array.Empty<T>(), etc.)
  • Added logging guard clauses (IsEnabled checks) to prevent expensive logging argument evaluation when logging is disabled
  • Converted to modern pattern matching (is not (Type1 or Type2), switch expressions)

Reviewed changes

Copilot reviewed 41 out of 41 changed files in this pull request and generated 2 comments.

Show a summary per file
FileDescription
dotnet/Directory.Build.propsUpdated AnalysisLevel to target .NET 10 with all analyzers enabled
dotnet/tests/.editorconfigAdded suppressions for new .NET 10 analyzers in test projects (CA1822, CA1873, CA1875, CA2249)
dotnet/samples/.editorconfigAdded CA1873 suppression for sample projects
dotnet/src/Microsoft.Agents.AI/Memory/ChatHistoryMemoryProvider.csAdded logging guard clauses for performance optimization
dotnet/src/Microsoft.Agents.AI/Data/TextSearchProvider.csAdded logging guard clauses for performance optimization
dotnet/src/Microsoft.Agents.AI.Workflows/WorkflowBuilder.csConverted to collection expression syntax
dotnet/src/Microsoft.Agents.AI.Workflows/Execution/FanInEdgeState.csConverted to collection expression syntax
dotnet/src/Microsoft.Agents.AI.Workflows/Execution/EdgeConnection.csConverted to collection expression syntax
dotnet/src/Microsoft.Agents.AI.Workflows/Checkpointing/RepresentationExtensions.csConverted to collection expression syntax
dotnet/src/Microsoft.Agents.AI.Purview/ScopedContentProcessor.csConverted to switch expression and collection expression syntax
dotnet/src/Microsoft.Agents.AI.Purview/PurviewWrapper.csAdded logging guard clauses
dotnet/src/Microsoft.Agents.AI.Purview/PurviewClient.csAdded logging guard clauses and collection expression syntax
dotnet/src/Microsoft.Agents.AI.Purview/PurviewAppLocation.csConverted to switch expression
dotnet/src/Microsoft.Agents.AI.Purview/ChannelHandler.csAdded logging guard clauses
dotnet/src/Microsoft.Agents.AI.Purview/BackgroundJobRunner.csAdded logging guard clauses
dotnet/src/Microsoft.Agents.AI.Mem0/Mem0Provider.csAdded logging guard clauses
dotnet/src/Microsoft.Agents.AI.Mem0/Mem0Client.csConverted to collection expression syntax
dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/Responses/HostedAgentResponseExecutor.csAdded logging guard clauses
dotnet/src/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore/AGUIServerSentEventsResult.csRemoved unused StatusCode property
dotnet/src/Microsoft.Agents.AI.DurableTask/State/DurableAgentStateFunctionCallContent.csChanged from ToImmutableDictionary to ToDictionary
dotnet/src/Microsoft.Agents.AI.DurableTask/DurableAIAgent.csSimplified object initialization syntax
dotnet/src/Microsoft.Agents.AI.DevUI/DevUIMiddleware.csAdded logging guard clauses
dotnet/src/Microsoft.Agents.AI.CosmosNoSql/CosmosChatMessageStore.csUpdated to use JsonElement.Deserialize extension method
dotnet/src/Microsoft.Agents.AI.CopilotStudio/ActivityProcessor.csAdded logging guard clause
dotnet/src/Microsoft.Agents.AI.AGUI/AGUIChatClient.csAdded logging guard clauses
dotnet/src/Microsoft.Agents.AI.A2A/A2AAgent.csConverted to pattern matching with or
dotnet/samples/GettingStarted/AgentProviders/Agent_With_GoogleGemini/GeminiChatClient.csExtensive conversion to collection expression syntax
dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/TestEchoAgent.csConverted to collection expression syntax
dotnet/tests/Microsoft.Agents.AI.UnitTests/Memory/ChatHistoryMemoryProviderTests.csUpdated test assertion to use IsType with exactMatch parameter
dotnet/tests/Microsoft.Agents.AI.UnitTests/Data/TextSearchProviderTests.csConverted test data to collection expression syntax
dotnet/tests/Microsoft.Agents.AI.Purview.UnitTests/ScopedContentProcessorTests.csConverted test data to collection expression syntax
dotnet/tests/Microsoft.Agents.AI.Purview.UnitTests/PurviewClientTests.csConverted test data to collection expression syntax
dotnet/tests/Microsoft.Agents.AI.Mem0.UnitTests/Mem0ProviderTests.csConverted test data to collection expression syntax and updated assertions
dotnet/tests/Microsoft.Agents.AI.Mem0.IntegrationTests/Mem0ProviderTests.csConverted test data to collection expression syntax
dotnet/tests/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.UnitTests/AGUIServerSentEventsResultTests.csRemoved assertion for deleted StatusCode property
dotnet/tests/Microsoft.Agents.AI.CosmosNoSql.UnitTests/CosmosCheckpointStoreTests.csConverted to modern pattern matching syntax
dotnet/tests/Microsoft.Agents.AI.CosmosNoSql.UnitTests/CosmosChatMessageStoreTests.csConverted to collection expression syntax
dotnet/tests/Microsoft.Agents.AI.AzureAI.UnitTests/AzureAIProjectChatClientExtensionsTests.csSimplified MockPipelineResponse to use auto-property
dotnet/tests/Microsoft.Agents.AI.AGUI.UnitTests/AGUIChatClientTests.csConverted to collection spread expression
dotnet/tests/Microsoft.Agents.AI.A2A.UnitTests/Extensions/A2AArtifactExtensionsTests.csConverted to collection expression syntax
dotnet/tests/Microsoft.Agents.AI.A2A.UnitTests/A2AAgentTests.csConverted to pattern matching with or
Comments suppressed due to low confidence (1)

dotnet/src/Microsoft.Agents.AI.Mem0/Mem0Provider.cs:177

  • The nested IsEnabled check for LogLevel.Trace is redundant and creates a logic issue. Similar to the TextSearchProvider issue, this nests the Trace check inside the Information check, which means Trace logs will only be written if Information level is enabled. Since Trace is a more verbose level than Information, this should be a separate independent check. The checks should be:
if(this._logger?.IsEnabled(LogLevel.Information)istrue){this._logger.LogInformation(...);}if(outputMessageTextis not null&&this._logger?.IsEnabled(LogLevel.Trace)istrue){this._logger.LogTrace(...);}
 if (this._logger?.IsEnabled(LogLevel.Information) is true)
{
this._logger.LogInformation(
"Mem0AIContextProvider: Retrieved {Count} memories. ApplicationId: '{ApplicationId}', AgentId: '{AgentId}', ThreadId: '{ThreadId}', UserId: '{UserId}'.",
memories.Count,
this._searchScope.ApplicationId,
this._searchScope.AgentId,
this._searchScope.ThreadId,
this.SanitizeLogData(this._searchScope.UserId));
if (outputMessageText is not null && this._logger.IsEnabled(LogLevel.Trace))
{
this._logger.LogTrace(
"Mem0AIContextProvider: Search Results\nInput:{Input}\nOutput:{MessageText}\nApplicationId: '{ApplicationId}', AgentId: '{AgentId}', ThreadId: '{ThreadId}', UserId: '{UserId}'.",
this.SanitizeLogData(queryText),
this.SanitizeLogData(outputMessageText),
this._searchScope.ApplicationId,
this._searchScope.AgentId,
this._searchScope.ThreadId,
this.SanitizeLogData(this._searchScope.UserId));
}
}

Comment threaddotnet/src/Microsoft.Agents.AI/TextSearchProvider.cs
Aris Nguyen (arisng) pushed a commit to arisng/agent-framework that referenced this pull request Feb 2, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

.NETUsage: [Issues, PRs], Target: .NetworkflowsUsage: [Issues, PRs], Target: Workflows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@stephentoub@rogerbarreto@markwallace-microsoft