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
EntityFrameworkExtras.EFCore.DatabaseExtensions.ExecuteStoredProcedure
DocumentPortal.Components.FolderViewComponent+<>c__DisplayClass3_0.
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+
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.ViewComponents.DefaultViewComponentInvoker+
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.ViewComponents.DefaultViewComponentInvoker+
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.ViewComponents.DefaultViewComponentHelper+
The following code is causing the error
c#
IEnumerable<string> actualNames = dr.GetColumnSchema().Select(o => o.ColumnName);
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.
What's the type of the DbDataReader being used here?
@ajcvickers @corivera I think we can either assume that this could be SqlDataReader and investigate, or close as no repro, as we haven't heard back from @dominicrooijackers. Thoughts?
I have resolved my issue, I have to look and see what the solution was again.
Verzonden van mijn HTC
----- Bericht beantwoorden -----
Van: "Diego Vega" notifications@github.com
Aan: "dotnet/corefx" corefx@noreply.github.com
CC: "Dominic Rooijackers" drooijackers@exploriaresorts.com, "Mention" mention@noreply.github.com
Onderwerp: [dotnet/corefx] GetColumnSchema not supported (#26302)
Datum: wo, feb. 7, 2018 21:28
@ajcvickershttps://github.com/ajcvickers @coriverahttps://github.com/corivera I think we can either assume that this could be SqlDataReader and investigate, or close as no repro, as we haven't heard back from @dominicrooijackershttps://github.com/dominicrooijackers. Thoughts?
-
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://github.com/dotnet/corefx/issues/26302#issuecomment-363982110, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AV62WkA5KU7_O-PP0PJTfOD4_a-lYdf4ks5tSlu6gaJpZM4Rc1ov.
This e-mail is confidential and all information within, including any attachments, is intended for the named recipient(s) listed above. The unauthorized use, distribution, copying or alteration of this email is strictly prohibited. If you are not the intended recipient, any disclosure or action taken with the information contained in this e-mail is strictly prohibited. If you have received this e-mail in error, please notify the sender immediately by return e-mail and proceed to delete email message from your system. Thank You.
I'm using EFCore version 2.1.0-preview2-30045 and Full Framework
All worked properly on v462
After moving to v471, SqlDataReader.GetColumnSchema is no longer working:
System.NotSupportedException: Specified method is not supported.
at ReadOnlyCollection<DbColumn> System.Data.Common.DbDataReaderExtensions.GetColumnSchema(DbDataReader reader)
EDIT
After switching project back to .NET 462, all is working again.
Thanks @msmolka for the additional information!
Moved to SqlClient.
I looked through the code on Framework.
A change was ported to 4.7.1 for API compat between NetStandard and NetFx in System.Data.Common. The port relies on the provider to implement IDbColumnSchemaGenerator else throws a not supported exception.
The consuming APIs should be checking for DbDataReader.CanGetColumnSchema() before actually retrieving the schema using the GetColumnSchema() API.
For 4.6.2 the partial facade was mapping the DataTable to ReadOnlyCollection
The fix has to go into NetFx and not .Net Core. I will move this issue out of 2.1.0, open a bug in our NetFx repo and track this issue there.
Is there any workaround?
So in which version of FULL Framework it will be working?
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.
We should NOT track .NET Framework bugs on CoreFX repo. @saurabh500 @keeratsingh @David-Engel @AfsanehR can you please clarify and close it here?
If it is a regression / serious bug in .NET Framework, we should use appropriate channels.
@saurabh500 Any news on this one?
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.
Do you have any news on this one?
@pantonis I've ended up copying solution from net 462:
```c#
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
}
```c#
/// <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;
}
@msmolka Since I was trying to use this when calling and mapping Stored Procedure result, I ended up using Query
Thanks anyway
As @saurabh500 mentioned, this is not a .NET Core issue. He filed a bug in the NetFx repo. Closing this issue.
@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.
That's a question for @saurabh500. I'm not sure where the "NetFx" repo he referred to is. I don't see an issue in the one I thought it would be in.
NetFx is .NET Framework. It is not open source. The bugs there are tracked via VS Developer Community Portal (see our main page).
I would recommend to file it there, then post the link here - @David-Engel and team can associate the NetFx bug with it and communicate there directly.
Most helpful comment
@pantonis I've ended up copying solution from net 462:
```c#
private class DataRowDbColumn : DbColumn
{
#region Fields