Search code examples
c#asp.net-coregoogle-cloud-firestorewebassembly.net-8.0

Is it possible to use C# code to call Firestore database in .NET Web Assembly project?


I have just set up a new .NET 8 Web Assembly project and want to interact with a Firestore database. So I downloaded the official .NET library (https://www.nuget.org/packages/Google.Cloud.Firestore/ ) and got my Json credentials file.

Now whenever I try to initialize the database access, like so:

FirestoreDb firestoreDatabase = FirestoreDb.Create("myAppId", firestoreClientBuilder.Build());

I catch a System.PlatformNotSupportedException.

I thought it was because .NET 8 is not officialy released yet, so I created a WebAssembly .NET 7 project, got the same error, then .NET 6 for the same result. I tried with MAUI in .NET8 and it worked perfectly.

-> Is there another library I am missing to interact with Firestore with WASM, in C#, or is it simply impossible at the moment ? If so do you know about release plans ?


Solution

  • Sharing this as a community wiki for the benefit of others

    As mentioned by @Jon Skeet

    "I thought it was because .NET 8 is not officialy released yet" - no, it's because this isn't a supported platform - see cloud.google.com/dotnet/docs/reference/help/platforms for supported platforms. I don't know why you're explicitly building a FirestoreClient - I'd recommend just using FirestoreDbBuilder if you need anything custom. It's possible that this will mostly work if you set FirestoreDbBuilder.GrpcAdapter to RestGrpcAdapter.Default and have suitable credentials (e.g. a service account). But the Watch API certainly won't work.

    (Because it needs client-side streaming, which isn't supported in the REST adapter at the moment.) Even if it does partially work, this isn't a supported scenario (and may never be). I would personally recommend that instead you use the Firestore library in your server and talk to your server. (I'm assuming this is part of a web app or similar.)