I'm trying to use the .NET
assembly Microsoft.VisualBasic
in my boo code that
looks like this:
import System
import Regex from System.Text.RegularExpressions
import Interaction from Microsoft.VisualBasic
import Microsoft.VisualBasic
## import Reflection.Assembly
## path="""C:\Windows\winsxs\msil_microsoft.visualbasic_b03f5f7f11d50a3a_6.1.7100.0_none_29f6b89369881fe4\Microsoft.VisualBasic.dll"""
## f=Reflection.Assembly.Load(Reflection.Assembly.LoadFile(path).ToString())
## Interaction.Beep()
for i in Regex.Matches("def jam(this)","\\w+"):
print i
arr=array(range(10))
print List(arr)
Array.Reverse(arr)
print List(arr)
When using import Microsoft.VisualBasic
I get the error:
test.boo(9,1): BCE0005: Unknown identifier: 'Interaction'.
When using import Interaction from Microsoft.VisualBasic
:
test.boo(4,8): BCE0167: Namespace 'Interaction' not found in assembly 'Microsoft.VisualBasic'
It still doesn't work when I try to load the dll this way:
Reflection.Assembly.Load(Reflection.Assembly.LoadFile(path))
The thing is the above approach works in Powershell:
PS C:\mine> [reflection.assembly]::loadfile("C:\Windows\winsxs\msil_microsoft.visualbasic_b03f5f7f11d50a3a_6.1.7100.0_none_29f6b89369881fe4\Microsoft.VisualBasic.dll")
GAC Version Location
--- ------- --------
True v2.0.50727 C:\Windows\assembly\GAC_MSIL\Microsoft.VisualBasic\8.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualBasic.dll
PS C:\mine> [microsoft.visualbasic.interaction]::beep()
I could also use LoadWithPartialName
i.e [Reflection.Assembly]::loadwithPartialName('Microsoft.VisualBasic')
but it's deprecated.
How do I make this work?
I've found the solution, finally. Turns out the problem was the way I was compiling it. I was using
booc.exe test.boo
, instead of adding a reference toMicrosoft.VisualBasic
. You don't even need to load it usingReflection.Assembly
, you just import it, use it and compile withbooc.exe test.boo -r:Microsoft.VisualBasic.dll
. Supplying a full path to thedll
will also work. I guessPowershell
andboo
have different ways of accessing.NET
assemblies.