Overview
This article describes the reason and fix for an error similar to the following:
Could not load file or assembly 'mfmssqlclrobjs'
The beginning of the error likely contains more information, similar to this:
Statement(s) could not be prepared. (ERROR 8180, SQLSTATE: 42000) An error occurred in the Microsoft .NET Framework while trying to load assembly id 65536. The server may be running out of resources, or the assembly may not be trusted. Rin the query again, or check documentation to see how to solve the assembly trust issues. For more information about this error: System.IO.FileLoadException: Could not load file or assembly 'mfmssqlclrobjs, Version=18.12.7201.5, Culture=neutral, PublicKeyToken=2a7ac2a585d27d18' or one of its dependencies. An error relating to security occurred. (Exception from HRESULT: 0x8013150A)…
And after a .NET stack trace it would likely end with "(ERROR: 10314, SQLSTATE: 42000)".
Symptoms
You may experience it in situations like the following:
- In the metadata card when you select an object in the M-Files Desktop.
- When a new MS SQL server from a high-availability cluster serves the request.
- If you migrate an existing vault to a new MS SQL server.
The symptoms include:
- Error when showing the metadata card when the user is not a vault admin or does not have rights to see all objects.
- Failed background tasks in the M-Files Admin tool.
- Inability to create objects.
- New users can't log in (e.g., with a message similar to "we are preparing the vault for you").
- Searches may fail.
- Permission changes do not propagate (e.g., caused by workflow state transitions or metadata changes).
- Windows Event Log gets flooded with these errors (e.g., that background tasks cannot be completed).
Note that a Vault Administrator may see less of the issues in the vault than an ordinary user.
Reason
The error comes from the MS SQL server that hosts the vault database. It indicates that an M-Files assembly is not present and/or not trusted on that server.
The mfmssqlclrobjs.dll assembly is a CLR assembly by M-Files that needs to be allowed to run code on the SQL server.
Typically, the M-Files server handles that assembly for the server it adds the vault to, but in cases similar to the following ones, it may be unable to do that:
- There is a high-availability cluster of MS SQL servers - in this case it is likely that only one server got the M-Files assembly whitelisted, while the others also got the database - the MS SQL server high-availability does not replicate the assembly trust, only the database.
- The vault was set up without server administrator or database owner privileges on the M-Files account so it did not have the necessary privileges to perform the operation.
- The vault database was restored on a new server that an M-Files server has not created a vault on and has not whiltelisted the M-Files assembly.
When the database request is handled by a server that does not trust the assembly, you can get that error. If the error feels random, the most likely reason is that it does not happen on all units in the high-availability cluster.
This applies to MS SQL server versions 2017 and later which have the CLR assembly whitelisting feature, it does not apply to earlier versions.
Solution
To allow the MS SQL server to use the M-Files assembly, you need to whitelist it with an SQL command on every MS SQL server instance that serves the vault database. You can obtain the assembly from the M-Files Server installation folder. You can find more detailed instructions on the commands in section 1.2 "Adding Assembly Trusts (SQL Server 2017 and above)" of the following document: Setting M-Files to Operate Without Sysadmin Role in Microsoft SQL Server.pdf .
Also, make sure that the database owner in the MS SQL server(s) is the M-Files administrative vault user (the credentials you enter in the "Administrator credentials" section of the vault properties pertaining to the MS SQL connection). You can read more about this in the following article: Roles for MS SQL M-Files database.
To double check that the assembly is whitelisted, run the following commands:
use [Sample Vault] --replace with actual M-Files vault database name
go
select * from sys.assemblies
select * from sys.assembly_files
select * from sys.trusted_assemblies
You should see something like this
Notes
In the typical cases, the steps above let you confirm if the assembly whitelisting is done correctly, but you may still experience the issue.
We have seen this happen when the TRUSTWORTHY property is set to ON for the database.
You can check if it is on with a query like this:
SELECT name, trustworthy_setting =
CASE is_trustworthy_on
WHEN 1 THEN 'Trustworthy setting is ON'
ELSE 'Trustworthy setting is OFF'
END
FROM sys.databases
WHERE name LIKE '%My Vault%' -- replace the database name with the real database name
It does not need to be set to ON, so you should set it to OFF:
ALTER DATABASE [Sample Vault] SET TRUSTWORTHY OFF; -- replace the database name with the real database name
After that, monitor the background tasks for errors, you should see them progress and the errors should go away.
