Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.
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

share|improve this question
add comment

3 Answers

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

If(locator is IAdressGeocoding)
{
   IAddressGeocoding addressGeocoding = (IAddressGeocoding)locator;
}
share|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
add comment

With ArcEngine, you need to be sure to call IAoInitialize.Initialize when your app starts. Otherwise it throws exceptions in really strange places.

share|improve this answer
1  
furthermore, 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 Sep 9 '10 at 11:10
add comment
up vote 1 down vote accepted

My .loc file was corrupted

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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