The Software Artist | Code is a form of art.

Dec/09

30

Using NHibernate.Linq in medium trust

Here are some instructions for using the NHibernate.Linq functionality in the latest NHibernate trunk (3.0 alpha version) in medium trust.

Disclaimer: To use NHibernate.Linq in medium trust, we have to recompile the three re-motion assemblies that NHibernate references, adding the AllowPartiallyTrustedCallersAttribute to these assemblies so they can be used in a partial trust environment. As always, simply adding the APTCA attribute to the assembly does not guarantee that the code therein is safe for use in partial trust. Analysis of the re-motion assemblies with permcalc shows that there is quite a bit of code in these assemblies that demands permissions greater than what is allowed in the standard medium trust environment. I asked the re-motion developers what they thought about setting APTCA on their assemblies, you can read their favorable response here. Anyway, all of this is to say that using NHibernate.Linq with these recompiled re-motion assemblies could still possibly result in exceptions in partial trust, so be sure to test your code thoroughly if you try this. I updated the SharpArch Northwind sample app to use NHibernate.Linq and I did not have any problems.

  1. First, get the re-motion source from: https://svn.re-motion.org/svn/Remotion/trunk
  2. Read through the “How to build.txt” file, particularly the note about generating the key pair file. You might want to build the entire project from the command line just to make sure everything is set up correctly.
  3. Open Remotion.sln in Visual Studio. Add the following code:
      using System.Security;
      [assembly: AllowPartiallyTrustedCallers]
      

    to these files:

    • Core\Core.Core\Properties\AssemblyInfo.cs
    • Core\Core.Interfaces\Properties\AssemblyInfo.cs
    • Data\Data.Linq\Properties\AssemblyInfo.cs
  4. Build the Data.Linq project, which should force a build of Core.Core and Core.Interfaces as well.
  5. Copy Remotion.dll, Remotion.Interfaces.dll, and Remotion.Data.Linq.dll from trunk\Remotion\Data\Linq\bin\<config> to your NHibernate lib\net\3.5 directory, and rebuild NHibernate.
  6. The three re-motion assemblies and the new NHibernate.dll should be usable in medium trust now.

Happy partially trusted Linqing.

· ·

No comments yet.

Leave a Reply

<<

>>

Theme Design by devolux.nh2.me