Eliminate warnings from the solution build#670
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request eliminates compiler warnings from the solution build by addressing nullable reference type warnings and other compiler diagnostics. The changes include adding null-forgiving operators (!), initializing properties with default values, converting .Value to GetValueOrDefault(), removing duplicate using statements, and selectively suppressing specific warnings where appropriate.
Changes:
- Added null-forgiving operators throughout the codebase to handle nullable reference types
- Initialized properties with default values (
string.Empty,null!,[], etc.) to satisfy non-nullable requirements - Converted nullable DateTime
.Valueaccess toGetValueOrDefault()for safer null handling - Suppressed specific warnings (CS0649, CS0414, CS8669, CS9113, CS1998, CS8620, CS0067, CS8601) with documentation
- Removed duplicate using statements
- Fixed async/await patterns where methods were incorrectly marked async
Reviewed changes
Copilot reviewed 132 out of 132 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| Directory.Build.props | Added CS8669 warning suppression for Avalonia project |
| WalletOperations.cs | Added null-forgiving operators for coins collection |
| AssemblyInfoHelper.cs | Initialized string properties with empty defaults |
| SignService.cs | Added null-forgiving operators and converted to GetValueOrDefault() |
| RelaySubscriptionsHandling.cs | Added null-forgiving operators for event responses |
| RelayService.cs | Added null-forgiving operators for Nostr events and IDs |
| NostrCommunicationFactory.cs | Added null-forgiving operators for relay URLs |
| NetworkService.cs | Initialized event handler and changed nullable network declaration |
| MempoolSpaceIndexerApi.cs | Initialized properties with default values |
| IndexerService.cs | Added logger field with CS0649 suppression (obsolete class) |
| PsbtOperations.cs | Added null-forgiving operator for change address |
| InvestmentTransactionBuilder.cs | Changed nullable Script declaration |
| TaprootScriptBuilder.cs | Changed nullable Script declaration |
| InvestmentScriptBuilder.cs | Changed .Value to GetValueOrDefault() |
| Networks.cs | Added null-forgiving operator for null network returns |
| BitcoinSignet.cs, BitcoinMain.cs | Added null-forgiving operators for template lookups |
| Multiple model files | Initialized properties with default values (string.Empty, null!, []) |
| Multiple Avalonia UI files | Initialized properties and added null-forgiving operators |
| TransactionHistory.cs | Added CS9113 suppression for reserved logger parameter |
| FileStore.cs | Added CS1998 suppression (incorrectly documented) |
| Multiple SDK operations | Added CS9113 suppressions for DI-injected unused parameters |
| Multiple test files | Fixed type casting with explicit long conversions and null-forgiving operators |
| Various files | Removed duplicate using statements |
| public async Task<Result> Save<T>(string key, T data) | ||
| { | ||
| return from filePath in Result.Try(() => Path.Combine(appDataPath, key)) | ||
| from contents in Result.Try(() => JsonSerializer.Serialize(data, new JsonSerializerOptions { WriteIndented = true })) | ||
| select Result.Try(() => File.WriteAllTextAsync(filePath, contents)) | ||
| .Bind(Result.Success); | ||
| #pragma warning restore CS1998 |
There was a problem hiding this comment.
The File.WriteAllTextAsync method is called but not awaited on line 27. This means the method will return before the file write completes, which could lead to data loss or corruption. The method should either: 1) await the WriteAllTextAsync call and return its result, or 2) use the synchronous File.WriteAllText method. Also, the pragma warning comment is misleading - the async keyword is needed to match the interface signature and properly await async operations, not for "LINQ query expression type inference".
| nostrClient.Send(new NostrEventRequest(signed)); | ||
|
|
||
| return Task.FromResult(signed.Id); | ||
| return Task.FromResult(signed.Id)!; |
There was a problem hiding this comment.
Incorrect placement of null-forgiving operator. The null-forgiving operator should be on signed.Id rather than on Task.FromResult. Change Task.FromResult(signed.Id)! to Task.FromResult(signed.Id!). The same issue exists on line 264.
| nostrClient.Send(new NostrEventRequest(signed)); | ||
|
|
||
| return Task.FromResult(signed.Id); | ||
| return Task.FromResult(signed.Id)!; |
There was a problem hiding this comment.
Incorrect placement of null-forgiving operator. The null-forgiving operator should be on signed.Id rather than on Task.FromResult. Change Task.FromResult(signed.Id)! to Task.FromResult(signed.Id!). This is the same issue as on line 242.
| eventId!, | ||
| nostrEvent.Pubkey!, | ||
| nostrEvent.Content!, | ||
| nostrEvent.CreatedAt!.Value); |
There was a problem hiding this comment.
Inconsistent handling of nullable DateTime. This line uses CreatedAt!.Value while similar code throughout this file was changed to use GetValueOrDefault() (see lines 124, 160, 221, 256, 464). Consider changing this to nostrEvent.CreatedAt.GetValueOrDefault() for consistency and to handle null values safely.
| NostrEvent = nostrEvent!, | ||
| ProfileIdentifier = nostrEvent.Tags!.FindFirstTagValue(NostrEventTag.ProfileIdentifier) ?? string.Empty, | ||
| EventCreatedAt = nostrEvent.CreatedAt.GetValueOrDefault(), | ||
| EventIdentifier = nostrEvent.Tags.FindFirstTagValue(NostrEventTag.EventIdentifier) ?? string.Empty |
There was a problem hiding this comment.
Missing null-forgiving operator on nostrEvent.Tags. Line 463 uses nostrEvent.Tags!.FindFirstTagValue(...) but line 465 uses nostrEvent.Tags.FindFirstTagValue(...) without the null-forgiving operator. This is inconsistent and may cause a compiler warning.
|
|
||
| var secretHash = uint256.Parse("e1449d99d4861ff66a41e316d5605a37d79168a954b4f9cd0bb4656c7cd5dcfc"); | ||
| var investorKey = "03eb7d47c80390672435987b9a7ecaa22730cd9c4537fc8d257417fb058248ed77"; | ||
| //var investorKey = "03eb7d47c80390672435987b9a7ecaa22730cd9c4537fc8d257417fb058248ed77"; |
There was a problem hiding this comment.
Commented-out variable that appears to be unused. If this variable is truly not needed, consider removing it entirely rather than leaving it commented out. Dead code should be removed to keep the codebase clean.
| @@ -230,12 +232,12 @@ public async Task<string> GetTransactionHexByIdAsync(string transactionId) | |||
| return (true, blockHashElement.GetString()); | |||
| } | |||
|
|
|||
| _logger.LogWarning("blockHash not found in the block response."); | |||
| _logger!.LogWarning("blockHash not found in the block response."); | |||
| return (true, null); // Indexer is online, but no valid block hash | |||
| } | |||
| catch (Exception ex) | |||
| { | |||
| _logger.LogError(ex, $"Error during indexer network check: {ex.Message}"); | |||
| _logger!.LogError(ex, $"Error during indexer network check: {ex.Message}"); | |||
There was a problem hiding this comment.
Potential NullReferenceException. The _logger field is never assigned (it's not injected in the constructor) and is marked as nullable, but it's used with null-forgiving operators on lines 223, 235, and 240. This will throw a NullReferenceException at runtime. Since this class is marked as obsolete, consider either: 1) removing the logger calls entirely, 2) checking for null before using it, or 3) injecting it in the constructor.
|
I will submit a new PR that fixes warnings that are safe only |
No description provided.