Hi,
I found that I am able to reproduce this error under medium trust hosting, but previously it worked fine so I'm suspecting that some Windows Update may have changed things.
I did find that we have version 4.0.8402.1 of SQL Ce dlls, so I updated to the newer version 4.0.8482.1 on my local machine, but the problem still persists under Medium Trust. With Full Trust it works correctly.
I have emailed my contacts at Microsoft to find out if they can help. The full error details are:
An unhandled exception occurred and the process was terminated.
Application ID: /LM/W3SVC/1/ROOT
Process ID: 5488
Exception: System.TypeInitializationException
Message: The type initializer for 'System.Data.SqlServerCe.SqlCeConnection' threw an exception.
StackTrace: at System.Data.SqlServerCe.SqlCeConnection.Finalize()
InnerException: System.TypeInitializationException
Message: The type initializer for 'System.Data.SqlServerCe.KillBitHelper' threw an exception.
StackTrace: at System.Data.SqlServerCe.KillBitHelper.ThrowIfKillBitIsSet()
at System.Data.SqlServerCe.SqlCeParameter..cctor()
InnerException: System.InvalidOperationException
Message: Cannot perform CAS Asserts in Security Transparent methods
StackTrace: at System.Security.CodeAccessSecurityEngine.CheckNReturnSO(PermissionToken permToken, CodeAccessPermission demand, StackCrawlMark& stackMark, Int32 create)
at System.Security.CodeAccessSecurityEngine.Assert(CodeAccessPermission cap, StackCrawlMark& stackMark)
at System.Security.CodeAccessPermission.Assert()
at System.Data.SqlServerCe.KillBitHelper.GetKillBit()
at System.Data.SqlServerCe.KillBitHelper..cctor()
As far as your comments about trying to handle this error, we do check if we can connect to the database, if we can alter the schema etc, but this error happens before that, just in trying to create a connection, the error is not happening in mojoPortal code it happens in the SQL CE dlls and it only happens under partial trust hosting.
I will post again if I find a solution. For now I would see if you can get full trust hosting if you want to try mojoPortal with SQL CE.
Best,
Joe