Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / March 2006

Tip: Looking for answers? Try searching our database.

OnPreviewKeyDown requires UnmanagedCode SecurityPermission

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
George Holdridge - 07 Mar 2006 16:08 GMT
I am creating a Winform app will be run over the Internet and I want to use
the default security profile for ClickOnce Internet apps.  This app has
custom controls that override the OnPreviewKeyDown method (necessary to get
access to arrow keys in the OnKeyDown method).  However, by just including an
empty OnPreviewKeyDown method in a control class, a security exception occurs
unless "UnmanagedCode" is added to the SecurityPermission class.  Is
OnPreviewKeyDown an unmanaged method, or am I missing something?

Thanks,
George
Luke Zhang [MSFT] - 08 Mar 2006 02:31 GMT
With .NET reflector, we can see the source code of OnPreviewKeyDown:

[EditorBrowsable(EditorBrowsableState.Advanced),
SecurityPermission(SecurityAction.InheritanceDemand,
Flags=SecurityPermissionFlag.UnmanagedCode),
SecurityPermission(SecurityAction.LinkDemand,
Flags=SecurityPermissionFlag.UnmanagedCode)]
protected virtual void OnPreviewKeyDown(PreviewKeyDownEventArgs e)
{
     PreviewKeyDownEventHandler handler1 = (PreviewKeyDownEventHandler)
base.Events[Control.EventPreviewKeyDown];
     if (handler1 != null)
     {
           handler1(this, e);
     }
}

So, I think "UnmanagedCode" is required here.  

Luke Zhang
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
George Holdridge - 08 Mar 2006 05:40 GMT
Luke,
Thank you for your reply.  While I don't (yet) understand how to use .NET
reflector, I'm not surprised that it indicates that UnmanagedCode is
required, as I deduced this from trial-and-error.  I guess my questions now
are:

1. Where is the fact that OnPreviewKeyDown is unmanaged documented?
2. Why is OnPreviewKeyDown unmanaged?
3. Are there other .NET classes/methods that are unmanaged?  If so, where is
this documented?

Again, I am creating Winform applications which can be run via ClickOnce
with default Internet permissions.  I am concerned that if unmanaged code
permission is required to run basic ClickOnce winform apps, it won't be
acceptable to my customers.
Thanks,
George Holdridge

> With .NET reflector, we can see the source code of OnPreviewKeyDown:
>
[quoted text clipped - 18 lines]
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
Luke Zhang [MSFT] - 09 Mar 2006 05:33 GMT
Hello,

To download .NET reflector:

http://www.aisto.com/roeder/dotnet/

This utility can help study more about class, properties and methods in
.NET framework. OnPreviewKeyDown is new in the .NET Framework version 2.0.
Its implementing may require unmanaged code (This is not document, but from
what I get from .NET reflector, "UnmanagedCode" permission is necessary
here).

Luke Zhang
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.