.NET Framework - Using assembly to load a non-cls compliant .net library intopowershell script

Asked By Rodion Raskolnikiv on 26-Apr-12 02:43 PM
I need to connect to RabbitMQ using Powershell. Using this recent blog post=
as a guide: http://devrants.blog.com/2012/02/29/rabbitmq-in-powershell/=20

This appears to be a basic example. However, when I run the code line by li=
ne in the console, I get an error saying:=20
Exception calling "Invoke" with "5" arguement(s): "None of the specified en=
dpoints were reachable=20

So I put $factory in the pipeline, and saw that:=20
format-default: the field/property: "Uri" for type: "RabbitMQ.Client.Connec=
tionFactory" differs only in case from the field/property: "uri". Failed to=
use non CLS compliant type.=20

This blog post addresses the issue of loading non-cls compliant .net librar=
ies into powershell:
http://www.nivot.org/post/2007/10/24/NonCLSCompliantTypesInPowerShell.aspx

So I fired up the console and tried:=20
[Reflection.Assembly]::LoadFile(($pwd).Path + =93\RabbitMq.Client.Dll=94)=
=20
$uri1 =3D [RabbitMQ.Client.ConnectionFactory].GetField("uri")=20
$uri2 =3D [RabbitMQ.Client.ConnectionFactory].GetField("Uri")=20
and both $uri1 and $uri2 are null-valued expressions!=20

This is pretty frustrating, I have the Dll file in my powershell working di=
rectory (next to the file that I have used to test this) as suggested in th=
e blog post, after calling [Reflection.Assembly]::LoadFile() to load the Ra=
bbitMQ dll there is information printed to the screen:=20
GAC      Version       Location=20
---      -------       --------=20
True     v2.0.50727     C:...(long path)\RabbitMQ.Client.dll=20


I do not have a background in ms programming and would very much appreciate =
a little guidance.=20
Many thanks in advance!




Rodion Raskolnikiv replied to Rodion Raskolnikiv on 26-Apr-12 04:12 PM
st as a guide: http://devrants.blog.com/2012/02/29/rabbitmq-in-powershell/=
=20
line in the console, I get an error saying:=20
endpoints were reachable=20
ectionFactory" differs only in case from the field/property: "uri". Failed =
to use non CLS compliant type.=20
aries into powershell:
x
=20
directory (next to the file that I have used to test this) as suggested in =
the blog post, after calling [Reflection.Assembly]::LoadFile() to load the =
RabbitMQ dll there is information printed to the screen:=20
e a little guidance.=20

So perhaps this is an ongoing issue with RabbitMQ: http://lists.rabbitmq.co=
m/pipermail/rabbitmq-discuss/2011-November/016313.html

I downloaded an older version (that appears to be CLS compliant), and it so=
lves the problem of loading the dll.