0

I'm trying to create a CoordinateTransformation to transform the SRS of a shapefile. However, on attempting to create one with the following method call:

var sourceSrs = new SpatialReference(Osr.SRS_WKT_WGS84);

I get the exception:

The type initializer for 'OSGeo.OSR.OsrPINVOKE' threw an exception.

The detailed exception looks like:

Exception

Can anyone help?

displayName
  • 13,888
  • 8
  • 60
  • 75
  • I've already put this question on [GIS SE](http://gis.stackexchange.com/q/198362/30966) as well. – displayName Jun 14 '16 at 15:08
  • That "bad image format" points to likely a difference in architecture -- something built for x86 trying to interact with something built for x64, for example. Much of that is probably hidden behind the P/Invoke calls that are internal to the library you're using. – Cᴏʀʏ Jun 14 '16 at 15:13
  • @Cᴏʀʏ: You are absolutely correct. So, I was running this code from a unit test. I set the 'Default Process Architecture' under Test Settings to x64. I still get this exception. Any other setting I need to change (which you can think of)? – displayName Jun 14 '16 at 15:19

1 Answers1

1

Forcing the project to build for target platform of x64 helps. You can do that by going to Project Properties (Shortcut: Alt + Enter) > Build > Platform Target.

Further, if you are running the code from some unit test, do the same for the Unit Testing project and change the "Default Process Architecture" to x64. The "Default Process Architecture" can be changed from the Test (in VS menu items) > Test Settings > Default Processor Architecture > x64.

displayName
  • 13,888
  • 8
  • 60
  • 75