Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to request app exit when ClickOnce is set to 'partial trust application'?

Tags:

.net

clickonce

If a .NET console application is built in the VisualStudio with project settings Security > Enable ClickOnce security settings > This is a partial trust application, the following ways to exit application throw SecurityException due to insufficient privileges because they cannot access the system environment:

  • Environment.Exit()
  • Environment.FailFast()
  • End statement (Visual Basic)

How to exit the application without running into this exception?

More details:

Exception message is: Message=Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed..

This is perfectly OK, as they obviously want to return an ErrorLevel, but the system environment is not accessible at that time. But do you know about any way to prematurely exit the application which does not attempt to access the environment and thus is able to exit without triggering the exception?

The only working way I found so far is to continue the execution to end of Main() where the application exits 'naturally'. But this sometimes adds unwanted code constructs. This is why I'm asking how to exit immediately.

Please, in this case let's not conclude by adding privileges to the application etc. Let's keep the application restricted as it is and find a way how to exit it. Does .NET offer some other way to exit the app instantly than the above three?

like image 842
miroxlav Avatar asked Nov 11 '22 22:11

miroxlav


1 Answers

did you try

Process.GetCurrentProcess().Kill()

or

AppDomain.Unload(AppDomain.CurrentDomain)

?

like image 110
avs099 Avatar answered Nov 15 '22 08:11

avs099