473,320 Members | 2,088 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

I am attempting to write a class to expose the STL map class to .NET
languages as an IDictionary. As part of the implementation I created an
implementation of IEnumerator that contains a pointer to an iterator.
However any calls to the enumerators constructor result in a
TypeLoadException being thrown, stating that the type "std.iterator" can't
be found in the assembly.

Does anyone know:

1) What is causing this exception to be thrown?
2) Is there any way to get around it?

Thanks
Scott Wisniewski
Nov 17 '05 #1
2 2559
"Scott Wisniewski" <sc******@uwm.edu> wrote in message news:<eO**************@TK2MSFTNGP10.phx.gbl>...
I am attempting to write a class to expose the STL map class to .NET
languages as an IDictionary. As part of the implementation I created an
implementation of IEnumerator that contains a pointer to an iterator.
However any calls to the enumerators constructor result in a
TypeLoadException being thrown, stating that the type "std.iterator" can't
be found in the assembly.

Does anyone know:

1) What is causing this exception to be thrown?
2) Is there any way to get around it?

Thanks
Scott Wisniewski


I don't know if you have the same problem I did, but yesterday I
solved mine using the information given here regarding forward
declarations:
http://www.winterdom.com/mcppfaq/archives/000262.html
Nov 17 '05 #2
The problem is that I don't know exactly what to add a forward decleration
for.

The type that is giving the error is "std.iterator", which I assume is some
instantion of the std::iterator template, which serves as the base class for
the map classes iterator.

I tried placing a typedef in the stdafx.h file to instantiate the map
template with the paramters I use in my program like this

typedef System::Object * key_type;
typedef System::Object * data_type;
typedef ComparerPredicate< key_type > predicate_type;
typedef std::map<gcroot<key_type>, gcroot<key_type>, predicate_type>
container_type;
typedef container_type::iterator iterator_type;

however, the program still throws a TypeLoadException every time its run.

I have a class that looks like this in another file (with details removed
for clarity)....
public __gc class TreeDictionary : IDictionary_ {
public:
TreeDictionary() : pMap_(new container_type(predicate_type())){
}
//...
IDictionaryEnumerator * IDictionary::GetEnumerator() {
return new Enumerator(this);
}
private:
__gc class Enumerator_ : IDictionaryEnumerator_ {
public:
Enumerator_(TreeDictionary * dictionary) :
pDict_(dictionary),
pCur_(new iterator_type(dictionary->pMap_->begin()))
{
}
//...
private:
//..
iterator_type * pCur_;
TreeDictionary * pDict_;
};
//...
map_type * pMap_;
};

and comparer predicate defined as thus

class ComparerPredicate : public std::binary_function<T, T, bool> {
public:
ComparerPredicate() {
pComp_ = Comparer::Default;
}
ComparerPredicate(IComparer * pComp) : pComp_(pComp) {
}
bool operator()(const T& first, const T& second) const {
return pComp_->Compare(first, second) < 0;
}
private:
gcroot<IComparer *> pComp_;
};
Running new TreeDictionary() from a C# test driver works without any
problems.
However, when I try to do

TreeDictionary t = new TreeDictionary();

foreach (DictionaryEntry de in t) {
//blaaa...
}

I receive a TypeLoadException saying that std.iterator can't be loaded.

Why does the loader have a program with TreeDictionary::Enumerator_, but not
with TreeDictionary? Both have pointers to unmanged types, so I would think
that both would either or work, or not work.

Shouldn't instantiating map in the std.afx also instantiate map::iterator,
which should inturn instantiate std::iterator?

Why don't those template instantiatons create the necessary meta data?
"Donna Gresh" <gr***@us.ibm.com> wrote in message
news:aa**************************@posting.google.c om...
"Scott Wisniewski" <sc******@uwm.edu> wrote in message

news:<eO**************@TK2MSFTNGP10.phx.gbl>...
I am attempting to write a class to expose the STL map class to .NET
languages as an IDictionary. As part of the implementation I created an
implementation of IEnumerator that contains a pointer to an iterator.
However any calls to the enumerators constructor result in a
TypeLoadException being thrown, stating that the type "std.iterator" can't be found in the assembly.

Does anyone know:

1) What is causing this exception to be thrown?
2) Is there any way to get around it?

Thanks
Scott Wisniewski


I don't know if you have the same problem I did, but yesterday I
solved mine using the information given here regarding forward
declarations:
http://www.winterdom.com/mcppfaq/archives/000262.html

Nov 17 '05 #3

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

Similar topics

1
by: cody | last post by:
my problem is as follows: abstract class A { abstract Foo(); static Doit() { A = new B(); } }
0
by: daechulsohn | last post by:
Just thought I would contribute some knowledge for a change. After hours tracking down a problem with obfuscated code, where we were getting the exception : System.TypeLoadException: Method a...
0
by: Magnus Lindhe | last post by:
Hello, I'm trying to deserialize an XML document into a objects with the XmlSerializer which works fine in my NUnit test suit but fails with a TypeLoadException in the server. The difference...
1
by: DC | last post by:
Hi, I am programming a windows service and all went well until I needed to use a simple array of chars which I initialize like this: char test = new char {'\x002F', '\x005E'}; Immediatly...
1
by: @ndre | last post by:
Any type declaration of double leads to a TypeLoadException when run in cf (no compilation error), i.e. cf = reduced c# set??? see example below comments? @ndre this compiles with cf, but give...
0
by: Tintax | last post by:
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...
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...
1
by: :\\\\derian | last post by:
Hello All, I'm attempting to add a c# DLL that uses unmanaged code to my VB project. When I add the C# DLL to the project and compile, all goes well but when i hit F5, i get a...
0
by: Pierre-Alain Vigeant | last post by:
Hi, I'm getting a TypeLoadException inside an object that is located in a DLL that is dynamically loaded. I have this main program "main.exe" that dynamically load "main.dll" using o =...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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)...
1
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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.