One of the identified items was in an invalid format - Microsoft.SqlServer.Type

Johann picture Johann · Aug 6, 2012 · Viewed 11.4k times · Source

I'm trying to retrieve geography data from my SQl Server 2012 DB with:

new SqlDataAdapter("SELECT [SpatialColumn] FROM [SpatialTable]", myConnection).Fill(myDatatable);

When the data is a Sql Server 2008 geography type such as Polygon, it's all working fine. But when the type is the new CurvePolygon then that line of code crashes with the error:

System.FormatException occurred
Message="One of the identified items was in an invalid format."
Source="Microsoft.SqlServer.Types"
StackTrace: at Microsoft.SqlServer.Types.GeoData.Read(BinaryReader r)

In this MSDN article, in the section called SQL CLR Data Types I have read that when you reference the SqlTypes assembly version 11.0, and version 10.0 is also installed, you may see a similar error. So I changed my Config file as explained. But it hasn't solved my issue.

Any idea greatly appreciated!

Answer

Razvan Dumitru picture Razvan Dumitru · Dec 30, 2016

You can try the following binding redirect:

 <assemblyBinding>   
      <!--....-->
     <dependentAssembly>
            <assemblyIdentity name="Microsoft.SqlServer.Types" publicKeyToken="89845dcd8080cc91" />
            <bindingRedirect oldVersion="10.0.0.0-11.0.0.0" newVersion="11.0.0.0" />
          </dependentAssembly>
        </assemblyBinding>

It looks like there is a problem with the loading assembly. More here: https://blog.devart.com/adventures-of-clr-types-in-net-framework.html