Skip to content

TodoApp.Uno: nullable reference warnings in sample code (CS8618, CS8622) #535

Description

@adrianhall

Summary

Now that #525/#524 (PR #533) let TodoApp.Uno build on every head in CI, the following pre-existing nullable-reference-type warnings are visible on every head (android, ios-maccatalyst, windows, browserwasm, desktop):

App.xaml.cs(15,12): warning CS8618: Non-nullable field 'dbConnection' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Database/OfflineClientEntity.cs(16,19): warning CS8618: Non-nullable property 'Id' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Views/TodoListPage.xaml.cs(40,46): warning CS8622: Nullability of reference types in type of parameter 'sender' of 'void TodoListPage.PublishNotification(object sender, NotificationEventArgs args)' doesn't match the target delegate 'EventHandler<NotificationEventArgs>' (possibly because of nullability attributes).

CI run: https://github.com/CommunityToolkit/Datasync/actions/runs/29093946725 (all todoapp-uno / * jobs)

Root cause

Genuine, pre-existing nullable-reference-type gaps in the sample's own code, unrelated to the Uno Platform version or any change in PR #533:

  • App.xaml.cs: dbConnection field is declared non-nullable but never initialized in the constructor.
  • Database/OfflineClientEntity.cs: Id property is declared non-nullable but not set in the constructor / not marked required.
  • Views/TodoListPage.xaml.cs: PublishNotification(object sender, NotificationEventArgs args) has non-nullable sender/args parameters that don't match the nullable annotations on the standard EventHandler<NotificationEventArgs> delegate it's assigned to (via ViewModel.NotificationHandler += PublishNotification;).

Suggested fix

  • App.xaml.cs: add the required modifier to dbConnection, or initialize it, or declare it nullable if genuinely optional at construction time.
  • Database/OfflineClientEntity.cs: add required to the Id property (mirroring the fix pattern already used elsewhere in this codebase for the same warning class).
  • Views/TodoListPage.xaml.cs: change PublishNotification's signature to object? sender, NotificationEventArgs args (or whatever matches EventHandler<NotificationEventArgs>'s actual nullable annotations) to eliminate the delegate mismatch.

None of these require behavioral changes - just nullability annotation fixes.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions