Home All Groups Group Topic Archive Search About

(paritially) trusted caller exception problem

Author
23 Mar 2006 11:07 AM
Michael Schöller
Hi,

I have created an simple example to show of my problem and hope that someone
could help me.


SecurityTest (Solution)
|
+---SecTest (Project, Console Application)
+---SecurityLib (Project, Library)
+---SecurityLib2(Project, Library)

SecTest (Referenz auf SecurityLib) macht nichts anderes als
using System;
using System.Collections.Generic;
using System.Text;
using SecurityLib;
namespace SecTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Test x = new Test();
            x.run();
        }
    }
}

the following lines are added to the AssemblyInfo.cs of SecurityLib and
SecurityLib2
    //Remove all Permissions from Assembly to Explizit set them with
RequestMinimum
    [assembly:
System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.RequestOptional,
Unrestricted = false)]

if I comment out the lines all is working fine, but i want to explizit allow
permissions with RequestMinimum

SecuityLib (reference to SecurityLib2) is implemented as
using System;
using System.Collections.Generic;
using System.Text;
using SecurityLib2;
namespace SecurityLib
{
    public class Test
    {
        private class InternalClass : Class1
        {
            int _x;
            public InternalClass(int x) : base()
            {
                _x = x;
            }
        }

        public void run()
        {
            int y = 0;
            y = 11;
            InternalClass ic = new InternalClass(y);
//<-----------------------Exception occurs
        }
    }
}

SecurityLib2 looks like
using System;
using System.Collections.Generic;
using System.Text;
namespace SecurityLib2
{
    public abstract class Class1
    {
    }
}

It's working if I AllowPartitialTrustedCallers in SecurityLib2, but I do not
want that for all classes.
The question is what's the permission to set (to RequestMinimum) so that the
code is working.
On my reallifeproject in the additional line in the AssemblyInfo.cs are
    [assembly:
System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.RequestOptional,
Unrestricted = false)]
    [assembly:
System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.RequestMinimum,
SerializationFormatter = true)]
    [assembly:
System.Net.SocketPermission(System.Security.Permissions.SecurityAction.RequestMinimum,
Unrestricted = true)]
but that has no impact on the problem itself.

Hope someone could help

Thanks
Mike

AddThis Social Bookmark Button