Unable to to login - System.InvalidCastException: Object cannot be cast from DBNull to other types.
-
Hi, suddenly, I'm no longer able to login to the UI (with 'Unknown Error Obtaining Token' error). The logs however started showing "Object cannot be cast from DBNull to other types." error as follows:
FrontEnd.log[InvalidCastException]: Object cannot be cast from DBNull to other types. at System.DBNull.System.IConvertible.ToInt32(IFormatProvider provider) at MySql.Data.MySqlClient.Driver.LoadCharacterSets(MySqlConnection connection) at MySql.Data.MySqlClient.Driver.Configure(MySqlConnection connection) at MySql.Data.MySqlClient.MySqlConnection.Open() at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext](TTarget target, Action`2 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed) at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.Open(DbConnection connection, DbInterceptionContext interceptionContext) at System.Data.Entity.Core.EntityClient.EntityConnection.Open() [EntityException]: The underlying provider failed on Open. at System.Data.Entity.Core.EntityClient.EntityConnection.Open() at System.Data.Entity.Core.Objects.ObjectContext.EnsureConnection(Boolean shouldMonitorTransactions) at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess) at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass41_0.<GetResults>b__0() at System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption) at System.Data.Entity.Core.Objects.ObjectQuery`1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__31_0() at System.Data.Entity.Internal.LazyEnumerator`1.MoveNext() at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source) at Toems_DataModel.GenericRepository`1.GetFirstOrDefault(Expression`1 filter, Func`2 orderBy) at Toems_Service.Entity.ServiceUser.GetUserForLogin(String userName) at Toems_Service.AuthenticationServices.GlobalLogin(String userName, String password, String loginType, String verificationCode) at Toems_ApplicationApi.SimpleAuthorizationServerProvider.GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context) at Microsoft.Owin.Security.OAuth.OAuthAuthorizationServerHandler.<InvokeTokenEndpointResourceOwnerPasswordCredentialsGrantAsync>d__10.MoveNext() in /_/src/Microsoft.Owin.Security.OAuth/OAuthAuthorizationServerHandler.cs:line 567
Application.log
System.Data.Entity.Core.EntityException: The underlying provider failed on Open. ---> System.InvalidCastException: Object cannot be cast from DBNull to other types. at System.DBNull.System.IConvertible.ToInt32(IFormatProvider provider) at MySql.Data.MySqlClient.Driver.LoadCharacterSets(MySqlConnection connection) at MySql.Data.MySqlClient.Driver.Configure(MySqlConnection connection) at MySql.Data.MySqlClient.MySqlConnection.Open() at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext](TTarget target, Action`2 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed) at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.Open(DbConnection connection, DbInterceptionContext interceptionContext) at System.Data.Entity.Core.EntityClient.EntityConnection.Open() --- End of inner exception stack trace --- at System.Data.Entity.Core.EntityClient.EntityConnection.Open() at System.Data.Entity.Core.Objects.ObjectContext.EnsureConnection(Boolean shouldMonitorTransactions) at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess) at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass41_0.<GetResults>b__0() at System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption) at System.Data.Entity.Core.Objects.ObjectQuery`1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__31_0() at System.Data.Entity.Internal.LazyEnumerator`1.MoveNext() at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source) at Toems_DataModel.GenericRepository`1.GetFirstOrDefault(Expression`1 filter, Func`2 orderBy) at Toems_Service.Entity.ServiceSetting.GetSetting(String settingName) at Toems_Service.Entity.ServiceSetting.GetSettingValue(String settingName) at Toems_Service.Entity.ServiceActiveImagingTask.CancelTimedOutTasks()
I have recently updated to MariaDB 4.11 (I can succesfully access the database via Heidi), other than that I haven't done anything that may have caused this. Can you help please?
-
There are two issues here, both seem connected to upgrading my MariaDB to 10.11.
- From MariaDB 10.6.1, the main name of the previous 3 byte utf character set has been changed to utf8mb3. This causes an error MySql.Data.MySqlClient.MySqlException: Character set 'utf8mb3' is not supported by .Net Framework.
- From MariaDB 10.10.1 the ID field has been made Nullable which appears to be causing the 'Object cannot be cast from DBNull to other types'
Unfortunately the database files have been changed and downgrading back to 10.4 and 10.5 can't read them. I would have to backup my db, recreate 10.4 or 10.5 instance and restore.
Stackoverflow suggests updating the MySql.Data package or switching to different connector like MysqlConnector.
Hopefully this will help.
-
Thanks for your research. I had planned on updating mysql.data to the 8.x version in the last release, but was having problems with it and scrapped it. I'll try and work through the problems and get it into the next release.
-
no problem, happy to help