Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / March 2004

Tip: Looking for answers? Try searching our database.

TypeLoadException

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Scott Wisniewski - 02 Mar 2004 19:28 GMT
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
Donna Gresh - 03 Mar 2004 17:49 GMT
> 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
[quoted text clipped - 11 lines]
>
> 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
Scott Wisniewski - 03 Mar 2004 21:42 GMT
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?

> > 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
[quoted text clipped - 16 lines]
> declarations:
> http://www.winterdom.com/mcppfaq/archives/000262.html

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.