tags:

views:

278

answers:

2

I am stumped. I have a solution with a couple projects. Among them a little side project that doesn't do very much more than doing some XML reading / writing. It is a C# project and I am using XDocument / XElement from the System.Xml.Linq namespace. The project is targetting .NET 3.5 framework.

Now, when I try to run it, I get this strange exception:

"$exception {System.Reflection.TargetInvocationException: Ein Aufrufziel hat einen Ausnahmefehler verursacht. ---> System.IO.FileNotFoundException: Die Datei oder Assembly System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 oder eine Abhängigkeit davon wurde nicht gefunden. Das System kann die angegebene Datei nicht finden."

I apologize that the message is in german; I'll give a translation of the core part: System.IO.FileNotFoundException: File or Assembly System.Xml.Linq, [...] not found. System cannot find the file.

The project references the System.Xml.Linq.dll residing in "%programfiles%\Reference Assemblies\Microsoft\Framework\v3.5". It exists and is registered in the GAC with corresponding version and public key token. When debugging, the exception occurs even before the tracer steps into the method in question, but after the code is compiled and I have run the project that calls the failing method.

The code is this:

public static SimpleTree<SankeyItem> XML2Tree(String xml)
{
    XDocument document = XDocument.Load(xml);
    SimpleTree<SankeyItem> tree = new SimpleTree<SankeyItem>();
    XElement element = document.Root;
    if (element.Name == "Node")
    {
        DoSomethingUseful(element)
    }
    else
    {
        throw new TreeParseException("Useful message here");
    }

    return tree; 
}

If I comment out all the XSomething code, it works. Please, I have no idea what could cause this issue. :( For completeness sake: The string "xml" is neither null not empty (the "real" code checks that).

Thank you in advance!

A: 

Are you sure your build target framework is not version 2.0?

Josh Stodola
Positive - it's .NET 3.5
ClearsTheScreen
+1  A: 

I had a similar type of problem once. All dependent assemblies according to my setup package were on the client machine. I used a tool from www.dependencywalker.com. That helped me find some Microsoft assembly that was needed. Built that the go into System32 in my project and never had the issue again.

Matt
I DLed that software and had a look at what it tells me about System.Xml.Linq.dll - it shows very much. I admit I don't really have much clue, except that there is quite an amount of DLLs involved of which only the fewest seem to be .NET assemblies. OTOH, only two of the (felt) hundreds of DLLs are reported missing. WER.DLL and IESHIMS.DLL - I suppose this doesn't count?Btw, this happenes on two independent windows machines.
ClearsTheScreen
Yeah I saw a lot in there too. I had to do some digging, but it did lead me to the issue eventually. I would have never found it otherwise.
Matt
The two missing files are these: IESHIMS.DLL - apparently responsible for some backwards compatibility stuff for IE8 in Vista and newerWER.DLL is a windows error reporting feature shipped with win Vista dn Server 2008. Since using System.Xml.Linq worked some time back on this very XP machine, I am tempted to say I do not need those DLLs.Those are the only ones reported missing. :|
ClearsTheScreen
dependency walker doesn't work with .NET assemblies, only with Win32 DLLs. And from what I've heard it is normal on the systems with IE8 to report missing IESHIMS.DLL
wRAR
Ah. I didn't expect it to be _that_ common to have the DLL missing. But thanks for the info about DW not working with .NET assemblies.
ClearsTheScreen