-
January 14th, 2009, 05:29 PM
#1
C#/ WPF App - System.Security.SecurityException was unhandled by user code
I've created a WPF applicaiton in VS2008. (.NET 3.5) It's a simple application that has a button in the browser. Once the button is clicked, an sms text is supposed to be sent to a phone number via the skype API. However, I get the "System.Security.SecurityException was unhandled by user code" message. Any thoughts as to how to get around the error?
Here's the code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace GenevaText
{
/// <summary>
/// Interaction logic for Page1.xaml
/// </summary>
public partial class Page1 : Page
{
public Page1()
{
InitializeComponent();
}
//User presses button to send a sms message to the appropriate phone number
private void btnTestMsg_Click(object sender, RoutedEventArgs e)
{
SKYPE4COMLib.SkypeClass objSkype = new SKYPE4COMLib.SkypeClass();
objSkype.SendSms("3125551212", "test message", "3125551111");
}
}
}
-
January 15th, 2009, 12:02 AM
#2
Re: C#/ WPF App - System.Security.SecurityException was unhandled by user code
You have a permissions issue because the WPF app is operating within the security context of the browser. By default this prevents you from accessing COM objects.
Last edited by Arjay; January 15th, 2009 at 12:06 AM.
-
January 15th, 2009, 10:48 AM
#3
Re: C#/ WPF App - System.Security.SecurityException was unhandled by user code
Thanks for your reply. Any way around that?
-
January 16th, 2009, 02:53 AM
#4
Re: C#/ WPF App - System.Security.SecurityException was unhandled by user code
Post the whole exception, especialy the exception's message.
- Make it run.
- Make it right.
- Make it fast.
Don't hesitate to rate my post.
-
January 16th, 2009, 11:01 AM
#5
Re: C#/ WPF App - System.Security.SecurityException was unhandled by user code
Here's the entire exception...Thanks!!
System.Security.SecurityException was unhandled by user code
Message="System.Security.Permissions.SecurityPermission"
Source="GenevaText"
StackTrace:
at GenevaText.Page1.btnTestMsg_Click(Object sender, RoutedEventArgs e)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
at System.Windows.Controls.Primitives.ButtonBase.OnClick()
at System.Windows.Controls.Button.OnClick()
at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
at System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object sender, MouseButtonEventArgs e)
at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
at System.Windows.UIElement.CrackMouseButtonEventAndReRaiseEvent(DependencyObject sender, MouseButtonEventArgs e)
at System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e)
at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
at System.Windows.Input.InputManager.ProcessStagingArea()
at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)
at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.Run()
at System.Windows.Application.RunDispatcher(Object ignore)
at System.Windows.Application.StartDispatcherInBrowser(Object unused)
InnerException:
-
January 16th, 2009, 04:58 PM
#6
Re: C#/ WPF App - System.Security.SecurityException was unhandled by user code
Put a try/catch block around the COM call:
Code:
try
{
SKYPE4COMLib.SkypeClass objSkype = new SKYPE4COMLib.SkypeClass();
objSkype.SendSms("3125551212", "test message", "3125551111");
}
catch( Exception e )
{
// Look at the exception here in a debugger
}
-
January 16th, 2009, 07:21 PM
#7
Re: C#/ WPF App - System.Security.SecurityException was unhandled by user code
Right click your project, go to properties, and click on the security tab and click "This is a full trust application"
-
January 16th, 2009, 11:09 PM
#8
Re: C#/ WPF App - System.Security.SecurityException was unhandled by user code
Originally Posted by Traps
Right click your project, go to properties, and click on the security tab and click "This is a full trust application"
That will have the wonderful effect of totally preventing the program from loading into the browser on most client machines, unless they shut down security.
A much better approach is to have a WebService that is configured to do the SMS work. Then the browsfer based WPF application can just make a safe call to the webservice.
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|