Red Gate forums :: View topic - Code Access Security problem after use SmartAssembly
Return to www.red-gate.com RSS Feed Available

Search  | Usergroups |  Profile |  Messages |  Log in  Register 
Go to product documentation
SmartAssembly 5
SmartAssembly 5 forum

Code Access Security problem after use SmartAssembly

Search in SmartAssembly 5 forum
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.
Jump to:  
Author Message
tannerel



Joined: 16 Sep 2010
Posts: 2

PostPosted: Thu Sep 16, 2010 9:31 am    Post subject: Code Access Security problem after use SmartAssembly Reply with quote

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 ?
Back to top
View user's profile Send private message
Brian Donahue



Joined: 23 Aug 2004
Posts: 6673

PostPosted: Fri Sep 17, 2010 3:10 pm    Post subject: Reply with quote

Hello Thomas,

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.
Back to top
View user's profile Send private message
tannerel



Joined: 16 Sep 2010
Posts: 2

PostPosted: Mon Sep 20, 2010 11:39 am    Post subject: Reply with quote

Dear,

It.s a WPF application.

Indeed we are listing to the unhandeld eventhandler.

Greetz
Thomas Annerel
Back to top
View user's profile Send private message
Brian Donahue



Joined: 23 Aug 2004
Posts: 6673

PostPosted: Mon Sep 20, 2010 2:29 pm    Post subject: Reply with quote

Hi Thomas,

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?
Back to top
View user's profile Send private message
Brian Donahue



Joined: 23 Aug 2004
Posts: 6673

PostPosted: Wed Sep 22, 2010 1:04 pm    Post subject: Reply with quote

Logically speaking, I think marking the method as Security-Critical may make this work.
Code:

[SecurityCriticalAttribute()]
RunInDebugMode(System.String[] myStringArray)
{
...
}


Are you sure this worked before processing with SmartAssembly?
Back to top
View user's profile Send private message
Brian Donahue



Joined: 23 Aug 2004
Posts: 6673

PostPosted: Tue Sep 28, 2010 4:18 pm    Post subject: Reply with quote

I think that we have come to a conclusion about this, and that is that upgrading a .NET assembly from runtime v2 to runtime v4 that has code access security applied needs to be re-evaluated before running it through SmartAssembly. Because the code access security model has changed, things like assembly attribute "AllowPartiallyTrustedCallers" stop working on protected assemblies and there is no "magic bullet" that will make SmartAssembly work when CASPOL has determined that a SmartAssembly code modification violates a policy.

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.
Back to top
View user's profile Send private message
Display posts from previous:   
This topic is locked: you cannot edit posts or make replies. All times are GMT + 1 Hour
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group