OnPreviewKeyDown requires UnmanagedCode SecurityPermission

G

Guest

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
 
L

Luke Zhang [MSFT]

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.)
 
G

Guest

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
 
L

Luke Zhang [MSFT]

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.)
 

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