# Re: InternalsVisibleTo

**URL:** <https://www.ruby-forum.com/t/re-internalsvisibleto/181705>\
**Category:** IronRuby\
**Created:** [January 16, 2010, 9:48am UTC](https://www.ruby-forum.com/t/re-internalsvisibleto/181705 "2010-01-16T09:48:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrew\_Wilson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/278dde/32.png) [@andrew\_Wilson](https://www.ruby-forum.com/u/andrew_Wilson)\
**Post date:** [January 16, 2010, 9:48am UTC](https://www.ruby-forum.com/t/re-internalsvisibleto/181705/1 "2010-01-16T09:48:58Z")

</div>

Jimmy,

So I decided to debug this out a bit for myself. Before I go too far,  
here  
is how my require headers are setup:

require ‘System.Xml.Linq, Version=3.5.0.0, Culture=neutral,  
PublicKeyToken=b77a5c561934e089’  
require ‘System.Data.DataSetExtensions, Version=3.5.0.0,  
Culture=neutral,  
PublicKeyToken=b77a5c561934e089’  
require ‘System.Data, Version=2.0.0.0, Culture=neutral,  
PublicKeyToken=b77a5c561934e089’  
require ‘System.Xml, Version=2.0.0.0, Culture=neutral,  
PublicKeyToken=b77a5c561934e089’  
require ‘System.Drawing, Version=2.0.0.0, Culture=neutral,  
PublicKeyToken=b03f5f7f11d50a3a’  
require ‘System.Windows.Forms, Version=2.0.0.0, Culture=neutral,  
PublicKeyToken=b77a5c561934e089’  
require  
‘C:\Users\pinvoke\Desktop\Rspec\_Project\_Runner\cmd\_parser\bin\Debug\CmdParser.dll’  
require  
‘C:\Users\pinvoke\Desktop\Rspec\_Project\_Runner\rspec\_project\_runner\bin\Debug\rspec\_project\_runner.exe’

Inside of my IronRuby specs, there is a call that, in ruby looks like  
this:

```
    rargs = ['-o', 'C:\Users\pinvoke']
    args = System::Array[System::String].new(rargs)
    p = Rspec::Project::Runner::ProgramArguments.Parse(args)

```

The call to assign the results of Parse to P always fails unless I

a) Do what Ivan suggested and copy to the bin folder  
b.) Modify ir.exe.config to include the path to the actual .dll

- 

I was reading the source code this evening and noticed that during the  
RubyContext buildup it only includes the following paths to resolve  
references:

context.Loader.GetLoadPathStrings()  
{string[4]}  
[0]: “F:/ironruby-ironruby-178b744/Merlin/Main/Languages/Ruby/libs/”  
[1]:  
“F:/ironruby-ironruby-178b744/Merlin/External.LCA\_RESTRICTED/Languages/Ruby/redist-libs/ruby/site\_ruby/1.8/”  
[2]:  
“F:/ironruby-ironruby-178b744/Merlin/External.LCA\_RESTRICTED/Languages/Ruby/redist-libs/ruby/1.8/”  
[3]: “.”

I assumed this is was why if I dump my .dll into any of those paths it  
resolves.

Then when I looked at the loaded files, everything looked like it loaded  
correctly:

```
[2]: "System.Xml.Linq, Version=3.5.0.0, Culture=neutral,

```

PublicKeyToken=b77a5c561934e089"  
[3]: “System.Data.DataSetExtensions, Version=3.5.0.0,  
Culture=neutral,  
PublicKeyToken=b77a5c561934e089”  
[4]: “System.Data, Version=2.0.0.0, Culture=neutral,  
PublicKeyToken=b77a5c561934e089”  
[5]: “System.Xml, Version=2.0.0.0, Culture=neutral,  
PublicKeyToken=b77a5c561934e089”  
[6]: “System.Drawing, Version=2.0.0.0, Culture=neutral,  
PublicKeyToken=b03f5f7f11d50a3a”  
[7]: “System.Windows.Forms, Version=2.0.0.0, Culture=neutral,  
PublicKeyToken=b77a5c561934e089”  
[8]:  
“C:\\Users\\pinvoke\\Desktop\\Rspec\_Project\_Runner\\cmd\_parser\\bin\\Debug\\CmdParser.dll”  
[9]:  
“C:\\Users\\pinvoke\\Desktop\\Rspec\_Project\_Runner\\Specs\\CmdParser\_spec\_helper.rb”  
[10]:  
“C:\\Users\\pinvoke\\Desktop\\Rspec\_Project\_Runner\\rspec\_project\_runner\\bin\\Debug\\rspec\_project\_runner.exe”  
[11]: “rspec\_project\_runner\_spec\_helper.rb”

