Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'UnauthorizedAccessException' - 'Global\.net clr networking'

Tags:

.net

security

I'm testing my application under the user Guest. It crashes with the following error.

'UnauthorizedAccessException' - 'Global.net clr networking'

Now, I know I can edit the security policy on the machine to allow CLR code running under guest to be trusted, but what should one do on a commercial app?

(Sign, and add CAS attributes?) I'm currently reading the whole security section, but I'm in a time pinch, so any pointers in the right direction will be appreciated.

EDIT: I've traced the problem to using the class Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase. If this is included, the error appears. I'm looking for something to add to the manifest or some other way so that when the application is installed/run, it will ask for the appropriate permissions. I don't want to have to ask the user to personally call caspol or some other tool.

Environment Details: - App is using .NET 3.0 - OS is Vista

Here's the relevant stack trace for those into these things:

Unhandled Exception: System.UnauthorizedAccessException: Access to the path 'Glo
bal\.net clr networking' is denied.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.Threading.Mutex.<>c__DisplayClass3.<.ctor>b__0(Object userData)
   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCl
eanup(TryCode code, CleanupCode backoutCode, Object userData)
   at System.Threading.Mutex..ctor(Boolean initiallyOwned, String name, Boolean&
 createdNew, MutexSecurity mutexSecurity)
   at System.Diagnostics.SharedUtils.EnterMutexWithoutGlobal(String mutexName, M
utex& mutex)
   at System.Diagnostics.SharedPerformanceCounter.Verify(CategoryEntry* currentC
ategoryPointer)
   at System.Diagnostics.SharedPerformanceCounter.FindCategory(CategoryEntry** r
eturnCategoryPointerReference)
   at System.Diagnostics.SharedPerformanceCounter.GetCounter(String counterName,
 String instanceName, Boolean enableReuse, PerformanceCounterInstanceLifetime li
fetime)
   at System.Diagnostics.SharedPerformanceCounter..ctor(String catName, String c
ounterName, String instanceName, PerformanceCounterInstanceLifetime lifetime)
   at System.Diagnostics.PerformanceCounter.Initialize()
   at System.Diagnostics.PerformanceCounter.set_RawValue(Int64 value)
   at System.Net.NetworkingPerfCounters.Initialize()
   at System.Net.Configuration.SettingsSectionInternal..ctor(SettingsSection sec
tion)
   at System.Net.Configuration.SettingsSectionInternal.get_Section()
   at System.Net.Sockets.Socket.InitializeSockets()
   at System.Net.Sockets.Socket.get_SupportsIPv4()
   at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.get_
HostName()
   at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Regi
sterChannel(Boolean SecureChannel)
   at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(
String[] commandLine)
like image 791
moogs Avatar asked May 25 '09 04:05

moogs


1 Answers

Is it possible to add this to your app.config file?

<configuration>
   <system.net>
      <settings>
         <performanceCounters enabled="false" />
      </settings>
   </system.net>
</configuration>

This will direct the networking classes to not try to create performance counters which doesn't work under the Guest account.

The above setting shsould work in .NET Framework 4 and higher but due to a bug fails in in earlier versions.

like image 185
Matt Ellis Avatar answered Sep 20 '22 06:09

Matt Ellis