Closed PhilipEve closed 7 months ago
Section "BlazorWorker.BackgroundService" reads in part as follows:
The public methods that you expose in your service can then be called from the IWorkerBackgroundService interface.
So you could argue that this is already mentioned. However, the qualifier "public" in this sentence is easily missed or dismissed. And if you make the mistake of trying to call an internal method rather than a public one, there's nothing to clue you in to what is wrong. The error message you get certainly isn't any help.
Hello, thank you for your feedback and interest in the project.
This error is not caught explicitly anywhere and I can't remember what causes it, probably a prerequisite of the Serialize.Linq library serialization.
There might be a bug here. At least a functional bug. Not the fact that we cannot serialize internal method calls, that is expected behavior. But I would like to see some kind of exception here that closes the message loop and it appears that the message loop breaks instead
I just spent an hour and a half trying to figure out why I wasn't able to call a particular method on my background service (my IWorkerBackgroundService) without getting an incomprehensible error message. The long and the short of it is that the method DoThing() in your code that looks like this:
... can't be an internal method. Why did I make it an internal method? Because I was incrementally adding more parameters as I made sure they (de)serialized correctly, and at some point I had a parameter that was an internal type, and when I got the "inconsistent visibility" error I made the method internal in order to resolve it.
If DoThing() is an internal method, then when you try to run it, you'll get a long error message the first few lines of which look like this:
To save other people the aggro I had, I'd like to suggest that this restriction should be mentioned somewhere in the documentation.