System.Object obj = Activator.CreateInstance(Type.GetTypeFromProgID("esriLocation.LocatorManager"));
ILocatorManager2 locatorManager2 = obj as ILocatorManager2;
ILocatorWorkspace locatorWorkspace = locatorManager2.GetLocatorWorkspaceFromPath(@"Z:\ESRI\DataMaps10\streetmap_na");
locator = locatorWorkspace.GetLocator("Street_Addresses_US");
IAddressGeocoding addressGeocoding = (IAddressGeocoding)locator; //this fails
Inspecting the addressCoding object gives
'addressGeoCoding.matchFields' threw an exception of type Interop.COMException
asked Sep 8, 2010 at 17:03
3 Answers 3
check if the locator object is of the type IAddressGeocoding before casting it to that interface.
If(locator is IAdressGeocoding)
{
IAddressGeocoding addressGeocoding = (IAddressGeocoding)locator;
}
answered Sep 8, 2010 at 18:07
-
surprisingly enough it is...patrick– patrick2010年09月08日 18:47:55 +00:00Commented Sep 8, 2010 at 18:47
-
1@iterationx, Noticed that the locator is not declared in the code snippet, how is it declared? I had som issues with some objects that got garbaged collected, setting the variable as static or as a class variable solved that..MathiasWestin– MathiasWestin2010年09月08日 19:04:03 +00:00Commented Sep 8, 2010 at 19:04
-
I checked its not out of scope, I'll keep that in mind tho, thankspatrick– patrick2010年09月08日 19:10:37 +00:00Commented Sep 8, 2010 at 19:10
With ArcEngine, you need to be sure to call IAoInitialize.Initialize when your app starts. Otherwise it throws exceptions in really strange places.
answered Sep 9, 2010 at 2:10
-
1furthermore, at 10.0, you also need to Bind to a runtime before you call Initialize (there's a helper method to both at once) blogs.esri.com/Dev/blogs/arcgisdesktop/archive/2010/07/19/…bFlood– bFlood2010年09月09日 11:10:21 +00:00Commented Sep 9, 2010 at 11:10
My .loc file was corrupted
answered Sep 9, 2010 at 18:33