I have developed in c# 2 applications. One ASP .NET web service and a WinForms client that uses the web service. The client is distributed to many customers. For one of these customers, suddenly the application started throwing the following exception:
External component has thrown an exception.
at System.Diagnostics.SharedPerformanceCounter.GetCounter(String counterName, String instanceName, Boolean enableReuse, PerformanceCounterInstanceLifetime lifetime)
at System.Diagnostics.SharedPerformanceCounter..ctor(String catName, String counterName, 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 section)
at System.Net.Configuration.SettingsSectionInternal.get_Section()
at System.Net.ServicePointManager.set_Expect100Continue(Boolean value)
at #Neh.#hgh.#P0f(String[] args)
The obfuscated (using SmartAssembly 5) function at the end of the exception, is client’s main function which is as follows
public static void Main(string[] args) {
try {
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
System.Net.ServicePointManager.Expect100Continue = false;
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Globals.Settings.NoWaitPrintJobs = true;
Application.Run(new frmMain());
}
catch(Exception ex) {
HandleUnhandledException(ex);
}
}
From the exception I understand that it is breaking at line
System.Net.ServicePointManager.Expect100Continue = false;
The application doesn’t reference any interop components, just other managed dlls. It’s also using a native function in shell32.dll
[DllImport("shell32.dll")]
static extern bool SHGetSpecialFolderPath(IntPtr hwndOwner, [Out] StringBuilder lpszPath, int nFolder, bool fCreate);
that is being called on main form load event from a static object.
Globals.Settings.InitLocalFiles();
I don’t know the customer’s computer specifications yet. I think he has Windows XP.
Any thoughts please?
Looks like the user account running the client doesn’t have the correct permissions, to use performance counters
see 'UnauthorizedAccessException' – 'Global\.net clr networking'
This makes the network classes not use the performance counters.