Skip to content

Fixing MSF to allow for Scripting Runtime Version 4.x

mschwarz1 edited this page Nov 16, 2018 · 2 revisions

Unity as of writing this has by default a Scripting Runtime Version of .NET 3.5. Currently you are able to choose between 3.5 or 4.x. As of Unity 2018.3 the new default Scripting Runtime Version is .NET 4.x and the 3.5 option is deprecated. That said you can still use it as it isn't totally removed yet but it will eventually be.

MSF currently uses by default LiteDB in order to maintain databases for various user information. The dll currently included in the project targets a Scripting Runtime Version of .NET 3.5, as a result it can cause a problem when attempting to run it on some (potentially all, I'm not sure I only tested it on my linux box) platforms.

If you attempt to run the built master server and spawner you should get console output somewhat around the lines of

[Error | Logs] Failed to setup LiteDB. Try removing generated database files, because we've switched to V2 of LiteDB instead of V3. This caused files, generated by V3, to be incompatible with V2.

(Filename: ./Runtime/Export/Debug.bindings.h Line: 45)

PlatformNotSupportedException: Operation is not supported on this platform.

Then it will fail to bind and eventually just crash or hang. The error log is actually inaccurate in this case although I would recommend deleting any databases it attempts to generate (auth.db if you're running through the quick setup examples).

The fix to this is actually fairly simple. Grab a newer dll from https://github.com/mbdavid/LiteDB/releases then replace the old LiteDB.dll located in Path\To\Project\Assets\Barebones\MsfDatabaseImplementations\LiteDBV2\Plugins. After Unity recompiles you should run into 5 errors.

Assets\Barebones\MsfDatabaseImplementations\LiteDBV2\Scripts\ProfilesDatabaseLdb.cs(20,56): error CS0246: The type or namespace name 'IndexOptions' could not be found (are you missing a using directive or an assembly reference?)
Assets\Barebones\MsfDatabaseImplementations\LiteDBV2\Scripts\AuthDbLdb.cs(21,56): error CS0246: The type or namespace name 'IndexOptions' could not be found (are you missing a using directive or an assembly reference?)
Assets\Barebones\MsfDatabaseImplementations\LiteDBV2\Scripts\AuthDbLdb.cs(22,53): error CS0246: The type or namespace name 'IndexOptions' could not be found (are you missing a using directive or an assembly reference?)
Assets\Barebones\MsfDatabaseImplementations\LiteDBV2\Scripts\AuthDbLdb.cs(25,55): error CS0246: The type or namespace name 'IndexOptions' could not be found (are you missing a using directive or an assembly reference?)
Assets\Barebones\MsfDatabaseImplementations\LiteDBV2\Scripts\AuthDbLdb.cs(28,63): error CS0246: The type or namespace name 'IndexOptions' could not be found (are you missing a using directive or an assembly reference?)

All of them have to do with IndexOptions not being found. As far as I can tell IndexOptions have been removed from LiteDB. That said here is an example of what I changed one of the problematic lines of code to.

originally:

_accounts.EnsureIndex(a => a.Username, new IndexOptions() { Unique = true, IgnoreCase = true, TrimWhitespace = true});

my fix:

_accounts.EnsureIndex(a => a.Username, true);

Seems they removed the additional index options aside from unique in the later versions of LiteDB. The same changes can be applied to each line causing an error. Once those issues are fixed and Unity recompiles you shouldn't run into any more issues and everything should run fine on the master server.