DataReader.GetFieldType returned null

Viewed 26803

In my db table Layout, there's one column whose type is hierarchyid (column index=4). When trying to set-up new environment (a virtual web-server, created from XEN server), then running the site, I've met with this issue:

Exception message: DataReader.GetFieldType(4) returned null. Exception data: System.Collections.ListDictionaryInternal

I've made some search and found out there are already some topic on it (such as on MSDN).

But even when I added the C:\Program Files\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SqlServer.Types.dll library, it seems like db type in structure SqlHierarchyId doesn't get recognized.

"Exception at DataReader.GetFieldType(4) returned null" is still thrown out.

Note: The issue will be solved if I made installation of C# package in VS2010 onto the environment (Windows Server 2008 RC2), but my boss didn't accept that, because this is purely a simple web-server.

7 Answers

For those experiencing this problem with PowerShell, I was able to fix my problem by installing the SQLSysClrTypes.msi package from Microsoft for SQL Server 2016 and restarting powershell. The download page is confusing to navigate, click "Download" and search the page for SQLSysClrTypes. Select the right architecture.

Exception calling "Fill" with "1" argument(s): "DataReader.GetFieldType(24) 
returned null."
At MyScript.ps1:15 char:5
+     $adapter.Fill($ds) | Out-Null
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], 
ParentContainsErrorRecordException
    + FullyQualifiedErrorId : InvalidOperationException

In my case, the offending data type was Microsoft.SqlServer.Types.SqlGeography in position (24) This field worked fine inside AppVeyor with SQL Server 2016 installed, but wouldn't run on my local environment.

I found several articles explaining why this occurs and some specified to use NuGet to fetch the latest Microsoft.SqlServer.Types.dll, but in my case, this didn't help, nor did any attempt to replace the assembly\GAC_... version with one from Install-Package and friends.

Note: Installing the .msi wasn't as straight forward as one would expect because through trial and error, I had installed several older "Microsoft SQL Server System CLR Types". This resulted in the MSI only offering "Repair" and "Remove". If this occurs, chose "Remove" and the run the installer again.

Installing the correct version and restarting PowerShell did the trick.

For me had to add 10.0.0.0__89845dcd8080cc91 folder inside it added the

Microsoft.SqlServer.Types.dll

for version 10

to C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.Types

Probably there's hidden dependency that uses GAC instead of the the project directory

Related