We have a windows application(.NET 3.0) that throws an exception when starting the application from the Visual Studio IDE. Below is the code in the App.xaml.cs
[System.Security.Permissions.
SecurityPermission(System.Security.Permissions.SecurityAction.Demand,UnmanagedCode=true)] public partial class App : System.Windows.Application{
public System.Collections.ObjectModel.ObservableCollection<AuthenticationService.RibbonControlClass> MainRibbonMenu; public InfraElements infraObj; public BlueTheme BlueTheme; public GenericXmlSecurityToken stsTokenCache; Mutex mutex; bool newMutexCreated = false; string mutexName = "Global\\BancAssuranceClient"; void OnApplicationStartUp(object sender, StartupEventArgs e){
try{
// Create a new mutex object with a unique namemutex =
new Mutex(false, mutexName, out newMutexCreated); if (newMutexCreated){
AuthenticationScreen win = new AuthenticationScreen();win.Show();
newMutexCreated =
true; App.Current.Exit += new ExitEventHandler(OnExiting);}
else{
MessageBox.Show("The application does not support Fast User Switching" + "\n\n" + "Application Exiting...", "Application Error", MessageBoxButton.OK, MessageBoxImage.Error); App.Current.Shutdown();}
}
catch (System.UnauthorizedAccessException ex){
LogWriter.WriteLogFile(ex);}
}
}
The exception encountered is "Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed." at the statement
string mutexName = "Global\\BancAssuranceClient";
which is not expected. Please help to fix this problem.