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


check if the locator object is of the type IAddressGeocoding before casting it to that interface.

If(locator is IAdressGeocoding)
   IAddressGeocoding addressGeocoding = (IAddressGeocoding)locator;
|improve this answer|||||
  • surprisingly enough it is... – patrick Sep 8 '10 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 Sep 8 '10 at 19:04
  • I checked its not out of scope, I'll keep that in mind tho, thanks – patrick Sep 8 '10 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.

|improve this answer|||||

My .loc file was corrupted

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.