# WatiN .NET 4.0 and the loadFromRemoteSources Element in App.config

**URL:** <https://www.ruby-forum.com/t/watin-net-4-0-and-the-loadfromremotesources-element-in-app-config/190496>\
**Category:** IronRuby\
**Created:** [June 21, 2010, 5:39pm UTC](https://www.ruby-forum.com/t/watin-net-4-0-and-the-loadfromremotesources-element-in-app-config/190496 "2010-06-21T17:39:35Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![metanoize](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9fc29f/32.png) [@metanoize](https://www.ruby-forum.com/u/metanoize)\
**Post date:** [June 21, 2010, 5:39pm UTC](https://www.ruby-forum.com/t/watin-net-4-0-and-the-loadfromremotesources-element-in-app-config/190496/1 "2010-06-21T17:39:35Z")

</div>

I am using .NET 4.0 with IronRuby to invoke some methods on WatiN  
framework  
2.0.10.928.

I keep getting the following error when loading the WatiN assemblies:

C:\Projects\IronRubyDemo\IronRubyDemoSolution\BusinessObjects\>ir -S spec  
testacc  
ountbalanceUI.rb  
C:/IronRuby/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:30:in  
`require': A n attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed in previous versions of the .NET Framework. This release of the .NET Framework does not enable CAS policy by default, so thi s load may be dangerous. If this load is not intended to sandbox the assembly, p lease enable the loadFromRemoteSources switch. See http://go.microsoft.com/fwlin k/?LinkId=155569 for more information. (LoadError) from C:/IronRuby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:30:in`require’

So, I went to the App.config file of my project and added the following  
lines:

\<?xml version="1.0" encoding="utf-8" ?\> 

I tried running it again and encountered the same problem. Any ideas!

---

<div class="post-metadata">

**Author:** ![metanoize](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9fc29f/32.png) [@metanoize](https://www.ruby-forum.com/u/metanoize)\
**Post date:** [June 21, 2010, 5:47pm UTC](https://www.ruby-forum.com/t/watin-net-4-0-and-the-loadfromremotesources-element-in-app-config/190496/2 "2010-06-21T17:47:12Z")

</div>

Your app is not the thing trying to load that assembly, IronRuby is. So,  
you’ll need to add that to IronRuby’s app.config.

That said, why are you trying to load an assembly from a network  
location in  
your tests? That is, IMO bad testing practice.

–  
Will G.  
[http://hotgazpacho.org/](http://hotgazpacho.org/)

---

<div class="post-metadata">

**Author:** ![metanoize](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9fc29f/32.png) [@metanoize](https://www.ruby-forum.com/u/metanoize)\
**Post date:** [June 21, 2010, 5:49pm UTC](https://www.ruby-forum.com/t/watin-net-4-0-and-the-loadfromremotesources-element-in-app-config/190496/3 "2010-06-21T17:49:20Z")

</div>

Will G. wrote:

> Your app is not the thing trying to load that assembly, IronRuby is. So,  
> you’ll need to add that to IronRuby’s app.config.
> 
> That said, why are you trying to load an assembly from a network  
> location in  
> your tests? That is, IMO bad testing practice.
> 
> –  
> Will G.  
> [http://hotgazpacho.org/](http://hotgazpacho.org/)

I am not sure what you mean by IronRuby app.config. Where is IronRuby  
app.config located? I guess it should be in the installed folder of  
IronRuby.

Also, I am just loading an assembly from my local machine.

---

<div class="post-metadata">

**Author:** ![metanoize](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9fc29f/32.png) [@metanoize](https://www.ruby-forum.com/u/metanoize)\
**Post date:** [June 21, 2010, 5:51pm UTC](https://www.ruby-forum.com/t/watin-net-4-0-and-the-loadfromremotesources-element-in-app-config/190496/4 "2010-06-21T17:51:45Z")

</div>

Thanks for the help! I edited the IronRuby configuration file and now  
the error has disappeared.

---

<div class="post-metadata">

**Author:** ![metanoize](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9fc29f/32.png) [@metanoize](https://www.ruby-forum.com/u/metanoize)\
**Post date:** [June 21, 2010, 5:57pm UTC](https://www.ruby-forum.com/t/watin-net-4-0-and-the-loadfromremotesources-element-in-app-config/190496/5 "2010-06-21T17:57:45Z")

</div>

## wherever you installed ironruby. it’s called ir.exe.config for me in C:\ironruby\bin

Met vriendelijke groeten - Best regards - Salutations  
Ivan Porto C.

---

<div class="post-metadata">

**Author:** ![metanoize](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9fc29f/32.png) [@metanoize](https://www.ruby-forum.com/u/metanoize)\
**Post date:** [June 21, 2010, 6:13pm UTC](https://www.ruby-forum.com/t/watin-net-4-0-and-the-loadfromremotesources-element-in-app-config/190496/6 "2010-06-21T18:13:41Z")

</div>

I created a new project in Visual Studio 2008 and tried running the same  
code and it worked without any problems. It did not gave me load error  
for the Interop.SHDocVw.dll.

Looks like there are some issues with WatiN when using it on .NET 4.0  
framework.

---

<div class="post-metadata">

**Author:** ![metanoize](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9fc29f/32.png) [@metanoize](https://www.ruby-forum.com/u/metanoize)\
**Post date:** [June 21, 2010, 6:20pm UTC](https://www.ruby-forum.com/t/watin-net-4-0-and-the-loadfromremotesources-element-in-app-config/190496/7 "2010-06-21T18:20:31Z")

</div>

Actually facing the same problem on VS 2008.

---

<div class="post-metadata">

**Author:** ![metanoize](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9fc29f/32.png) [@metanoize](https://www.ruby-forum.com/u/metanoize)\
**Post date:** [June 21, 2010, 6:06pm UTC](https://www.ruby-forum.com/t/watin-net-4-0-and-the-loadfromremotesources-element-in-app-config/190496/8 "2010-06-21T18:06:14Z")

</div>

Got the first problem solved by editing the configuration file. Now,  
facing problem loading the Interop.SHDocVw assembly. Here is the  
complete code:

require ‘rubygems’  
require ‘spec’

require File.dirname( **FILE** ) + ‘/bin/Debug/BusinessObjects.dll’  
require File.dirname( **FILE** ) + ‘/bin/Debug/WatiN.Core.dll’  
require File.dirname( **FILE** ) + ‘/bin/Debug/Microsoft.mshtml.dll’  
require File.dirname( **FILE** ) + ‘/bin/Debug/Interop.SHDocVw.dll’

include BusinessObjects  
include WatiN

describe Account, “when something happens” do

before do

IE = WatiN::Core::IE  
@ie = IE.new

end

it “should do something” do

end

end

And here is the error:

C:\Projects\IronRubyDemo\IronRubyDemoSolution\BusinessObjects\>ir -S spec  
testacc  
ountbalanceUI.rb  
F

1. 

Errno::ENOENT in ‘BusinessObjects::Account when something happens should  
do some  
thing’  
Could not load file or assembly ‘Interop.SHDocVw, Version=1.1.0.0,  
Culture=neutr  
al, PublicKeyToken=db7cfd3acb5ad44e’ or one of its dependencies. The  
system cann  
ot find the file specified.  
./testaccountbalanceUI.rb:18:

Finished in 0.148009 seconds

1 example, 1 failure

---

<div class="post-metadata">

**Author:** ![metanoize](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9fc29f/32.png) [@metanoize](https://www.ruby-forum.com/u/metanoize)\
**Post date:** [June 21, 2010, 6:38pm UTC](https://www.ruby-forum.com/t/watin-net-4-0-and-the-loadfromremotesources-element-in-app-config/190496/9 "2010-06-21T18:38:09Z")

</div>

instead of requiring the files with path. maybe try to set the load path

$:.unshift( File.dirname( **FILE** ) + “/bin/Debug”)  
require ‘BusinessObjects.dll’  
require ‘WatiN.Core.dll’  
require ‘Microsoft.mshtml.dll’  
require ‘Interop.SHDocVw.dll’

## I also think that the last 2 are redundant.. they should get picked up automatically by Watin.Core isn’t it

Met vriendelijke groeten - Best regards - Salutations  
Ivan Porto C.  
Web: [http://whiterabbitconsulting.eu](http://whiterabbitconsulting.eu) - [http://flanders.co.nz](http://flanders.co.nz)  
Twitter: [http://twitter.com/casualjim](http://twitter.com/casualjim)  
Author of IronRuby in Action ([IronRuby in Action - Ivan Porto Carrero and Adam Burmister | Manning](http://manning.com/carrero))  
Microsoft IronRuby/C# MVP

---

<div class="post-metadata">

**Author:** ![metanoize](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9fc29f/32.png) [@metanoize](https://www.ruby-forum.com/u/metanoize)\
**Post date:** [June 21, 2010, 6:54pm UTC](https://www.ruby-forum.com/t/watin-net-4-0-and-the-loadfromremotesources-element-in-app-config/190496/10 "2010-06-21T18:54:56Z")

</div>

Ivan Porto C. wrote:

> instead of requiring the files with path. maybe try to set the load path
> 
> $:.unshift( File.dirname( **FILE** ) + “/bin/Debug”)  
> require ‘BusinessObjects.dll’  
> require ‘WatiN.Core.dll’  
> require ‘Microsoft.mshtml.dll’  
> require ‘Interop.SHDocVw.dll’
> 
> ## I also think that the last 2 are redundant.. they should get picked up automatically by Watin.Core isn’t it
> 
> Met vriendelijke groeten - Best regards - Salutations  
> Ivan Porto C.  
> Web: [http://whiterabbitconsulting.eu](http://whiterabbitconsulting.eu) - [http://flanders.co.nz](http://flanders.co.nz)  
> Twitter: [http://twitter.com/casualjim](http://twitter.com/casualjim)  
> Author of IronRuby in Action ([IronRuby in Action - Ivan Porto Carrero and Adam Burmister | Manning](http://manning.com/carrero))  
> Microsoft IronRuby/C# MVP

You are right! It should be loaded automatically but for some reason it  
is not. Here is my IronRuby code:

require ‘rubygems’  
require ‘spec’

require File.dirname( **FILE** ) + ‘/bin/Debug/BusinessObjects.dll’  
require File.dirname( **FILE** ) + ‘/bin/Debug/WatiN.Core.dll’

include BusinessObjects  
include WatiN

describe Account, “when something happens” do

before do

IE = WatiN::Core::IE

i = IE.new()

end

it “should do something” do

end

end

And here is the error I get:

C:\Projects\TestingIronRuby\BusinessObjects\BusinessObjects\>ir -S spec  
testaccou  
ntbalanceUI.rb  
F

1. 

Errno::ENOENT in ‘BusinessObjects::Account when something happens should  
do some  
thing’  
Could not load file or assembly ‘Interop.SHDocVw, Version=1.1.0.0,  
Culture=neutr  
al, PublicKeyToken=db7cfd3acb5ad44e’ or one of its dependencies. The  
system cann  
ot find the file specified.  
./testaccountbalanceUI.rb:19:

Finished in 0.150009 seconds

1 example, 1 failure

---

<div class="post-metadata">

**Author:** ![metanoize](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9fc29f/32.png) [@metanoize](https://www.ruby-forum.com/u/metanoize)\
**Post date:** [June 21, 2010, 7:46pm UTC](https://www.ruby-forum.com/t/watin-net-4-0-and-the-loadfromremotesources-element-in-app-config/190496/11 "2010-06-21T19:46:04Z")

</div>

The load path basically determines where ir.exe looks for assemblies and  
files to load.

if you do

$LOAD\_PATH.unshift(File.dirname( **FILE** ) +"/bin/Debug")  
and then require Watin.Core.dll the CLR knows where to look for your  
DLL’s  
including the referenced assemblies

You might have gotten a correct result by including your assemblies in  
the  
inverted order too

So either you do :

$LOAD\_PATH.unshift(File.dirname( **FILE** ) +"/bin/Debug")  
require ‘BusinessObjects.dll’  
require ‘WatiN.Core.dll’

or this might work too:

require File.dirname( **FILE** ) +"/bin/Debug/Interop.SHDocVw.dll"  
require File.dirname( **FILE** ) +"/bin/Debug/Microsoft.mshtml.dll"  
require File.dirname( **FILE** ) +"/bin/Debug/BusinessObjects.dll"  
require File.dirname( **FILE** ) +"/bin/Debug/WatiN.Core.dll"

* * *

Met vriendelijke groeten - Best regards - Salutations  
Ivan Porto C.

---

<div class="post-metadata">

**Author:** ![metanoize](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9fc29f/32.png) [@metanoize](https://www.ruby-forum.com/u/metanoize)\
**Post date:** [June 21, 2010, 7:04pm UTC](https://www.ruby-forum.com/t/watin-net-4-0-and-the-loadfromremotesources-element-in-app-config/190496/12 "2010-06-21T19:04:31Z")

</div>

Ivan Porto C. wrote:

> instead of requiring the files with path. maybe try to set the load path
> 
> $:.unshift( File.dirname( **FILE** ) + “/bin/Debug”)  
> require ‘BusinessObjects.dll’  
> require ‘WatiN.Core.dll’  
> require ‘Microsoft.mshtml.dll’  
> require ‘Interop.SHDocVw.dll’
> 
> ## I also think that the last 2 are redundant.. they should get picked up automatically by Watin.Core isn’t it
> 
> Met vriendelijke groeten - Best regards - Salutations  
> Ivan Porto C.  
> Web: [http://whiterabbitconsulting.eu](http://whiterabbitconsulting.eu) - [http://flanders.co.nz](http://flanders.co.nz)  
> Twitter: [http://twitter.com/casualjim](http://twitter.com/casualjim)  
> Author of IronRuby in Action ([IronRuby in Action - Ivan Porto Carrero and Adam Burmister | Manning](http://manning.com/carrero))  
> Microsoft IronRuby/C# MVP

Hi Ivan,

I tried it without the path and it worked instantly. Why is it  
different? I mean why does it not work when I include the path and why  
does it work when I set the load path?
