Subscribe | Alerts via Email
View All Quotes
“If you can't explain something to a six-year-old, you really don't understand it yourself.”
-Unknown
<February 2012>
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
26272829123
45678910
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

©2012 Cal Zant
Sign In
Total Posts: 107
This Year: 0
This Month: 0
This Week: 0
Comments: 0

I use .netTiers as my data access and business logic layers in some of my web applications, and recently started using it on one that is hosted on a server I don't have access to.  .netTiers is based on the Enterprise Library, but allows you to choose which version you want to target.  I am targeting the latest version, Enterprise Library 3.1 (May 2007 release).  My application built and seemed to be working fine on my local machine, but when I tried to move the code out to the hosted server I got an error saying:

Security Exception
That assembly does not allow partially trusted callers.

After a little research, I figured out that the Enterprise Library runs at the "full" trust level out of the box, which is more than the company hosting my application would allow.  Like most major hosting services, they only allow applications to run under "medium" trust ... which is actually a good thing because it isolates your application from others that may be running on the same machine.  Medium trust applications also have no registry access, no event log access, no ability to use reflection, and file system access is limited to the application's virtual directory.

Fortunately, I did find a few "hacks" out there that allowed me to modify the library to run in "medium" trust environments.  I eventually built some new dll's for the Enterprise Library that I used to replace the ones in my application.  Even though the process was a little painful, I finally got it to work.  To save you from going through the same hassle, the link below will allow you to download the customized, medium trust dll files I built.  I bet if you are having a similar problem that the one I described, you can probably just copy the dll's you need over the ones currently in your application.

App Blocks bin Folder.zip (1.12 MB)

To generate those dll's I followed the steps listed below, which are a condensed version I found in this article.

  1. If you don't already have the Enterprise library installed, download and install the Enterprise Library 3.1 (May 2007 release).
  2. Make a complete copy of the EntLibSrc Enterprise Library 3.1 source code folder, and rename it to something like EntLibSrc-PartialTrust.
  3. Go to http://www.codeplex.com/ObjectBuilder/Release/ProjectReleases.aspx?ReleaseId=1613, download ObjectBuilder-1.0.51206.0-source.zip, and unzip it.
  4. Open the solution ObjectBuilder.sln from the root of your ObjectBuilder folder in Visual Studio 2005.
  5. Open the file AssemblyInfo.cs from the Properties folder of the ObjectBuilder project and add the line "[assembly: AllowPartiallyTrustedCallers()]" to the end of the code. (You'll also have to add a reference to the System.Security namespace).
  6. Right-click on the ObjectBuilder project in Solution Explorer and click Rebuild.
  7. Copy Microsoft.Practices.ObjectBuilder.dll from the EntLibSrc-PartialTrust\ObjectBuilder\ObjectBuilder\bin\Debug folder to the Enterprise Library folder EntLibSrc-PartialTrust\App Blocks\Lib, replacing the original signed version of the assembly.
  8. Open the solution EnterpriseLibrary.sln from the folder EntLibSrc-PartialTrust\App Blocks into Visual Studio 2005, and hit CTRL+SHIFT+H to open the "Find and Replace" dialog.  Set the following values:
    • Find what: <Reference Include="Microsoft.Practices.ObjectBuilder, Version=1.0.51206.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
    • Replace with: <Reference Include="Microsoft.Practices.ObjectBuilder, Version=1.0.51206.0, Culture=neutral, PublicKeyToken=null, processorArchitecture=MSIL">
    • Look in: [path]\EntLibSrc-PartialTrust (the full path to your copy of the Enterprise Library source files)
    • Include sub-folders: Yes (checked)
    • Look at these file types: *.csproj
  9. Click Replace All, and the matching files are modified.  VS will give you a few prompts, but just click "Reload" (and maybe "Discard" once) until there are no more alerts.  Click "Save All" from the File menu.
  10. Right-click on the Enterprise Solution entry at the top of the Solution Explorer window and click Rebuild.
  11. Navigate to the EntLibSrc-PartialTrust\App Blocks folder in Windows Explorer and double-click the batch file named BuildLibraryAndCopyAssemblies.bat.
  12. Copy the assemblies you need from the EntLibSrc-PartialTrust\App Blocks\Bin folder into your application's Bin folder.
Thursday, October 18, 2007 6:26:43 PM (Central Standard Time, UTC-06:00)  #