mahalax

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 name

mutex = 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.




Re: Common Language Runtime SecurityException when running a Windows Application

Martin Xie - MSFT

This is a code access security exception. I don¡¯t think it should occur on a string assignment statement.

You can try to run the application outside Visual Studio IDE.

Does your project (or the output folder) stay on a network file share (which frequently occurs with roaming user profile)

If you copy the output EXE to a simple folder like ¡°C:\¡± and run it directly, still get the exception






Re: Common Language Runtime SecurityException when running a Windows Application

mahalax

Yes, I do not get the exception.