lwsrbrts / PoSHue

Windows PowerShell 5/PowerShell Core 6 Classes for controlling Philips Hue Bridge and Hue Lights, Groups, Sensors.
GNU Lesser General Public License v3.0
51 stars 7 forks source link

Add-Type required before class will work #2

Closed lwsrbrts closed 8 years ago

lwsrbrts commented 8 years ago

As a result of the recent introduction of RGBtoXYZ and the use of the [System.Drawing.Color] .NET type, the class will not parse unless the System.Drawing assembly is first loaded.

This means that any script loading the class must first do: Add-Type -AssemblyName System.Drawing

If you try to run a script/automation without the Add-Type declaration, the class refuses to parse since it can't fine the [System.Drawing.Color] type.

I can't add it to the .ps1 script - it just gives exactly the same error and doesn't load the type.

So, does anyone know how to overcome this in the best way?

lwsrbrts commented 8 years ago

So, it seems the only solution when I load my class is to force everyone to go to the trouble of typing

Add-Type -AssemblyName System.Drawing
Import-Module .\PoSHue.ps1

$Light = [HueLight]::new($Name, $IP, $APIKey)
...

That is not good and should not be necessary.

lwsrbrts commented 8 years ago

I've no idea why but this seems to now be working using a module manifest and RequiredAssemblies just like I tried before. The class now parses, loads etc. and I can control lights with it.

As a result, I've create a 1.0.0 release, updated the documentation and uploaded the class as a module to the PowerShell Gallery