.net - .net 4.0 security model framework v2 and v4 compatibility issues

 

the .net framework has a new security model which is quit different from its ancestor/predecessor/forerunner/antecessor/forebearer....

 

 

In a simple word, every application running from places other than local then it is not trusted. and the caspol does not work anymore.

 

<configuration>
   <runtime>
      <loadFromRemoteSources enabled="true"/>
   </runtime>
</configuration>
 

 

 

.NET 4.0 doesn't have CasPol?. If you are running a non-hosted application (launching an exe), it'll be full-trusted, no-matter from where you started it. Sandboxing of assemblies is possible if they are loaded into an explicit host application (office, iis, etc...). If the exe is full-trusted, it wouldn't be safe to load an assembly from the network (afs) without limiting its permissions, that's why it throws this exception.

 

http://msdn.microsoft.com/en-us/magazine/ee677170.aspx

 

You can also enable the caspol settings. and relying on the dist benig full-trusted by default:

 

<configuration>
   <runtime>
      <NetFx40_LegacySecurityPolicy enabled="true"/>
   </runtime>
</configuration>
 

 

 

Without doing so , you may end up having the following error: 

 

An attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed in previous versions of the .NET Framework. This release of the .NET Framework does not enable CAS policy by default, so this load may be dangerous. If this load is not intended to sandbox the assembly, please enable the loadFromRemoteSources switch. See http://go.microsoft.com/fwlink/?LinkId=155569 for more information.
 

 

Loading mixed mode or managed c++ assemblies fails

 

 

You may need to do this: 

 

<startup useLegacyV2RuntimeActivationPolicy="true">
  <supportedRuntime version="v4.0"/>
</startup>
 

 

.NET 4.0 changed the runtime activation policy. Mixed mode and managed c++ assemblies are built with earlier versions of .NET cannot be loaded without the configuration snippet above.

 

http://blogs.msdn.com/b/clrteam/archive/2010/06/23/in-proc-sxs-and-migration-quick-start.aspx

http://msdn.microsoft.com/en-us/magazine/ee819091.aspx

你可能感兴趣的:(.net)