The type initializer for 'MongoDB.Bson.ObjectId' threw an exception.

137 views
Skip to first unread message

CJ

unread,
Oct 29, 2011, 11:24:53 AM10/29/11
to mongodb-user
Hi :)

Recently i started developing a web app in which i use MongoDB and it
worked beautifully, that until i uploaded to my Windows Shared Hosting
where the security policy is set to "Medium Trust" and Asp.Net it
always gave me this error "[SecurityException: That assembly does not
allow partially trusted callers.]".

After some research and debugging i finally set my development server
with the same policy (Medium Trust), but in order to solve that error
i had to download the C# Driver source code and compile it again, but
this time adding the following lines to the "AssemblyInfo.cs" files of
the "Bson" and "Driver" classes.

using System.Security;
...
...
[assembly: AllowPartiallyTrustedCallers()]

Finally that error was gone "[SecurityException: That assembly does
not allow partially trusted callers.]", But now i'm getting this new
error "The type initializer for 'MongoDB.Bson.ObjectId' threw an
exception." and i have no idea what should be done in that case.

Any ideas ?

PS: C# .Net Driver's developers should consider adding those lines to
the next driver's version, or come up with some solution so that we
don't get those errors while running on Medium Trust .Net servers

Robert Stam

unread,
Oct 29, 2011, 6:51:15 PM10/29/11
to mongodb-user
We have not tested the C# driver in a Medium Trust environment. My
guess is that while adding the Assembly attribute allowed the assembly
to be loaded, the type initializer for ObjectId is still making some
operating system calls that are not permitted in a Medium Trust
environment.

I have created a JIRA issue to investigate whether the C# driver can
be made to run in a Medium Trust environment. See:

https://jira.mongodb.org/browse/CSHARP-348
Reply all
Reply to author
Forward
0 new messages