Eliminate all CS8618, CS0618, and ASP0019 compiler warnings #7048
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR eliminates all compiler and analyzer warnings mentioned in issue #7044 by implementing proper nullability annotations, replacing obsolete API calls, and using recommended header dictionary methods.
Changes Made
1. Fixed Non-nullable Property Warnings (CS8618)
File:
eFormAPI.Web/Infrastructure/Models/SelectableList/AdvEntitySelectableGroupEditModel.cs
Added the
required
modifier to three non-nullable string properties to ensure they are initialized at object creation:This leverages C# 11's required members feature, which is the recommended approach for ensuring non-nullable reference types are properly initialized while maintaining model binding compatibility.
2. Replaced Obsolete HTML Parser Method (CS0618)
File:
eFormAPI.Web/Services/WordProcessor.cs
Updated the
AddHtml
method to use the newerParseBody
API instead of the deprecatedParseHtml
:The
ParseBody
method provides better output clarification and is the recommended replacement for the obsoleteParseHtml
method.3. Fixed IHeaderDictionary Usage (ASP0019)
Files:
eFormAPI.Web/Controllers/Eforms/AudioController.cs
eFormAPI.Web/Hosting/Security/ClaimsTransformer.cs
Replaced
Headers.Add()
calls with indexer syntax to prevent potentialArgumentException
when adding duplicate keys:The indexer approach is safer as it sets or overwrites headers instead of throwing exceptions on duplicates.
Results
Fixes #7044
Original prompt
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.