Unable to cast object of type 'Glimpse.Ado.AlternateType.GlimpseDbConnection' to type 'System.Data.SqlClient.SqlConnection'

和自甴很熟 提交于 2019-12-08 15:04:18

问题


I am getting an "System.InvalidCastException occurred" exception where I am using the EF 6 asynchronous functionality. The message is: Unable to cast object of type 'Glimpse.Ado.AlternateType.GlimpseDbConnection' to type 'System.Data.SqlClient.SqlConnection'.

This application was upgraded from MVC4 to MVC5 and is using the .Net Framework 4.5 for the first time.

I am aware this has been raised as an issue before; https://github.com/Glimpse/Glimpse/issues/540 but I tried getting the latest version of Glimpse and I still got the same problem. I am wondering if I failed to uninstall Glimpse properly, either the latest version or the one I used previously.

The code where the exception happened is;

   public static async Task<IList<Company>> GetCompaniesAsync()
    {
        using (var db = new SherryGreenGroupContext())
        {
            return await db.Companies
                             .Include("AddressLines")
                             .Where(x => x.EndOfBusinessDate == null)
                             .OrderBy(x => x.CompanyName).ToListAsync();
        }
    }

The exception is;

System.InvalidCastException occurred
  HResult=-2147467262
  Message=Unable to cast object of type 'Glimpse.Ado.AlternateType.GlimpseDbConnection' to type 'System.Data.SqlClient.SqlConnection'.
  Source=System.Data
  StackTrace:
       at System.Data.SqlClient.SqlCommand.set_DbConnection(DbConnection value)
  InnerException: 

回答1:


You should check you don't have Glimpse EF5 installed. That fixed it for me.

If you dont' then just uninstall all Glimpse packages. Clean your solution and reinstall Glimpse.



来源:https://stackoverflow.com/questions/21776705/unable-to-cast-object-of-type-glimpse-ado-alternatetype-glimpsedbconnection-to

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!