Hello all,
I want to iterate over all Itemtypes in a all Libraries but I get an Memory Exception in the second iteration in following Code:
try { ItemTypeLibraryPtr itemTypeLibrary = ItemTypeLibrary::FindByName(libName.c_str(), *ISessionMgr::GetActiveDgnFile()); for (ItemTypeLibrary::iterator iter = itemTypeLibrary->begin(); iter != itemTypeLibrary->end(); ++iter) { if (WString::IsNullOrEmpty(iter->GetName())) continue; auto name = iter-> GetName(); } } catch (...) { printf("Error\n"); }
The Exception appears when I try to retrieve the name or the internalName of the Item Type:
The Try - catch Block is not throwing aswell.
Am I using the iterator in wrong way or is there an alternative possibility to retrieve the Names of all Itemtypes in a library?
Thanks in advance
Manu
Hi Manuel Höger,
You will want to create to create your own list and push entries found into it, like this:
ItemTypeLibraryPtr lib = Bentley::DgnPlatform::ItemTypeLibrary::FindByName(libname, *dgnfile); list<WCharCP>* itemTypelist = new list<WCharCP>(); if (lib == nullptr) { return itemTypelist; } Bentley::DgnPlatform::ItemTypeLibrary::iterator i= lib->begin(); for (; i != lib->end (); i++) { itemTypelist->push_back(i->GetName()); } return itemTypelist;
HTH,Bob
Yes, thats the idea. Except that I use WStrings to copy the content of the WCharCP.
But the Error appears directly in the GetName() Method. The strange thing is that the error mostly appears at the second iteration. The first Name is extracted without problems.
Manuel Höger said:I want to iterate over all Itemtypes in a all LibrariesItemTypeLibrary::FindByName
ItemTypeLibrary::FindByName
Does that return a valid pointer? Test itemTypeLibrary.IsValid()
itemTypeLibrary.IsValid()
Regards, Jon Summers LA Solutions
Yes it does. I tried this before. And any other possibility of exception handling I know to get around this error.
It appears often at the second iteration. Means my library has two Itemtypes. The first Typename is resolved without problems and the second gives this error.
With very similar code I iterate through all libraries without a problem.
Maybe if you provide a sample dgn (instance) and dgnlib (definitions) as a test case, we can reproduce the issue, review and make recommendations with those details.
Bob
I didn't use a dgnlib. I directly created the Itemtypes in the Dgn with the MS Itemtype Dialog.
But the problem appears with Definitions in a dgn lib aswell. I tried it just now.
Your answer leads me to the suggestion that there haven't been any problems with the iterators right now and you couldn't reproduce it?
I will prepare a testcase example next week.
Thanks again
This is a reproducible issue. We have filed below bug:
BUG 1037870 : Exception occurred while iterating ItemType by using C++
For now, you can use below revised header file to replace your current one to overcome this bug.
https://communities.bentley.com/cfs-file/__key/communityserver-discussions-components-files/343173/CustomItemType.h
Just add one line as below shown: