Hi All,
I'm trying to create a generic node class for generating class
hierarchies like XmlNode/XmlDocument. Unfortunately I'm running into an
interesting problem where my code compiles fine but causes a
System.TypeLoadException trying to load one of my classes.
I've created a small example that replicates the problem. If I compile
this sample using Visual C# 2005 Express Edition Beta1 then it generates
the following unhandled exception:
Unhandled Exception: System.TypeLoadException: Could not load type
'NodeApp.XmlDocument' from assembly 'NodeApp, Version=1.0.1909.20129,
Culture=neutral, PublicKeyToken=null'. at NodeApp.Program.Main(String[]
args)
namespace NodeApp
{
abstract public class Node<T, O>
where T : Node<T, O> where O : class
{
protected Node()
{
_owner = null;
_children = new List<T>();
}
public O Owner { get { return _owner; } }
public T Parent
{ get { return _parent; } set { _parent = value; } }
public void AddChild(T newChild)
{ _children.Add(newChild); newChild._owner = _owner; }
protected O _owner;
private T _parent;
private List<T> _children;
}
public class XmlNode : Node<XmlNode, XmlDocument> { }
public class XmlDocument : XmlNode
{
public XmlDocument() : base() { _owner = this; }
}
class Program
{
static void Main(string[] args)
{
// error occurs in the first line
XmlDocument doc = new XmlDocument();
XmlNode node = new XmlNode();
doc.AddChild(node);
}
}
}
If anyone has any ideas, then I'd be most grateful.
Regards,
Matt