fixing .net security exceptions when running from a network share or drive

March 15, 2012 — Leave a comment

there are lots of posts about using caspol to solve problems when running .net apps from a network drive or share.  e.g. http://blogs.msdn.com/b/shawnfa/archive/2004/12/30/344554.aspx.

the documentation at msdn is rather impenetrable: http://msdn.microsoft.com/en-us/library/ee191568(VS.100).aspx.  Apparently .Net 4.0 has totally changed the way all this works.

my situation is this:

  • fresh install of Windows 7 SP1, all patched up and running in a VirtualBox VM (64-bit);
  • Visual Studio 2010;
  • .Net 4.0;
  • all compilation happening through a VirtualBox shared  folder, which makes it looks like a network location; and
  • i’m compiling a large enterprise app which has to stay targeted at .net 3.5 for the time being.

since my apps are targeted at pre-.Net 4.0 frameworks, I’ll need to use caspol.exe to run anything on the shared folder, which is mapped to the network letter f:.

trying to apply advice from the sites linked above does not result in any immediate gratification.  After flailing about for a good 32 minutes, the 64-bit penny drops: security policy for 64-bit and 32-bit version of the framework are maintained separately!  If I had just read shawnfa’s blog post a little more carefully, I would have noticed that.

so make sure the version of caspol you are running comes from the right version of the framework. Doh!

32-bit: %windir%\Microsoft.Net\Framework\v2.0.50727\caspol.exe
62-bit: %windir%\Microsoft.Net\Framework64\v2.0.50727\caspol.exe

since everything is being developed on a mapped network drive f:, here are the final commands I used to ensure that  I can develop both 32- and 64-bit apps from that drive targeted at older .Net versions:

C:\Windows\Microsoft.NET\Framework>v2.0.50727\CasPol.exe -m -ag 1 -url file://F:\* FullTrust -n "F Drive"
C:\Windows\Microsoft.NET\Framework64>v2.0.50727\CasPol.exe -m -ag 1 -url file://F:\* FullTrust -n "F Drive"

 

ciao!

Advertisements

No Comments

Be the first to start the conversation!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s