runtime: GetColumnSchema not supported

Originally filed as https://github.com/aspnet/EntityFrameworkCore/issues/10686 by @dominicrooijackers Moved here since this is either an issue with ADO.NET or possibly with the way the third-party EntityFrameworkExtras uses ADO.NET, but is not an issue with EF Core itself.

Overnight out .NET core 1.1.0 application broke on our development server. The application still works fine while running it from visual studio 2015

The error that I’m getting is An unhandled exception occurred while processing the request. NotSupportedException: Specified method is not supported. System.Data.Common.DbDataReaderExtensions.GetColumnSchema(DbDataReader reader)

Stacktrace as follows:

System.Data.Common.DbDataReaderExtensions.GetColumnSchema(DbDataReader reader) EntityFrameworkExtras.EFCore.DatabaseExtensions.GetModelFromQuery<T>(DatabaseFacade databaseFacade, string sql, Object[] parameters) in DatabaseExtensions.cs EntityFrameworkExtras.EFCore.DatabaseExtensions.ExecuteStoredProcedure<T>(DatabaseFacade database, object storedProcedure) in DatabaseExtensions.cs DocumentPortal.Components.FolderViewComponent+<>c__DisplayClass3_0.<GetFolderContentAsync>b__0() in FolderViewComponent.cs System.Threading.Tasks.Task.InnerInvoke() System.Threading.Tasks.Task.Execute() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) System.Runtime.CompilerServices.TaskAwaiter.GetResult() DocumentPortal.Components.FolderViewComponent+<InvokeAsync>d__2.MoveNext() in FolderViewComponent.cs System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) Microsoft.AspNetCore.Mvc.ViewComponents.DefaultViewComponentInvoker+<InvokeAsyncCore>d__6.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) Microsoft.AspNetCore.Mvc.ViewComponents.DefaultViewComponentInvoker+<InvokeAsync>d__5.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) Microsoft.AspNetCore.Mvc.ViewComponents.DefaultViewComponentHelper+<InvokeCoreAsync>d__12.MoveNext()

The following code is causing the error

IEnumerable<string> actualNames = dr.GetColumnSchema().Select(o => o.ColumnName);

Further technical details

EF Core version: 1.1.0 Database Provider: Microsoft.EntityFrameworkCore.SqlServer Operating system: Server 2012R2 IDE: Visual Studio 2015

No application updates have been made anytime recently, so I strongly believe it has something to do with the server environment.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 18 (8 by maintainers)

Most upvoted comments

@pantonis I’ve ended up copying solution from net 462:

        private class DataRowDbColumn : DbColumn
        {
            #region Fields
           
            private readonly DataColumnCollection schemaColumns;       
            private readonly DataRow schemaRow;

            #endregion

            #region Constructors and Destructors
            
            public DataRowDbColumn(DataRow readerSchemaRow, DataColumnCollection readerSchemaColumns)
            {
                this.schemaRow = readerSchemaRow;
                this.schemaColumns = readerSchemaColumns;
                this.PopulateFields();
            }

            #endregion

            #region Methods

            private T GetDbColumnValue<T>(string columnName)
            {
                if (!this.schemaColumns.Contains(columnName))
                {
                    return default(T);
                }

                object schemaObject = this.schemaRow[columnName];
                if (schemaObject is T variable)
                {
                    return variable;
                }

                return default(T);
            }

            /// <summary>
            /// </summary>
            private void PopulateFields()
            {
                this.AllowDBNull = this.GetDbColumnValue<bool?>(SchemaTableColumn.AllowDBNull);
                this.BaseCatalogName = this.GetDbColumnValue<string>(SchemaTableOptionalColumn.BaseCatalogName);
                this.BaseColumnName = this.GetDbColumnValue<string>(SchemaTableColumn.BaseColumnName);
                this.BaseSchemaName = this.GetDbColumnValue<string>(SchemaTableColumn.BaseSchemaName);
                this.BaseServerName = this.GetDbColumnValue<string>(SchemaTableOptionalColumn.BaseServerName);
                this.BaseTableName = this.GetDbColumnValue<string>(SchemaTableColumn.BaseTableName);
                this.ColumnName = this.GetDbColumnValue<string>(SchemaTableColumn.ColumnName);
                this.ColumnOrdinal = this.GetDbColumnValue<int?>(SchemaTableColumn.ColumnOrdinal);
                this.ColumnSize = this.GetDbColumnValue<int?>(SchemaTableColumn.ColumnSize);
                this.IsAliased = this.GetDbColumnValue<bool?>(SchemaTableColumn.IsAliased);
                this.IsAutoIncrement = this.GetDbColumnValue<bool?>(SchemaTableOptionalColumn.IsAutoIncrement);
                this.IsExpression = this.GetDbColumnValue<bool>(SchemaTableColumn.IsExpression);
                this.IsHidden = this.GetDbColumnValue<bool?>(SchemaTableOptionalColumn.IsHidden);
                this.IsIdentity = this.GetDbColumnValue<bool?>("IsIdentity");
                this.IsKey = this.GetDbColumnValue<bool?>(SchemaTableColumn.IsKey);
                this.IsLong = this.GetDbColumnValue<bool?>(SchemaTableColumn.IsLong);
                this.IsReadOnly = this.GetDbColumnValue<bool?>(SchemaTableOptionalColumn.IsReadOnly);
                this.IsUnique = this.GetDbColumnValue<bool?>(SchemaTableColumn.IsUnique);
                this.NumericPrecision = this.GetDbColumnValue<int?>(SchemaTableColumn.NumericPrecision);
                this.NumericScale = this.GetDbColumnValue<int?>(SchemaTableColumn.NumericScale);
                this.UdtAssemblyQualifiedName = this.GetDbColumnValue<string>("UdtAssemblyQualifiedName");
                this.DataType = this.GetDbColumnValue<Type>(SchemaTableColumn.DataType);
                this.DataTypeName = this.GetDbColumnValue<string>("DataTypeName");
            }

            #endregion
        }
        /// <summary>
        /// Custom column schema to support lack of native method.
        /// </summary>
        private static ReadOnlyCollection<DbColumn> GetCustomColumnSchema(this SqlDataReader reader)
        {
            IList<DbColumn> columnSchema = new List<DbColumn>();
            DataTable schemaTable = reader.GetSchemaTable();

            // ReSharper disable once PossibleNullReferenceException
            DataColumnCollection schemaTableColumns = schemaTable.Columns;
            foreach (DataRow row in schemaTable.Rows)
            {
                DbColumn dbColumn = new DataRowDbColumn(row, schemaTableColumns);
                columnSchema.Add(dbColumn);
            }

            ReadOnlyCollection<DbColumn> readOnlyColumnSchema = new ReadOnlyCollection<DbColumn>(columnSchema);
            return readOnlyColumnSchema;
        }

@David-Engel Is that repo public? Do you have a link to the bug report? I’m experiencing the same issues where changing a project to target .NET 4.7.2 broke my application due to System.Data.Common no-longer having the correct DbDataReaderExtensions implementation.

The temporary workaround is to target .net 4.6.2. But we can’t stay on it forever. When is this going to be resolved? It’s been 6 months already.