TypeLoadException

  • Thread starter Thread starter Scott Wisniewski
  • Start date Start date
S

Scott Wisniewski

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
 
Scott Wisniewski said:
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
 
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?
 
Back
Top