Microsoft KB Archive/327441

= FIX: &quot;System.Security.SecurityException&quot; Error Message Occurs When You Invoke a Method on a Transparent Proxy =

Article ID: 327441

Article Last Modified on 5/28/2003

-

APPLIES TO


 * Microsoft .NET Framework 1.1
 * Microsoft .NET Framework 1.0

-



This article was previously published under Q327441



SYMPTOMS
When a method is called through an interface on a transparent proxy, you may get the following error message:

An unhandled exception of type 'System.Security.SecurityException' occurred in TestClass.exe

Additional information: System.Security.Permissions.SecurityPermission

This error message occurs although the permission is not required.



RESOLUTION
To resolve this problem, you can use an abstract class instead of an interface.



STATUS
This bug was corrected in .NET Framework (2003|1.1).



Steps to Reproduce the Behavior
 Create a new Microsoft C# Console Application and name it TestClass .  Paste the following code to the Class1.cs file: using System; using System.Reflection; using System.Security.Permissions;

// To refuse the UnmanagedCode permission [assembly: SecurityPermission(SecurityAction.RequestRefuse, UnmanagedCode=true)]

interface ITest {   void Test; }

class TestClass: MarshalByRefObject, ITest {   public static void Main(String[] args) {       AppDomain ad = AppDomain.CreateDomain(&quot;NewDomain&quot;, null, null);

TestClass proxy = (TestClass)ad.CreateInstance(&quot;TestClass&quot;, &quot;TestClass&quot;).Unwrap;

ITest i = proxy as ITest; i.Test; }   public void Test {       Console.WriteLine(&quot;Test&quot;); } }                    Compile the code and then run the code. The SecurityException is thrown.  You can use the following code sample to demonstrate the use of an &quot;abstract class&quot;, which resolves this problem: using System; using System.Reflection; using System.Security.Permissions;

// To refuse the UnmanagedCode permission [assembly: SecurityPermission(SecurityAction.RequestRefuse, UnmanagedCode=true)]

abstract class CTest : MarshalByRefObject {   public abstract void Test; }

class TestClass: CTest {   public static void Main(String[] args) {       AppDomain ad = AppDomain.CreateDomain(&quot;NewDomain&quot;, null, null);

TestClass proxy = (TestClass)ad.CreateInstance(&quot;TestClass&quot;, &quot;TestClass&quot;).Unwrap;

CTest i = proxy as CTest; i.Test; }   public override void Test {       Console.WriteLine(&quot;Test&quot;); } }                   

Keywords: kbbug kbfix kbremoting kbpending KB327441

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.