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

1

15

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: 
Hilaire answered 14/2, 2014 at 10:24 Comment(2)
did you ever get this resolved - i've the same problem?Hispanicism
No I run out of time and had to stick to MVC 3. Very annoying as I think I was close to a successful upgrade.Hilaire
H
10

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.

Hispanicism answered 22/3, 2014 at 19:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.