The First Thing in an XML file needs to be…

I just discovered a fun tidbit of information. I was using NUnit to test a number of assemblies in a single project, and many functions need an app.config file. The instructions on how to do this can be found in various places, but I was having a problem that nobody else seemed to have.

My config file looked like this:

<!– config values for nunit –>
<?xml version=”1.0″ encoding=”utf-8″ ?>
       <add key=”…” value=”……” />

Every time NUnit started up that project, it would fail with an assembly load error:

System.IO.FileNotFoundException : File or assembly name nunit.core, or one of its dependencies, was not found.

For further information, use the Exception Details menu item.

My first thought to that was “Huh?!” It was a highly annoying problem, because I thought I was following the instructions exactly and it should have worked!

Do you see the problem? It’s this line:

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

It needs to be the first line in the file (or taken out completely). Voila, everything works.

Check out my latest book, the essential, in-depth guide to performance for all .NET developers:

Writing High-Performance.NET Code, 2nd Edition by Ben Watson. Available for pre-order:

1 thought on “The First Thing in an XML file needs to be…

  1. Jem

    in fact if there’s any rubbish at all in the config file, you’ll get System.IO.FileNotFoundException : File or assembly name nunit.core….

    I’d put the following in the config file (don’t ask why):

    valid xml, but rubbish from a config file point of view…

Leave a Reply

Your email address will not be published. Required fields are marked *