views:

216

answers:

2

When I have a unit test that requires the System.Xml or System.Xml.Linq namespaces, I get the following error when I run the test:

System.IO.FileNotFoundException : Could not load file or assembly 'System.Xml.Linq, Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.

Things I've verified:

  • I have the proper usings in the test.
  • The project builds with no problems.
  • Using these namespaces work fine when I run the app in the emulator.
  • I've written a very simple unit test to prove that unit testing works at all (and it does).

I'm a test driven kinda guy so I can't wait to get this working so I can progress with my app.

Thanks in advance.

A: 

Probably Mono isn't finding the needed library in the places it looks. NUnit by default tries to copy your test library to some other place and so it won't find libraries that aren't globally visible (those system libraries installed in the GAC). Not sure if you can set in Monodevelop the option for NUnit not to copy the library under test to avoid the problem. One possibility is to run the standalone NUnit Console runner where you set the options or give NUnit more information to make it copy more things, but that is complicated by having to make NUnit use the right profile (Monotouch's which is based on Silverlight)

Monoman
+1  A: 

You need to add the same dll's (assemblies) that monotouch uses in the references of your unit test project.

These are found in /Developer/MonoTouch/usr/lib/mono//...

For example, i needed to use System.Xml, and so i edited the references of my test project and added the following assembly:

/Developer/MonoTouch/user/lib/mono/2.1/System.Xml.dll

There is one for system.xml.linq as well, and these are the proper versions you need (2.0.5.0)

leukosaima
I added the references the same way I did in the non-test project. Are you saying these assemblies are different and are required for the NUnit project? I'll give this a try this evening...
hambonious
That did it! Thanks Leuk. It seems like MonoDevelop would handle this properly for me. I guess I just need to understand the differences between Mono and MonoTouch better.
hambonious