Problem using System.Xml in unit test in MonoDevelop (MonoTouch)
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=184.108.40.206, 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.
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:
There is one for system.xml.linq as well, and these are the proper versions you need (220.127.116.11)
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)