Casting Error

929
4
12-23-2013 04:56 AM
SanajyJadhav
Occasional Contributor II
Hello,

I am trying to cast from IFeatureClass to INetworkClass and I get the following error.

Unable to cast COM object of type 'System.__ComObject' to interface type 'ESRI.ArcGIS.Geodatabase.INetworkClass'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{EE2896B0-5ED8-11D2-AA8A-00C04FA37B82}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

I am using VB.Net in Visual Studio 2010 and ArcObjects SDK 10.2 on X64 Windows 7.

Below is my sample code.


Sub Test ( ByRef pFeatClass as IFeatureClass)

Dim pnF  as INetworkClass 
pnF  = pFeatClass

End Sub


In this simple code, i am getting the above mentioned exception.

I tried, CType,DirectCast also with option Strict Off, but no use.

Any help is much appreciated on this.

Regards,
Kiran.
0 Kudos
4 Replies
LeoDonahue
Occasional Contributor III
Checking the docs, I see that INetworkClass is a Subinterface of IFeatureClass. (at least in the Java docs).

What this means is, you don't need to cast it.

The only two implementing classes of the INetworkClass are:  FeatureClass and INetworkClassProxy
0 Kudos
SanajyJadhav
Occasional Contributor II
Thanks Leo for the reply.

I fixed the issue.

The reason for the failure was, the source IFeatureClass did not belong to the Geoemtric Network. It was a "NORMAL" feature class.  That's why, the cast was failing.When I used the feature class from the GN, it got casted to INetworkClass. So, my same code worked without any change.

Cheers,
Kiran.
0 Kudos
LeoDonahue
Occasional Contributor III
That is not what you posted originally. 

Your OP didn't mention you were using the GeometricNetwork.  You asked why casting between IFeatureClass and INetworkClass was giving you an error.

If you look at the documentation for GeometricNetwork, you can see all the implemented interfaces for that class.  If you want to go from GeometricNetwork to a FeatureClass, you need IDataset.
0 Kudos
SanajyJadhav
Occasional Contributor II
Leo,

I am sorry if there has been any misunderstanding, I never meant it.

Yes, I know I should have mentioned that I was using GemetricNetwork and it would had been more clearer.

Sorry once again.

Cheers,
Sanjay.
0 Kudos