Message 1 of 7
Inconsistent ComponentDefinition.Type and InvalidCastException

Not applicable
04-20-2016
11:56 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Here's my code.
occ = assemdoc.ComponentDefinition.Occurrences.Add(partFile, location);
bool isPartComponentDefinition = occ.Definition.Type == ObjectTypeEnum.kPartComponentDefinitionObject; // true
((PartComponentDefinition)occ.Definition).Parameters["BDiameter"]); // System.InvalidCastException
It's throwing InvalidCastException on (PartComponentDefinition)occ.Definition, even though occ.Definition.Type == ObjectTypeEnum.kPartComponentDefinitionObject.
Is this a bug? Or do I have to do something before the occurrence from Occurrences.Add becomes valid?