Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to cast object of type 'Glimpse.Ado.AlternateType.GlimpseDbConnection' to type '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'.

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: 
like image 630
arame3333 Avatar asked Feb 14 '14 10:02

arame3333


1 Answers

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.

like image 102
richardwhatever Avatar answered Oct 21 '22 10:10

richardwhatever