views:

97

answers:

1

Assembly 'Foo.BAL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is marked with the AllowPartiallyTrustedCallersAttribute, and uses the level 2 security transparency model. Level 2 transparency causes all methods in AllowPartiallyTrustedCallers assemblies to become security transparent by default, which may be the cause of this exception.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

I have a standard Business Layer calling into my Data Access Layer, why am I getting this error with MVC 2 and .NET 4.0?

I was using the Enterprise Block, so I ditched it and am now just using standard System.Data.SqlClient APIs to minimize dependencies.

EDIT: If I change the Target Framework on my BAL and DAL projects to 3.5 I do not get the error.

+1  A: 

The security model changed pretty dramatically between .NET 3.5 and .NET 4.

http://msdn.microsoft.com/en-us/library/dd233103.aspx

Brad Wilson
Yes, I have read up on this. My understanding is that by default this error should not be happening. Is is MVC2(built on 3.5 sp1) or my BAL and or DAL library for data-access that is causing the problem?
rick schott
It sounds like the BAL is what's to blame here. What happens is that the CLR knows whether an assembly is built against CLR 2 or CLR 4, and applies the appropriate security policies. MVC is built against CLR 2, so it uses security level 1. If your BAL is built against CLR 4, then it's using security level 2 by default (you can change it with an assembly level attribute). It doesn't really matter that they're in the same app together.
Brad Wilson