Code Access Security problem after use SmartAssembly
tannerel
Posts: 3
Dear after using smart assembly on a .NET 4.0 project we get following error :
Attempt by security transparent method 'SDWorx.GO.BBX.Client.Shell.App.RunInDebugMode(System.String[])' to access security critical method 'System.AppDomain.add_UnhandledException(System.UnhandledExceptionEventHandler)' failed.
Assembly 'SDWorx.GO.BBX.Client.Shell, 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.
Can we fix this ?
Attempt by security transparent method 'SDWorx.GO.BBX.Client.Shell.App.RunInDebugMode(System.String[])' to access security critical method 'System.AppDomain.add_UnhandledException(System.UnhandledExceptionEventHandler)' failed.
Assembly 'SDWorx.GO.BBX.Client.Shell, 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.
Can we fix this ?
Comments
Admittedly I don't have a lot of experience with code access policy, but from what I understand, you have an assembly that calls SDWorx.GO.BBX.Client.Shell, or you have embedded 'SDWorx.GO.BBX.Client.Shell in your SA-protected assembly. You are probably using exception handling in the SA Project, and this is implementing an unhandled exception handler.
The error message itself seems to be new to .NET 4 because of a change in the security model. If this is a web application, you can add this line to web.config under System.Web:<trust legacyCasModel = "True" level="Full" />. If this is not a web application, please let me know.
It.s a WPF application.
Indeed we are listing to the unhandeld eventhandler.
Greetz
Thomas Annerel
I tried to reproduce this, but it's not happening. Using VS2010, I create a WPF application and implement an unhandled exception handler right before InitializeComponent and the assembly runs without incident. If I throw an exception, the SA dialogue displays.
I'm at a loss. Can you please send the assembly(ies) to support@red-gate.com?
Are you sure this worked before processing with SmartAssembly?
You can either use v4 security attribues or v2 security attributes, but using v2 attributes and then trying to run the assembly in v4 will cause problems.