473,320 Members | 1,948 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

TypeLoadException for Generic Type SubClass

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
Nov 17 '05 #1
0 1445

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: ryan groth | last post by:
Every three or four compiles I get a TypeLoadException everytime I run a web application on the same one or two dlls. The exception information is vauge, no file errors, no permission errors, no...
8
by: JAL | last post by:
Here is my first attempt at a deterministic collection using Generics, apologies for C#. I will try to convert to C++/cli. using System; using System.Collections.Generic; using System.Text; ...
25
by: Lars | last post by:
Hi, I have a base class holding a generic list that needs to be accessed by both the base class and its subclasses. What is the best solution to this? I am fairly new to generics, but I am...
2
by: AdawayNoSpam | last post by:
Said that I have the following class Class MyRootClass(Of T) End Class Class MySubClass1(Of T) Inherits MyRootClass(Of T) End Class
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.