Strange security issue in WinForms application

G

Guest

I have this WinForms application which is exhibiting a strange security issue.

The project contains a Form and a UserControl. The Form has a method which
populates data and an event from the UserControl. When I call the method
from the UserControl event it raises a SqlPermission exception. If I call
the method from any other method in the from (such as Form_Load) it works
fine.

I'm assuming the UserControl must have less rights assigned to it, but why?
It's embedded in the same project as the Form (and also embedded on the Form
itself). Incidentially, even if I grant the executable "FullTrust" it still
raises the exception from the UserControl event.

Does anyone know what's going on and why?
 
E

Ed Kaim

If the user control is in another assembly, that assembly must also have
required permissions to make the call. One option is to give the assembly
permission to make the call in question--or full trust if you're lazy :)

Alternatively, if you absolutely trust the user control assembly, the
calling EXE (which you've already given full trust to) can Assert
permissions before invoking the call. Check out
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconAssert.asp
for more info on how to do this.
 
G

Guest

What's strange is the UserControl is in the same assembly as the form (exe),
as I mentioned. FullTrust does not have any affect as I mentioned as well.
Incidentially, I'm using declartive LinkDemands instead of Asserts.

In any event, I'll figure it out eventually...
 

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