无法将类型为"Glimpse.Ado.AlternateType.GlimpseDbConnection"的对象转换为类型为"System.Data.SqlClient.SqlConnection"的对象 [英] Unable to cast object of type 'Glimpse.Ado.AlternateType.GlimpseDbConnection' to type 'System.Data.SqlClient.SqlConnection'

查看:184
本文介绍了无法将类型为"Glimpse.Ado.AlternateType.GlimpseDbConnection"的对象转换为类型为"System.Data.SqlClient.SqlConnection"的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用EF 6异步功能时,出现"System.InvalidCastException发生"异常. 该消息是:无法将类型为"Glimpse.Ado.AlternateType.GlimpseDbConnection"的对象转换为类型为"System.Data.SqlClient.SqlConnection".

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'.

此应用程序已从MVC4升级到MVC5,并且首次使用.Net Framework 4.5.

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

我知道以前曾有人提出过这个问题; https://github.com/Glimpse/Glimpse/issues/540 ,但是我尝试获取最新版本的Glimpse而且我仍然遇到同样的问题. 我想知道我是否无法正确卸载Glimpse,无论是最新版本还是以前使用的版本.

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.

发生异常的代码是

   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();
        }
    }

例外是;

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: 

推荐答案

您应检查是否未安装Glimpse EF5.这为我解决了.

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

如果不这样做,则只需卸载所有Glimpse软件包.清洁您的解决方案,然后重新安装Glimpse.

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

这篇关于无法将类型为"Glimpse.Ado.AlternateType.GlimpseDbConnection"的对象转换为类型为"System.Data.SqlClient.SqlConnection"的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