From 478bebd7af1ffdeb5d6058c5946549329d222aa7 Mon Sep 17 00:00:00 2001 From: Code Maze Date: Fri, 4 Dec 2026 18:27:46 +0100 Subject: [PATCH] Handle shoes with no image link in FirestoreService Shoes created before the image upload step are stored with an empty ImageUri, and new Uri(string.Empty) threw UriFormatException, so the Firestore index page failed with a 500. Shoe.ImageUri is now Uri?, an empty stored link maps to null, and a shoe with no link is stored with an empty string. Matches the current code in https://code-maze.com/dotnet-firebase/ --- dotnet-client-libraries/Firebase/Firebase/Models/Shoe.cs | 2 +- .../Firebase/Firebase/Services/FirestoreService.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dotnet-client-libraries/Firebase/Firebase/Models/Shoe.cs b/dotnet-client-libraries/Firebase/Firebase/Models/Shoe.cs index 3313456fab..8b85a63416 100644 --- a/dotnet-client-libraries/Firebase/Firebase/Models/Shoe.cs +++ b/dotnet-client-libraries/Firebase/Firebase/Models/Shoe.cs @@ -10,5 +10,5 @@ public class Shoe public required decimal Price { get; set; } - public Uri ImageUri { get; set; } = default!; + public Uri? ImageUri { get; set; } } diff --git a/dotnet-client-libraries/Firebase/Firebase/Services/FirestoreService.cs b/dotnet-client-libraries/Firebase/Firebase/Services/FirestoreService.cs index 1c7c5f7460..8e46eae4fd 100644 --- a/dotnet-client-libraries/Firebase/Firebase/Services/FirestoreService.cs +++ b/dotnet-client-libraries/Firebase/Firebase/Services/FirestoreService.cs @@ -42,7 +42,7 @@ private static Shoe ConvertDocumentToModel(ShoeDocument shoeDocument) Name = shoeDocument.Name, Brand = shoeDocument.Brand, Price = decimal.Parse(shoeDocument.Price), - ImageUri = new Uri(shoeDocument.ImageUri) + ImageUri = string.IsNullOrEmpty(shoeDocument.ImageUri) ? null : new Uri(shoeDocument.ImageUri) }; } @@ -54,7 +54,7 @@ private static ShoeDocument ConvertModelToDocument(Shoe shoe) Name = shoe.Name, Brand = shoe.Brand, Price = shoe.Price.ToString(), - ImageUri = shoe.ImageUri.ToString() + ImageUri = shoe.ImageUri?.ToString() ?? string.Empty }; } }