Question

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?

Was it helpful?

Solution

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 to Microsoft.VisualBasic. You don't even need to load it using Reflection.Assembly, you just import it, use it and compile with booc.exe test.boo -r:Microsoft.VisualBasic.dll. Supplying a full path to the dll will also work. I guess Powershell and boo have different ways of accessing .NET assemblies.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top