0
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

1

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
3
  • surprisingly enough it is... Commented 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.. Commented Sep 8, 2010 at 19:04
  • I checked its not out of scope, I'll keep that in mind tho, thanks Commented Sep 8, 2010 at 19:10
1

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
1
1

My .loc file was corrupted

answered Sep 9, 2010 at 18:33

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.