Skip to content

Conversation

@xingarr
Copy link

@xingarr xingarr commented Nov 10, 2025

Description

This PR improves code quality across the maui-samples repository by enhancing exception handling and adding defensive programming practices. The changes affect both 9.0 and 10.0 sample versions.

Changes Made

🔧 Exception Handling Improvements

  • Replaced generic catch (Exception) blocks with specific exception types
  • Added proper error logging with detailed diagnostic messages
  • Improved error context for better debugging experience

🛡️ Null Safety & Defensive Programming

  • Added null validation in TodoRepository methods (Insert, Update, Delete)
  • Added parameter validation to prevent ArgumentNullException
  • Improved error messages with specific exception details

📁 Files Modified (18 files total)

TodoREST API (4 files)

  • 10.0/WebServices/TodoREST/TodoAPI/Services/TodoRepository.cs
  • 10.0/WebServices/TodoREST/TodoAPI/Controllers/TodoItemsController.cs
  • 9.0/WebServices/TodoREST/TodoAPI/Services/TodoRepository.cs
  • 9.0/WebServices/TodoREST/TodoAPI/Controllers/TodoItemsController.cs

Employee Directory (2 files)

  • 10.0/Apps/EmployeeDirectory/EmployeeDirectory/Data/XmlFavoritesRepository.cs
  • 9.0/Apps/EmployeeDirectory/EmployeeDirectory/Data/XmlFavoritesRepository.cs

Xaminals Shell Sample (4 files)

  • 10.0/Fundamentals/Shell/Xaminals/Views/CatDetailPage.xaml.cs
  • 10.0/Fundamentals/Shell/Xaminals/Views/DogDetailPage.xaml.cs
  • 9.0/Fundamentals/Shell/Xaminals/Views/CatDetailPage.xaml.cs
  • 9.0/Fundamentals/Shell/Xaminals/Views/DogDetailPage.xaml.cs

WhatToEat App (6 files)

  • 10.0/Apps/WhatToEat/src/WhatToEat/ViewModels/RecipeDetailViewModel.cs
  • 10.0/Apps/WhatToEat/src/WhatToEat/ViewModels/SearchResultDetailViewModel.cs
  • 10.0/Apps/WhatToEat/src/WhatToEat/ViewModels/EditRecipeViewModel.cs
  • 9.0/Apps/WhatToEat/src/WhatToEat/ViewModels/RecipeDetailViewModel.cs
  • 9.0/Apps/WhatToEat/src/WhatToEat/ViewModels/SearchResultDetailViewModel.cs
  • 9.0/Apps/WhatToEat/src/WhatToEat/ViewModels/EditRecipeViewModel.cs

Benefits

  • Improved Reliability: Null checks prevent runtime crashes
  • Better Debugging: Specific exception types make issues easier to diagnose
  • Production Ready: Proper error handling with logging placeholders
  • Best Practices: Follows C# and .NET MAUI coding standards
  • Better Learning Resource: Sample code demonstrates proper exception handling patterns

Testing

  • All changes maintain backward compatibility
  • No breaking changes to public APIs
  • Code follows existing repository style guidelines

Related Issues

Addresses common code quality issues found in the repository including:

  • Generic exception catching without proper error context
  • Missing null checks leading to potential NullReferenceException
  • Inconsistent error logging practices

Checklist

  • Code follows the project's coding standards
  • Changes are applied to both 9.0 and 10.0 versions where applicable
  • No breaking changes introduced
  • Error messages are clear and helpful for debugging

Contribution by Gittensor, learn more at https://gittensor.io/

@xingarr
Copy link
Author

xingarr commented Nov 10, 2025

@dotnet-policy-service agree

@xingarr
Copy link
Author

xingarr commented Nov 10, 2025

@xingarr please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@dotnet-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@dotnet-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@dotnet-policy-service agree company="Microsoft"

Contributor License Agreement

@dotnet-policy-service agree

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant