What's wrong in my code?  If you can help?

979
4
Jump to solution
09-26-2013 08:14 AM
ShaningYu
Frequent Contributor
See my code below:
            // fc - a feature class w/ multiple feature records
            ESRI.ArcGIS.Location.RouteEventSourceClass rteEventSourceClass;
            rteEventSourceClass = fc as ESRI.ArcGIS.Location.RouteEventSourceClass;
But the value of the rteEventSourceClass is null.  Did I do something wrong?  I want to retrieve the rteEventSourceClass values.  Thanks.
0 Kudos
1 Solution

Accepted Solutions
ShaningYu
Frequent Contributor
The cast posted before was not correct.  In stead of
ESRI.ArcGIS.Location.IRouteEventSource rtEvtSourceClass;
rtEvtSourceClass = (ESRI.ArcGIS.Location.IRouteEventSource)fc;
It should be
IFeatureClass fc = (IFeatureClass)rtEvtSourceClass;
Thread is to be closed.

View solution in original post

0 Kudos
4 Replies
ShaningYu
Frequent Contributor
From the ArcObjects diagram (http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#//003100000138000000), it is known that the ESRI.ArcGIS.Location.RouteEventSourceClass is a sub-class of FeatureClass.  In this piece of code below:
            ESRI.ArcGIS.Location.RouteEventSourceClass rtEvtSourceClass = (ESRI.ArcGIS.Location.RouteEventSourceClass)fc;
            // fc - a feature class
Got InvalidCastException:  Unable to cast COM object of type 'System.__ComObject' to class type 'ESRI.ArcGIS.Location.RouteEventSourceClass'. COM components that enter the CLR and do not support IProvideClassInfo or that do not have any interop assembly registered will be wrapped in the __ComObject type. Instances of this type cannot be cast to any other class; however they can be cast to interfaces as long as the underlying COM component supports.
Why can't cast here?  Thanks.
0 Kudos
ShaningYu
Frequent Contributor
As the continuation of 2nd post of the thread, I followed the recommendation in the error message, used interface and then did the casting, like that:
            ESRI.ArcGIS.Location.IRouteEventSource rtEvtSourceClass;
            rtEvtSourceClass = (ESRI.ArcGIS.Location.IRouteEventSource)fc;
Then, got new error:  Unable to cast COM object of type 'System.__ComObject' to interface type 'ESRI.ArcGIS.Location.IRouteEventSource'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{641755F0-B7DE-11D3-9F7C-00C04F6BDF06}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
Then, I opened the Registry Editor to search the {641755F0-B7DE-11D3-9F7C-00C04F6BDF06}.  The result shows that it is at
Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Wow6432Node\Interface\.
For the 'No such interface supported ...', I referred to http://www.huggill.com/2012/09/06/solving-an-exception-occurred-in-publishing-no-such-interface-supp... provided procedure:
1. Run Command Prompt as Administrator
2. regsvr32 actxprxy.dll
3. Restart Visual Studio
The problem is still there and the error message is the same.  What I should do next?  Welcome your suggestion or hint.  Thanks.
0 Kudos
by Anonymous User
Not applicable
Make sure your reference to fc is also an interface rather than a class.

While .NET technically supports 'class casting', to ease the transition from VB6, you'll run into all sorts of problems with ArcObjects and COM interop.
0 Kudos
ShaningYu
Frequent Contributor
The cast posted before was not correct.  In stead of
ESRI.ArcGIS.Location.IRouteEventSource rtEvtSourceClass;
rtEvtSourceClass = (ESRI.ArcGIS.Location.IRouteEventSource)fc;
It should be
IFeatureClass fc = (IFeatureClass)rtEvtSourceClass;
Thread is to be closed.
0 Kudos