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");
}
}
}
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 14th, 2009 at 11:06 PM.
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
}
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 In theory, there is no difference between theory and paractice; 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
Bookmarks