michielpost / Q42.HueApi

C# helper library to talk to the Philips Hue bridge
MIT License
412 stars 114 forks source link

.NET Core not not working #170

Closed Suplanus closed 5 years ago

Suplanus commented 5 years ago

Hi,

i created a simple .NET Core project. If i call HttpBridgeLocator.LocateBridgesAsync or LocalHueClient.RegisterAsync the program crashes without an exception.

Made a project here for you to reproduce the problem: https://github.com/Suplanus/Suplanus.MuteToHue/blob/594a45040750dba876182bc158f65450055ffe5b/src/Suplanus.MuteToHue/MuteToHue.cs#L24

I tried also to remove the locater code and set the ip address manually.

michielpost commented 5 years ago

Q42.HueApi works fine with .Net Core and is used in multiple .Net Core apps.

I had a look at your code and your static Main is not async. A lot of Q42.HueApi's are async, so you should await them. You are not awaiting the muteToHue.StartAsync() in Program.cs

This should help:

static async Task Main(string[] args)
    {
      Console.WriteLine("MuteToHue started");
      try
      {
        MuteToHue muteToHue = new MuteToHue();
        await muteToHue.StartAsync();
      }
      catch (Exception ex)
      {
        Console.WriteLine("Error: " + Environment.NewLine + ex);
      }
    }
Suplanus commented 5 years ago

🤦‍♂️ Sorry my fault.

Thanks for your help!