title: Exception has been thrown by the target of an invocation - An attempt was made to load a program with an incorrect format. DbGeography
body: <p>Before I say anything - yes, I've read everything on this question so far, about building in X86/X64 modes and so on. I recently changed PC and have set up my environment again. The code is from a reporting service within a silverlight application. The silverlight application all builds fine and it has been publish ok as well. It just seems there are a few small errors somewhere within the reporting section that don't seem to want to play nice.</p>
  <pre><code>double Latitude = (double) parameters[&quot;GeofenceLatitude&quot;];
  double Longitude = (double) parameters[&quot;GeofenceLongitude&quot;];
  double Radius = (double) parameters[&quot;GeofenceRadius&quot;];
  DbGeography Geofence = GetPointFromLatLong(Latitude, Longitude);
  
  Geofence = Geofence.Buffer(Radius);
  </code></pre>
  <p>So everything works fine, the <code>GetPointFromLatLong</code> method (a custom one) returns a correct <code>DbGeography</code> object, however the <code>.Buffer(Radius)</code> causes an exception detailed below.</p>
  <blockquote>
  <p>InnerException = {&quot;An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)&quot;}</p>
  <p>Message = &quot;Exception has been thrown by the target of an invocation.&quot;</p>
  <p>Source = &quot;mscorlib&quot;</p>
  <p>StackTrace = &quot;at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) at System.Data.Entity.SqlServer.SqlSpatialServices.Buffer(DbGeography geographyValue, Double distance) at System.Data.Entity.Spatial.DbGeography.Buffer(Nullable distance) at GpsSilverlight.Web.Reports.ReportService.OnLoadData(IDictionary`2 parameters, String reportName, ReportSlot reportSlot) in PROJECT:line 1514&quot;</p>
  </blockquote>
  <p>I cannot figure out what's going on here. Does anyone have any experience with this?</p>
  <pre><code>static DbGeography GetPointFromLatLong(double Latitude, double Longitude)
      {
          DbGeography geogTest;
          geogTest = DbGeography.PointFromText(string.Format(&quot;POINT({1} {0})&quot;, Latitude.ToString(), Longitude.ToString()), 4326);
  
          return geogTest;
      }
  </code></pre>