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: 
arame3333
  • 9,887
  • 26
  • 122
  • 205

1 Answers1

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.

richardwhatever
  • 4,564
  • 5
  • 23
  • 26