assembly security/permission question

G

Guest

Hi;

I have a library DLL and in my AssemblyInfo.cs I want the permissions to say
that the dll does not ever call the file dialogs. But I do NOT want to stop
other parts of any program that connect to my library from using the file
dialogs.

And my library will call delegates in the programs that use it and so those
other programs will be called from my dll.

So, is this the right way to specify it?

[assembly:FileDialogPermission(SecurityAction.RequestRefuse)]
 
P

Peter Huang [MSFT]

Hi

Is this what you want?

[DLL]
[assembly:
FileDialogPermission(SecurityAction.RequestRefuse,Unrestricted=true)]
public class TestClass
{
public OpenFileDialog openFileDialog1 = new OpenFileDialog();
public void ShowFileDialog()
{
openFileDialog1.ShowDialog();
openFileDialog1.OpenFile(); //Failed due to security
}
}

[Form client]
TestClass tc = new TestClass();

private void button1_Click(object sender, System.EventArgs e)
{
tc.ShowFileDialog();//failed
}
private void button2_Click(object sender, System.EventArgs e)
{
tc.openFileDialog1.ShowDialog();
tc.openFileDialog1.OpenFile(); //Succeed.
}

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

No - my question is if I put
[assembly:
FileDialogPermission(SecurityAction.RequestRefuse,Unrestricted=true)]

in the assembly of a DLL, and that DLL has an event other DLLs subscribe to
- when that event fires does the above restriction stop the delegates in
other events from calling a FileDialog?

Because all I want to do in the assembly is say my dll does not call
FIleDialog - but that it is fine for other dlls that it calls via an event to
call it.
 
P

Peter Huang [MSFT]

Hi David,

A common event works as below.
public OpenFileDialog openFileDialog1 = new OpenFileDialog();
public delegate void TestDelegate();
public event TestDelegate TestEvent;
public void RaiseEvent()
{
TestEvent();
}

If we want to use the event, we need use the RaiseEvent to fire the event.

private void button3_Click(object sender, System.EventArgs e)
{
tc.RaiseEvent();
}

private void Form1_Load(object sender, System.EventArgs e)
{
tc.TestEvent+=new
FileDialogPermissionClassLibrary.TestClass.TestDelegate(tc_TestEvent);
}

private void tc_TestEvent()
{
tc.openFileDialog1.ShowDialog();
tc.openFileDialog1.OpenFile();
}

Then when the tc_TestEvent, the RaiseEvent is on the call stack which do
not have the right permission.

If I misunderstand, can you post a simple reproduce code to show your
scenario.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top