At first I tried referencing your project through nuget but whatever I did, calling Fill on a DataTable always returned a null on the Geometry column, same for a DataReader with GetFieldType. I saw both of these issues here but you couldn't reproduce them, so I thought I would clone your whole repo to see what was going on. The bizarre thing is that it works perfectly in a Test Project, so I stripped the included test project all back to a single test with my code and it still worked, the identical code in my Console app fails as above. I assumed there was something funky with the way your test project was set up so I created a whole new test project, yet again I can debug into the test and it works, but not in the Console app. So, if I take your original solution and create 2 net6.0 projects, one a test and the other a console app, then simply add the project reference, I have 2 different behaviors. I can't explain it. Create a Console Application and add a Project reference to the main Microsoft.SqlServer.Types project and add the following code:
SqlConnection connection = new SqlConnection(".......<your connection string>...");
connection.Open();
string sql = "SELECT * FROM [schema].[table_with_geometry_column]";
SqlCommand command = new SqlCommand(sql, connection);
SqlDataAdapter adapter = new SqlDataAdapter(command);
DataTable dataTable = new DataTable();
adapter.Fill(dataTable);
connection.Close();
It will throw a "System.InvalidOperationException: 'DataReader.GetFieldType(3) returned null."
Error on the call to Fill, where 3 is the ordinal of my geometry column.
Run this exact same code in a TestMethod and it works as expected. Cannot for the life of me figure out what's happening???
At first I tried referencing your project through nuget but whatever I did, calling Fill on a DataTable always returned a null on the Geometry column, same for a DataReader with GetFieldType. I saw both of these issues here but you couldn't reproduce them, so I thought I would clone your whole repo to see what was going on. The bizarre thing is that it works perfectly in a Test Project, so I stripped the included test project all back to a single test with my code and it still worked, the identical code in my Console app fails as above. I assumed there was something funky with the way your test project was set up so I created a whole new test project, yet again I can debug into the test and it works, but not in the Console app. So, if I take your original solution and create 2 net6.0 projects, one a test and the other a console app, then simply add the project reference, I have 2 different behaviors. I can't explain it. Create a Console Application and add a Project reference to the main Microsoft.SqlServer.Types project and add the following code:
It will throw a "System.InvalidOperationException: 'DataReader.GetFieldType(3) returned null."
Error on the call to Fill, where 3 is the ordinal of my geometry column.
Run this exact same code in a TestMethod and it works as expected. Cannot for the life of me figure out what's happening???