views:

436

answers:

2

I am using the embedded client/server version of db4o (I called OpenServer() instead of OpenFile() method) so that I can host an asp.net website that will have several users reading and writing to the database simultaneously. The only issue is that the webhost that we use is a medium trust environment so it's throwing an error stating that the assembly doesn't support partially trusted callers...

Wondering if anyone has any suggestions on how to get this to work. Thanks!

:: UPDATE ::

I have recompiled the db4o dll with the [AllowPartiallyTrustedCallers] attribute and now I am getting the following specific error:

System.TypeInitializationException was unhandled by user code Message="The type initializer for 'DataObjecten.db4oManager' threw an exception." TypeName="DataObjecten.db4oManager" InnerException: System.Security.SecurityException Message="Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed." Source="Db4objects.Db4o" StackTrace: at Db4objects.Db4o.Internal.Platform4.AddShutDownHook(PartialObjectContainer container) at Db4objects.Db4o.Internal.PartialObjectContainer.Initialize1(IConfiguration config) at Db4objects.Db4o.Internal.PartialObjectContainer.Open() at Db4objects.Db4o.Internal.IoAdaptedObjectContainer..ctor(IConfiguration config, String fileName) at Db4objects.Db4o.Internal.ObjectContainerFactory.OpenObjectContainer(IConfiguration config, String databaseFileName) at Db4objects.Db4o.Db4oFactory.OpenFile(IConfiguration config, String databaseFileName) at Db4objects.Db4o.Db4oFactory.OpenServer(IConfiguration config, String databaseFileName, Int32 port, INativeSocketFactory socketFactory) at Db4objects.Db4o.Db4oFactory.OpenServer(IConfiguration config, String databaseFileName, Int32 port) at DataObjecten.db4oManager..cctor() InnerException:

A: 

I don't know if this works, but you could try writing a wrapper DLL that has AllowPartiallyTrustedCaller set to true, and passes all calls to the db4o DLL.

Seeing as db4o is open source you could download and recompile with AllowPartiallyTrustedCaller set to true yourself of course.

This thread however suggests that that might not work.

samjudson
Hey Same, thanks for the response - Looking at the source for db4o I found that they are already compiling it with the APTC attribute on the dll's. Hmm... seems to have no effect. Maybe it's due to me using the client/server mode. I will try using the OpenFile() method instead of OpenServer() and see if I get the same security exception. If so, maybe i'll try your wrapper suggestion.
bbqchickenrobot
A: 

I've hit this problem as well and it does appear that db4o will not work in client/server mode in a medium trust web application environment.
This project for ASP.NET Providers using db4o seems to confirm this.
It states that db4o is reliant on reflection and unmanaged code which are both prohibited in medium trust.
I think your only hope to progress this would be to follow their suggestion and find a shared provider that allows you to run your code in full trust.
Very disappointing as I've enjoyed working with db4o and this has just scuppered several weeks of work.

Andy Rose
Indeed, db4o does depends on reflection (regarding unmanaged code, we used to depend directly on native code but we don't depend anymore).AFAIK (I am not a security expert), the APTC attribute should be enough to allow db4o to be used in medium trusted environments. Anyway, since we still have an open issue (http://tracker.db4o.com/browse/COR-51) related to this subject I'll discuss this in our next meeting.
Vagaus