System.InvalidCastException when trying to access portal

I installed the latest version of onlyoffice-communityserver on Debian 11, with two modifications from standard: Using an externally hosted MariaDB 10.9, and changing the port to 9970 instead of 80 in /etc/nginx/sites-available/onlyoffice (port 80 is already taken on this host). I used the instructions provided at Installing ONLYOFFICE Groups for Debian, Ubuntu, and derivatives - ONLYOFFICE

It looks like onlyoffice can connect to the DB, as it created and populated the tables in the database I gave to it. However, when I try to connect to the portal, I get the following error:

System.InvalidCastException
Object cannot be cast from DBNull to other types.

Description: HTTP 500.Error processing request.
Details: Non-web exception. Exception origin (name of application or object): mscorlib.
Exception stack trace:
  at System.DBNull.System.IConvertible.ToInt32 (System.IFormatProvider provider) [0x00000] in <f2b3ab7dfff746f594d2ef5b16ec3c90>:0 
  at System.Convert.ToInt32 (System.Object value, System.IFormatProvider provider) [0x00003] in <f2b3ab7dfff746f594d2ef5b16ec3c90>:0 
  at MySql.Data.MySqlClient.Driver.LoadCharacterSets (MySql.Data.MySqlClient.MySqlConnection connection) [0x000bc] in <67abbb3783c24cd0a9c685bbfbcea559>:0 
  at MySql.Data.MySqlClient.Driver.Configure (MySql.Data.MySqlClient.MySqlConnection connection) [0x00060] in <67abbb3783c24cd0a9c685bbfbcea559>:0 
  at MySql.Data.MySqlClient.MySqlConnection.Open () [0x0024f] in <67abbb3783c24cd0a9c685bbfbcea559>:0 
  at ASC.Common.Data.AdoProxy.DbConnectionProxy.Open () [0x00012] in <71cb3d721bb9413ea8360000a194c805>:0 
  at ASC.Common.Data.DbManager.OpenConnection () [0x00006] in <71cb3d721bb9413ea8360000a194c805>:0 
  at ASC.Common.Data.DbManager.get_Command () [0x0000e] in <71cb3d721bb9413ea8360000a194c805>:0 
  at ASC.Common.Data.DbManager.ExecuteList (ASC.Common.Data.Sql.ISqlInstruction sql) [0x00000] in <71cb3d721bb9413ea8360000a194c805>:0 
  at ASC.Common.Data.DbManagerProxy.ExecuteList (ASC.Common.Data.Sql.ISqlInstruction sql) [0x00006] in <71cb3d721bb9413ea8360000a194c805>:0 
  at ASC.Core.Data.DbBaseService+<>c__DisplayClass8_0.<ExecList>b__0 (ASC.Common.Data.IDbManager db) [0x00000] in <289eba5fc2ef4c3a9bc560fddf6ec9c8>:0 
  at ASC.Core.Data.DbBaseService.Execute[T] (System.Func`2[T,TResult] action) [0x00007] in <289eba5fc2ef4c3a9bc560fddf6ec9c8>:0 
  at ASC.Core.Data.DbBaseService.ExecList (ASC.Common.Data.Sql.ISqlInstruction sql) [0x0000d] in <289eba5fc2ef4c3a9bc560fddf6ec9c8>:0 
  at ASC.Core.Data.DbTenantService.GetTenants (ASC.Common.Data.Sql.Expressions.Exp where) [0x00007] in <289eba5fc2ef4c3a9bc560fddf6ec9c8>:0 
  at ASC.Core.Data.DbTenantService.GetTenant (System.String domain) [0x00039] in <289eba5fc2ef4c3a9bc560fddf6ec9c8>:0 
  at ASC.Core.Caching.CachedTenantService.GetTenant (System.String domain) [0x00012] in <289eba5fc2ef4c3a9bc560fddf6ec9c8>:0 
  at ASC.Core.TenantManager.GetTenant (System.String domain) [0x0001f] in <289eba5fc2ef4c3a9bc560fddf6ec9c8>:0 
  at ASC.Core.TenantManager.GetCurrentTenant (System.Boolean throwIfNotFound) [0x00047] in <289eba5fc2ef4c3a9bc560fddf6ec9c8>:0 
  at ASC.Common.Logging.LogManager+<>c.<GetLogger>b__0_0 () [0x00005] in <289eba5fc2ef4c3a9bc560fddf6ec9c8>:0 
  at ASC.Common.Logging.LogNLog.Log (NLog.LogEventInfo theEvent) [0x00008] in <71cb3d721bb9413ea8360000a194c805>:0 
  at ASC.Common.Logging.LogNLog.Log (NLog.LogLevel level, System.Object message) [0x00025] in <71cb3d721bb9413ea8360000a194c805>:0 
  at ASC.Common.Logging.LogNLog.Error (System.Object message) [0x00000] in <71cb3d721bb9413ea8360000a194c805>:0 
  at ASC.Api.ApiSetupHttpModule.Init (System.Web.HttpApplication context) [0x00053] in <1174082600f44859b26bb99bb8c52778>:0 
  at System.Web.Configuration.HttpModulesSection.LoadModules (System.Web.HttpApplication app) [0x00047] in <ed5a28140a7245099ac6474902196c2e>:0 
  at System.Web.HttpApplication.InitOnce (System.Boolean full_init) [0x0008e] in <ed5a28140a7245099ac6474902196c2e>:0

I had to turn off customErrors in /var/www/onlyoffice/WebStudio/Web.config to see this error message. I did try uninstalling and re-installing the onlyoffice-communityserver package, but it didn’t change. There is nothing in any error logs I can find, but I’d be happy to share any error logs you request. I’m a software developer with experience in Node, ASP.NET, linux, etc, so feel free to use technical jargon. I’m just hoping to get this working. I had it working on Ubuntu 22 in a test VM, but I haven’t got it to work since I switched to Debian 11 with MariaDB for prod.

Update: I switched to using an internal MySQL 8 server, and that allowed me to access the portal. I’m curious why that is, the instructions say that MariaDB worked. Perhaps it is the external database that is an issue? Or maybe it doesn’t work without root access? Would love to see that fixed.

Control panel isn’t working now, returns an app error:

2023-01-14 10:51:51 - error: http://localhost/api/2.0/settings/controlpanel.json write EPROTO 140485465192320:error:14094438:SSL routines:ssl3_read_bytes:tlsv1 alert internal error:../deps/openssl/openssl/ssl/record/rec_layer_s3.c:1544:SSL alert number 80

I assume this is because it should be requesting localhost:9970 instead of just localhost

Hello @ps_iclimbthings

Sorry for the late reply.

Please share more information on the issue:

  • version of MariaDB;
  • OS of the server where database is installed;

Possibly it is configured incorrectly. Please refer to this link to see the example of database configuration:
https://github.com/ONLYOFFICE/Docker-CommunityServer#installing-mysql

This is a good point. If possible try granting root access to the database and checking the situation after.

Please check next config www/config/production.json and the port used. If port differs from currently used one then change it and restart portal with command service monoserve restart and Control Panel with supervisorctl restart www . After portal is booted up try reaching the Control Panel again.

@Constantine Thanks for the help. I’ve pivoted a bit, now using docker to run (onlyoffice/communityserver latest), which worked with mysql 8, but is failing with MariaDB 10.10 (latest running in docker: Docker)

Here are the relevant parts of my docker run command (I excluded some arguments for brevity):

docker run -i -t -d --privileged --restart=always \
    --name onlyoffice-community-server \
    --cgroupns=host \
    -e MYSQL_SERVER_ROOT_PASSWORD=######### \
    -e MYSQL_SERVER_DB_NAME=onlyoffice_groups \
    -e MYSQL_SERVER_HOST=db \
    -e MYSQL_SERVER_USER=onlyoffice_groups \
    -e MYSQL_SERVER_PASS=######## \
    -v /sys/fs/cgroup:/sys/fs/cgroup:rw \
    onlyoffice/communityserver

I did put it on the same network as my MariaDB instance, and it does appear from the logs that it can connect and that the credentials are correct.

The error I am now getting is:

ERROR [10] ASC.Backup.Scheduler - error while scheduling backups: {0} System.InvalidCastException: Object cannot be cast from DBNull to other types.
  at System.DBNull.System.IConvertible.ToInt32 (System.IFormatProvider provider) [0x00000] in <f2b3ab7dfff746f594d2ef5b16ec3c90>:0 
  at System.Convert.ToInt32 (System.Object value, System.IFormatProvider provider) [0x00003] in <f2b3ab7dfff746f594d2ef5b16ec3c90>:0 
  at MySql.Data.MySqlClient.Driver.LoadCharacterSets (MySql.Data.MySqlClient.MySqlConnection connection) [0x000bc] in <67abbb3783c24cd0a9c685bbfbcea559>:0 
  at MySql.Data.MySqlClient.Driver.Configure (MySql.Data.MySqlClient.MySqlConnection connection) [0x00060] in <67abbb3783c24cd0a9c685bbfbcea559>:0 
  at MySql.Data.MySqlClient.MySqlConnection.Open () [0x0024f] in <67abbb3783c24cd0a9c685bbfbcea559>:0 
  at ASC.Common.Data.DbManager.OpenConnection () [0x00006] in <71cb3d721bb9413ea8360000a194c805>:0 
  at ASC.Common.Data.DbManager.get_Command () [0x0000e] in <71cb3d721bb9413ea8360000a194c805>:0 
  at ASC.Common.Data.DbManager.ExecuteList (ASC.Common.Data.Sql.ISqlInstruction sql) [0x00000] in <71cb3d721bb9413ea8360000a194c805>:0 
  at ASC.Data.Backup.Storage.BackupRepository.GetBackupSchedules () [0x00086] in <5c0ed394f8794246b5703a880bd6a0d2>:0 
  at ASC.Data.Backup.Service.BackupSchedulerService.ScheduleBackupTasks () [0x0002b] in <5c0ed394f8794246b5703a880bd6a0d2>:0 
ERROR [7] ASC.Backup.Cleaner - error while cleaning expired backup records System.InvalidCastException: Object cannot be cast from DBNull to other types.
  at System.DBNull.System.IConvertible.ToInt32 (System.IFormatProvider provider) [0x00000] in <f2b3ab7dfff746f594d2ef5b16ec3c90>:0 
  at System.Convert.ToInt32 (System.Object value, System.IFormatProvider provider) [0x00003] in <f2b3ab7dfff746f594d2ef5b16ec3c90>:0 
  at MySql.Data.MySqlClient.Driver.LoadCharacterSets (MySql.Data.MySqlClient.MySqlConnection connection) [0x000bc] in <67abbb3783c24cd0a9c685bbfbcea559>:0 
  at MySql.Data.MySqlClient.Driver.Configure (MySql.Data.MySqlClient.MySqlConnection connection) [0x00060] in <67abbb3783c24cd0a9c685bbfbcea559>:0 
  at MySql.Data.MySqlClient.MySqlConnection.Open () [0x0024f] in <67abbb3783c24cd0a9c685bbfbcea559>:0 
  at ASC.Common.Data.DbManager.OpenConnection () [0x00006] in <71cb3d721bb9413ea8360000a194c805>:0 
  at ASC.Common.Data.DbManager.get_Command () [0x0000e] in <71cb3d721bb9413ea8360000a194c805>:0 
  at ASC.Common.Data.DbManager.ExecuteList (ASC.Common.Data.Sql.ISqlInstruction sql) [0x00000] in <71cb3d721bb9413ea8360000a194c805>:0 
  at ASC.Data.Backup.Storage.BackupRepository.GetExpiredBackupRecords () [0x000a6] in <5c0ed394f8794246b5703a880bd6a0d2>:0 
  at ASC.Data.Backup.Service.BackupCleanerService.DeleteExpiredBackups () [0x00026] in <5c0ed394f8794246b5703a880bd6a0d2>:0 
ERROR [11] ASC.Feed.Agregator - System.InvalidCastException: Object cannot be cast from DBNull to other types.
  at System.DBNull.System.IConvertible.ToInt32 (System.IFormatProvider provider) [0x00000] in <f2b3ab7dfff746f594d2ef5b16ec3c90>:0 
  at System.Convert.ToInt32 (System.Object value, System.IFormatProvider provider) [0x00003] in <f2b3ab7dfff746f594d2ef5b16ec3c90>:0 
  at MySql.Data.MySqlClient.Driver.LoadCharacterSets (MySql.Data.MySqlClient.MySqlConnection connection) [0x000bc] in <67abbb3783c24cd0a9c685bbfbcea559>:0 
  at MySql.Data.MySqlClient.Driver.Configure (MySql.Data.MySqlClient.MySqlConnection connection) [0x00060] in <67abbb3783c24cd0a9c685bbfbcea559>:0 
  at MySql.Data.MySqlClient.MySqlConnection.Open () [0x0024f] in <67abbb3783c24cd0a9c685bbfbcea559>:0 
  at ASC.Common.Data.DbManager.OpenConnection () [0x00006] in <71cb3d721bb9413ea8360000a194c805>:0 
  at ASC.Common.Data.DbManager.get_Command () [0x0000e] in <71cb3d721bb9413ea8360000a194c805>:0 
  at ASC.Common.Data.DbManager.ExecuteScalar[T] (ASC.Common.Data.Sql.ISqlInstruction sql) [0x00000] in <71cb3d721bb9413ea8360000a194c805>:0 
  at ASC.Feed.Data.FeedAggregateDataProvider.GetLastTimeAggregate (System.String key) [0x00034] in <0ab92d6b4e274500855ca06732fa6e62>:0 
  at ASC.Feed.Aggregator.FeedAggregatorService.AggregateFeeds (System.Object interval) [0x0006a] in <c1a2e5bad0114912b4c92d41b081f85c>:0  
ERROR [11] ASC.Feed.Agregator - System.Collections.Generic.KeyNotFoundException: The given key '28271' was not present in the dictionary.
  at System.Collections.Generic.Dictionary`2[TKey,TValue].get_Item (TKey key) [0x0001e] in <f2b3ab7dfff746f594d2ef5b16ec3c90>:0 
  at MySql.Data.MySqlClient.MySqlField.SetFieldEncoding () [0x00034] in <67abbb3783c24cd0a9c685bbfbcea559>:0 
  at MySql.Data.MySqlClient.MySqlField.set_CharacterSetIndex (System.Int32 value) [0x00007] in <67abbb3783c24cd0a9c685bbfbcea559>:0 
  at MySql.Data.MySqlClient.NativeDriver.GetColumnData (MySql.Data.MySqlClient.MySqlField field) [0x000ad] in <67abbb3783c24cd0a9c685bbfbcea559>:0 
  at MySql.Data.MySqlClient.NativeDriver.GetColumnsData (MySql.Data.MySqlClient.MySqlField[] columns) [0x00004] in <67abbb3783c24cd0a9c685bbfbcea559>:0 
  at MySql.Data.MySqlClient.Driver.GetColumns (System.Int32 count) [0x0001c] in <67abbb3783c24cd0a9c685bbfbcea559>:0 
  at MySql.Data.MySqlClient.ResultSet.LoadColumns (System.Int32 numCols) [0x00000] in <67abbb3783c24cd0a9c685bbfbcea559>:0 
  at MySql.Data.MySqlClient.ResultSet..ctor (MySql.Data.MySqlClient.Driver d, System.Int32 statementId, System.Int32 numCols) [0x0002a] in <67abbb3783c24cd0a9c685bbfbcea559>:0 
  at MySql.Data.MySqlClient.Driver.NextResult (System.Int32 statementId, System.Boolean force) [0x00039] in <67abbb3783c24cd0a9c685bbfbcea559>:0 
  at MySql.Data.MySqlClient.MySqlDataReader.NextResult () [0x000d5] in <67abbb3783c24cd0a9c685bbfbcea559>:0 
  at MySql.Data.MySqlClient.MySqlDataReader.Close () [0x00039] in <67abbb3783c24cd0a9c685bbfbcea559>:0 
  at MySql.Data.MySqlClient.MySqlCommand.ResetReader () [0x00020] in <67abbb3783c24cd0a9c685bbfbcea559>:0 
  at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader (System.Data.CommandBehavior behavior) [0x0032c] in <67abbb3783c24cd0a9c685bbfbcea559>:0 
  at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader () [0x00000] in <67abbb3783c24cd0a9c685bbfbcea559>:0 
  at MySql.Data.MySqlClient.MySqlCommand.ExecuteScalar () [0x0002e] in <67abbb3783c24cd0a9c685bbfbcea559>:0 
  at ASC.Common.Data.DataExtensions.ExecuteScalar[T] (System.Data.Common.DbCommand command, System.String sql, System.Object[] parameters) [0x00009] in <71cb3d721bb9413ea8360000a194c805>:0 
  at ASC.Common.Data.DataExtensions.ExecuteScalar[T] (System.Data.Common.DbCommand command) [0x00007] in <71cb3d721bb9413ea8360000a194c805>:0 
  at ASC.Common.Data.DataExtensions.ExecuteScalar[T] (System.Data.Common.DbCommand command, ASC.Common.Data.Sql.ISqlInstruction sql, ASC.Common.Data.Sql.ISqlDialect dialect) [0x00008] in <71cb3d721bb9413ea8360000a194c805>:0 
  at ASC.Common.Data.DbManager.ExecuteScalar[T] (ASC.Common.Data.Sql.ISqlInstruction sql) [0x0000d] in <71cb3d721bb9413ea8360000a194c805>:0 
  at ASC.Feed.Data.FeedAggregateDataProvider.GetLastTimeAggregate (System.String key) [0x00034] in <0ab92d6b4e274500855ca06732fa6e62>:0 
  at ASC.Feed.Aggregator.FeedAggregatorService.AggregateFeeds (System.Object interval) [0x0006a] in <c1a2e5bad0114912b4c92d41b081f85c>:0  
ERROR [26] ASC.Indexer - Ping false System.Collections.Generic.KeyNotFoundException: The given key '28271' was not present in the dictionary.
  at System.Collections.Generic.Dictionary`2[TKey,TValue].get_Item (TKey key) [0x0001e] in <f2b3ab7dfff746f594d2ef5b16ec3c90>:0 
  at MySql.Data.MySqlClient.MySqlField.SetFieldEncoding () [0x00034] in <67abbb3783c24cd0a9c685bbfbcea559>:0 
  at MySql.Data.MySqlClient.MySqlField.set_CharacterSetIndex (System.Int32 value) [0x00007] in <67abbb3783c24cd0a9c685bbfbcea559>:0 
  at MySql.Data.MySqlClient.NativeDriver.GetColumnData (MySql.Data.MySqlClient.MySqlField field) [0x000ad] in <67abbb3783c24cd0a9c685bbfbcea559>:0 
  at MySql.Data.MySqlClient.NativeDriver.GetColumnsData (MySql.Data.MySqlClient.MySqlField[] columns) [0x00004] in <67abbb3783c24cd0a9c685bbfbcea559>:0 
  at MySql.Data.MySqlClient.Driver.GetColumns (System.Int32 count) [0x0001c] in <67abbb3783c24cd0a9c685bbfbcea559>:0 
  at MySql.Data.MySqlClient.ResultSet.LoadColumns (System.Int32 numCols) [0x00000] in <67abbb3783c24cd0a9c685bbfbcea559>:0 
  at MySql.Data.MySqlClient.ResultSet..ctor (MySql.Data.MySqlClient.Driver d, System.Int32 statementId, System.Int32 numCols) [0x0002a] in <67abbb3783c24cd0a9c685bbfbcea559>:0 
  at MySql.Data.MySqlClient.Driver.NextResult (System.Int32 statementId, System.Boolean force) [0x00039] in <67abbb3783c24cd0a9c685bbfbcea559>:0 
  at MySql.Data.MySqlClient.MySqlDataReader.NextResult () [0x000d5] in <67abbb3783c24cd0a9c685bbfbcea559>:0 
  at MySql.Data.MySqlClient.MySqlDataReader.Close () [0x00039] in <67abbb3783c24cd0a9c685bbfbcea559>:0 
  at MySql.Data.MySqlClient.MySqlCommand.ResetReader () [0x00020] in <67abbb3783c24cd0a9c685bbfbcea559>:0 
  at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader (System.Data.CommandBehavior behavior) [0x0032c] in <67abbb3783c24cd0a9c685bbfbcea559>:0 
  at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader () [0x00000] in <67abbb3783c24cd0a9c685bbfbcea559>:0 
  at MySql.Data.MySqlClient.MySqlCommand.ExecuteScalar () [0x0002e] in <67abbb3783c24cd0a9c685bbfbcea559>:0 
  at ASC.Common.Data.DataExtensions.ExecuteScalar[T] (System.Data.Common.DbCommand command, System.String sql, System.Object[] parameters) [0x00009] in <71cb3d721bb9413ea8360000a194c805>:0 
  at ASC.Common.Data.DataExtensions.ExecuteScalar[T] (System.Data.Common.DbCommand command) [0x00007] in <71cb3d721bb9413ea8360000a194c805>:0 
  at ASC.Common.Data.DataExtensions.ExecuteScalar[T] (System.Data.Common.DbCommand command, ASC.Common.Data.Sql.ISqlInstruction sql, ASC.Common.Data.Sql.ISqlDialect dialect) [0x00008] in <71cb3d721bb9413ea8360000a194c805>:0 
  at ASC.Common.Data.DbManager.ExecuteScalar[T] (ASC.Common.Data.Sql.ISqlInstruction sql) [0x0000d] in <71cb3d721bb9413ea8360000a194c805>:0 
  at ASC.Core.Data.DbBaseService+<>c__DisplayClass6_0`1[T].<ExecScalar>b__0 (ASC.Common.Data.IDbManager db) [0x00000] in <289eba5fc2ef4c3a9bc560fddf6ec9c8>:0 
  at ASC.Core.Data.DbBaseService.Execute[T] (System.Func`2[T,TResult] action) [0x00007] in <289eba5fc2ef4c3a9bc560fddf6ec9c8>:0 
  at ASC.Core.Data.DbBaseService.ExecScalar[T] (ASC.Common.Data.Sql.ISqlInstruction sql) [0x0000d] in <289eba5fc2ef4c3a9bc560fddf6ec9c8>:0 
  at ASC.Core.Data.DbTenantService.GetTenantSettings (System.Int32 tenant, System.String key) [0x00030] in <289eba5fc2ef4c3a9bc560fddf6ec9c8>:0 
  at ASC.Core.Caching.CachedTenantService.GetTenantSettings (System.Int32 tenant, System.String key) [0x00022] in <289eba5fc2ef4c3a9bc560fddf6ec9c8>:0 
  at ASC.Core.CoreConfiguration.GetSetting (System.String key, System.Int32 tenant) [0x00013] in <289eba5fc2ef4c3a9bc560fddf6ec9c8>:0 
  at ASC.Core.CoreConfiguration.GetSection[T] (System.Int32 tenantId, System.String sectionName) [0x00000] in <289eba5fc2ef4c3a9bc560fddf6ec9c8>:0 
  at ASC.Core.CoreConfiguration.GetSection[T] (System.Int32 tenantId) [0x00011] in <289eba5fc2ef4c3a9bc560fddf6ec9c8>:0 
  at ASC.ElasticSearch.Client.get_Instance () [0x0003d] in <3bb54ce544d94abf8906cb78d059ea79>:0 
  at ASC.ElasticSearch.FactoryIndexer.CheckState (System.Boolean cacheState) [0x00042] in <3bb54ce544d94abf8906cb78d059ea79>:0 

If I had to guess, it looks like some MariaDB incompatibility, because the error is during the load of a character set, but I don’t know much about character sets.

Thanks for any help!

Seems related to c# - MySqlConnection.Open() System.InvalidCastException: Object cannot be cast from DBNull to other types - Stack Overflow, going to try MariaDB 10.9.4 to see if that fixes

Looks like downgrading to MariaDB 10.9.4 does work. Seems like you guys should add support for 10.10 using the recommendations in that Stack Overflow article, or add a note on the system requirements page that 10.10+ is not supported.

We are checking the situation with MariaDB 10.10. I will update this thread when there are any news come up.

Does it mean that you’ve configured this version and it is working with your portal right now? Sorry if I misunderstood.

Yes, everything is working as expected now as far as this thread is concerned.

I’m glad to hear that.
As I said we are checking the situation. I will let you know the results.

Hello again @ps_iclimbthings

Indeed, there is a bug with external MariaDB 10.10.x that prevents portal from starting up.
We added it into our internal tracked under the number 60728. We are already looking for the way to solve it.
Thanks for reporting and sorry for the inconvenience caused.