I'm a bit stuck on a delegate error in Unity. The code works fine if I'm in a c# console app however Unity is giving me the error:

Cannot convert lambda expression to type 'IObserver' because it is not a delegate type.

client.ReconnectionHappened.Subscribe(type =>
                Log.Information($"Reconnection happened, type: {type}, url: {client.Url}");

I tried updating to the latest Unity for the c# 8 support but that didn't appear to fix anything. I'm guessing it has something to do with .net compatibility and Unity. Do I need to create this delegate some other way to be compatible with unity?

I've been looking at the code here. Websockets Server for Unity3d

Using this for the client https://github.com/Marfusios/websocket-client


anonymous function is not the same as an object representing an anonymous function. you're trying to pass in anonymous function, but you need to wrap it in the object representing it and pass that one instead https://stackoverflow.com/a/23247231/1705376

  • 1
    \$\begingroup\$ This answer would be even better if it included a code example demonstrating how to do this, within the body itself rather than a link away. \$\endgroup\$ – DMGregory Mar 5 at 2:49
  • \$\begingroup\$ @DMGregory i disagree. firstly, I prefer normalization before duplication. Secondly, it would be warranted to also mark the question as duplicate with the same link i provided, but that felt... not nice. so I gave the answer while pointing out it's already been answered, nudging the asker to next time, search better before asking. I think that's a nice compromise of effects :) \$\endgroup\$ – sh code Mar 6 at 22:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.