1

I am trying to do a sample of Uno Platform using gRPC-Web.

Therefore I got inspired by the content provided by this article. I followed the instructions of the article and created a BlazorApp which used a weather service with gRPC-Web. After that I also included an other service, the counter service, as seen in this gRPC-Web example.

After everthing was working, I added a Uno Platform WebAssembly app to replace the BlazorApp client.

Current Problem:

When trying to create a GrpcChannel the application gets a System.NullReferenceException.

The code snippet for creating the channel looks like this:

var baseUri = "https://localhost:44366";
var channel = GrpcChannel.ForAddress(baseUri, new GrpcChannelOptions());

This is exactly the same code as used in the BlazorApp.

The sample code for the BlazorApp and the Uno Platform WebAssembly can be found in this repository.

Any idea/suggestion/help would be appreciated.

Tom
  • 100
  • 1
  • 9
  • 2
    I'm sorry @enigmativity, but did you properly read the question before closing it? This is a very legitimate question, for which the answer is completely appropriate. A nullreference in the question title does not necessarily mean that people want to know about null references... – Jérôme Laban Jun 13 '22 at 03:15
  • @JérômeLaban - It seems like solving for the `NullReferenceException` would help here. Can you tell me how you would determine when the duplicate is appropriate or not? – Enigmativity Jun 13 '22 at 03:50
  • 1
    The already provided answer gives what's needed to understand the issue here. Are you closing it because you did not find all the relevant context in the question itself? – Jérôme Laban Jun 13 '22 at 04:13
  • @JérômeLaban - I'm not asking about this specific question. I'm asking how you would determine when the `NullReferenceException` duplicate is appropriate or not? What rule should I apply in my help to know if it's a duplicate or not? The question, as I read it, is that the OP is getting a `NullReferenceException` and the duplicate is about dealing with such an exception. – Enigmativity Jun 13 '22 at 04:31
  • 1
    By reading the question, and trying what the OP is asking about. If you're not in position to determine whether the `NullReferenceException` is the cause or a side-effect (which was the case here), you should not be closing it as duplicate. A simple comment about "have you tried looking at this nullreference question" would have helped. – Jérôme Laban Jun 13 '22 at 11:52
  • 1
    @Enigmativity, I'm the one providing the answer and your generic _NullReferenceException_ post can't help the problem provided by Tom here. The problem was the usage of a sync version of a method where the async version is required because of the environment. The Null stuff there is just the error message you'll get when this happen, it is not related to a NULL REF in the application code. – Carl de Billy Jun 13 '22 at 12:03

1 Answers1

5

Ok I analyzed your code and I found 4 problems in your code:

  1. You were using the Blazor IoC Container. Uno is not designed to use it out-of-the-box. There some ways to use a container, but there's more work to do. To fix this, I simply moved the gRPC service initialization into the MainPage.xaml.cs instead. That's not production quality, but it serves the purpose of demoing gRPC.
  2. You were calling the SYNC version of .IncrementCount(). This is not possible on WASM since it's not possible to block the main thread in WASM (actually, it's possible, but you need to use primitives hidden deep in JavaScript and it won't solve your problem anyway). That's why on Blazor you need to call .IncrementCountAsync(). The same requirements are present on WASM.
  3. The XAML of your page were using a <Grid> without any rows, so each elements were drawn one over the other. I replaced it with a <StackPanel> to have a better result.
  4. Is was required to activate CORS on the server because the host name + port is slightly different.

I published a working version on a Fork I did of your project IT WORKS!!

Carl de Billy
  • 941
  • 6
  • 13