Here is where it gets fun!

The problem appears to be in the way IronRuby is resolving assembly  
references from other already loaded assemblies. That is, if I make the  
above spec calls (rargs /args/ p) the application blows up w/o the  
CmdParser  
assembly in the path. The thing is that all the .Parse(args) method  
call is  
doing is a wrapper to call into another assembly… the one that blows  
up as  
not being found.

So, I decided to see what happened if I call the methods from the  
CmdParser  
assembly directly and… everything works fine. Regardless of which  
path  
the file is in 🙂

If I wasn’t so tired I would try and trace back how the resolve was  
working  
and why it wasn’t checking the loaded files… however I am exhausted  
and  
it’s way past my bed time.

If this helps, here is the Fusion Log that got dumped:

# === Pre-bind state information === LOG: User = veritas\pinvoke LOG: DisplayName = CmdParser, Version=1.5.0.0, Culture=neutral, PublicKeyToken=null (Fully-specified) LOG: Appbase = file:///F:/ironruby-ironruby-178b744/Merlin/Main/bin/Debug/ LOG: Initial PrivatePath = NULL Calling assembly : (Unknown).

LOG: This bind starts in default load context.  
LOG: Using application configuration file:  
F:\ironruby-ironruby-178b744\Merlin\Main\bin\Debug\ir.exe.Config  
LOG: Using machine configuration file from  
C:\Windows\Microsoft.NET\Framework\v2.0.50727\config\machine.config.  
LOG: Policy not being applied to reference at this time (private,  
custom,  
partial, or location-based assembly bind).  
LOG: The same bind was seen before, and was failed with hr = 0x80070002.

-Andrew

---

<div class="post-metadata">

**Author:** ![andrew\_Wilson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/278dde/32.png) [@andrew\_Wilson](https://www.ruby-forum.com/u/andrew_Wilson)\
**Post date:** [January 20, 2010, 9:57am UTC](https://www.ruby-forum.com/t/re-internalsvisibleto/181705/2 "2010-01-20T09:57:32Z")

</div>

> The call to assign the results of Parse to P always fails unless I
> 
> a) Do what Ivan suggested and copy to the bin folder  
> b.) Modify ir.exe.config to include the path to the actual .dll

I would suggest neither of these =P See below.

> I assumed this is was why if I dump my .dll into any of those paths it resolves.

Resolving DLLs should behave the same way as resolving Ruby libraries;  
it has to be on the load path. As you saw in the debugger, the load path  
is preset with the LibraryPaths value that is in the config, but it’s  
preferred to modify the load path by appending string to the $LOAD\_PATH  
(or $: shorthand) variable, rather than modifying the config file.

Consider the following directory structure:  
/dlls/foo.dll  
/bar.rb

Where foo.dll was compiled from this C# code:

public class Foo {  
public static void Bar() {  
System.Console.WriteLine(“In Bar”);  
}  
}

If foo.rb just looked like this:

require ‘foo.dll’  
Foo.bar

… and ir.exe is anywhere but the dlls directory you’d get this error:

PS C:\temp\> ir .\bar.rb  
:0:in `require’: no such file to load – foo (LoadError)  
from ./bar.rb:1

However, if you add “dlls” to the load path first:

$LOAD\_PATH \<\< File.dirname( **FILE** ) + “/dlls”  
require ‘foo.dll’  
Foo.bar

Then all will work:

PS C:\temp\> ir .\bar.rb  
In Bar

Notice that the first line “File.dirname( **FILE** )” to make the “dlls”  
path relative to the current file. Then doing “require ‘foo’” will look  
in the dlls directory.

Does that solve your problem?

~Jimmy
