Bug 55672 - System.Runtime.InteropServices.RuntimeEnvironment.SystemConfigurationFile behaves unstable
Summary: System.Runtime.InteropServices.RuntimeEnvironment.SystemConfigurationFile beh...
Status: RESOLVED DUPLICATE of bug 53461
Alias: None
Product: Class Libraries
Classification: Mono
Component: System ()
Version: 4.8.0 (C9)
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-04-27 07:27 UTC by Igor Botov
Modified: 2017-04-27 08:45 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Sample app, running script, built sample app, logs (3.09 MB, application/zip)
2017-04-27 07:27 UTC, Igor Botov
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED DUPLICATE of bug 53461

Description Igor Botov 2017-04-27 07:27:50 UTC
Created attachment 21836 [details]
Sample app, running script, built sample app, logs

Hello,


We struggle with weird bug related to system configuration initialization. According our observations System.Runtime.InteropServices.RuntimeEnvironment.SystemConfigurationFile behaves unstable. Normally, in our configuration, it returns: "/mono/4.5/machine.config"

But, occationally it returns values that seem random. Please check out list of values below.

We prepared sample app and bash script for running it for the issue demonstration.

What sample app does? 
1. Actively waits till "SystemConfigurationFile" is not empty.
2. Once it became non-empty just prints print it into std output using Console.Writeline.
3. Terminates itself.

What running script does?
In a loop, starts sample app process, waits till it's done and starts it again. It's necessary as a bug has low rate of reproduction.

I recommend to try it by yourself. Make sure both files - test.app and testing.sh are located in the same directory. Run testing script in terminal:
./testing.sh. 

You can stop testing by using Ctrl+C key combination.

Please check out log.txt which was genereated by the testing script on our mac book pro with yours script output.

Configuration of MacBook used:
Model Identifier:	MacBookPro8,1
System Version:	macOS 10.12.4 (16E195)
Kernel Version:	Darwin 16.5.0

Motivation
System.Runtime.InteropServices.RuntimeEnvironment.SystemConfigurationFile is pretty base thing in our opinion. It affects our app behaviour in at least two ways. Two components that we use deal with it under the hood.  System.Diagnostics.TraceSource for instance - it does lazy initialization of system configuration. When System.Runtime.InteropServices.RuntimeEnvironment.SystemConfigurationFile is empty string we are getting app crashed due to following exception: 
System.Configuration.ConfigurationErrorsException: Error Initializing the configuration system. ---> System.Configuration.ConfigurationErrorsException: Unrecognized configuration section <appSettings> (/Applications/Workplace.app/Contents/MonoBundle/Workplace.exe.config line 2). See full stack trace below.

This is really wired, hard to reproduce bug. Another component that occationaly thrown same exception is ServicePointManager. Maybe there are others.

As tracer is a base component in our app arhitecture - we use it in many places, we do not consider keeping app working with the tracer broken, so that when the issue is reproduced our app is getting terminated. This provides poor user experience and makes really negative impact on our business.

List of values returned
1.
(`

rD0,
   .

Z/mono/4.5/machine.config

2. 
S/mono/4.5/machine.config
3. 
com.apple.LaunchServices.database/mono/4.5/machine.config
4.
eservices.launchservices.session.100480/mono/4.5/machine.config
5.
RRRGGGGGGGGBBBBBBBB/mono/4.5/machine.config
6.
(`

rD0,
   .

Z/mono/4.5/machine.config
7.
eservices.launchservices.session.100480/mono/4.5/machine.config
8.
ry/Frameworks/AppKit.framework/AppKit/mono/4.5/machine.config
9.
RRRGGGGGGGGBBBBBBBB/mono/4.5/machine.config
10.
com.apple.LaunchServices.database/mono/4.5/machine.config
11.
ry/Frameworks/AppKit.framework/AppKit/mono/4.5/machine.config
12.
ry/Frameworks/AppKit.framework/AppKit/mono/4.5/machine.config
13.
RRRGGGGGGGGBBBBBBBB/mono/4.5/machine.config
14.
P?D?D?D?D?onfig_dir C
D
A
A

P?D?D?D?D?g_new C
D
A
A
 /mono/4.5/machine.configmono


System.Configuration initialization failes with following exception if System.Runtime.InteropServices.RuntimeEnvironment.SystemConfigurationFile returns empty string:

[ERROR] FATAL UNHANDLED EXCEPTION: System.Configuration.ConfigurationErrorsException: Error Initializing the configuration system. ---> System.Configuration.ConfigurationErrorsException: Unrecognized configuration section <appSettings> (/Applications/Workplace.app/Contents/MonoBundle/Workplace.exe.config line 2)
  at System.Configuration.ConfigInfo.ThrowException (System.String text, System.Xml.XmlReader reader) [0x00007] in <c88268b2ab694baf8f53384cac3b8843>:0 
  at System.Configuration.SectionGroupInfo.ReadContent (System.Xml.XmlReader reader, System.Configuration.Configuration config, System.Boolean overrideAllowed, System.Boolean root) [0x00170] in <c88268b2ab694baf8f53384cac3b8843>:0 
  at System.Configuration.SectionGroupInfo.ReadRootData (System.Xml.XmlReader reader, System.Configuration.Configuration config, System.Boolean overrideAllowed) [0x00007] in <c88268b2ab694baf8f53384cac3b8843>:0 
  at System.Configuration.Configuration.ReadConfigFile (System.Xml.XmlReader reader, System.String fileName) [0x0
00ec] in <c88268b2ab694baf8f53384cac3b8843>:0 
  at System.Configuration.Configuration.Load () [0x00052] in <c88268b2ab694baf8f53384cac3b8843>:0 
  at System.Configuration.Configuration.Init (System.Configuration.Internal.IConfigSystem system, System.String configPath, System.Configuration.Configuration parent) [0x00065] in <c88268b2ab694baf8f53384cac3b8843>:0 
  at System.Configuration.Configuration..ctor (System.Configuration.InternalConfigurationSystem system, System.String locationSubPath) [0x0005c] in <c88268b2ab694baf8f53384cac3b8843>:0 
  at System.Configuration.Configuration..ctor (System.Configuration.InternalConfigurationSystem system, System.String locationSubPath) [0x0003b] in <c88268b2ab694baf8f53384cac3b8843>:0 
  at System.Configuration.InternalConfigurationFactory.Create (System.Type typeConfigHost, System.Object[] hostInitConfigurationParams) [0x0000e] in <c88268b2ab694baf8f53384cac3b8843>:0 
  at System.Configuration.ConfigurationManager.OpenExeConfigurationInternal (System.Configuration.Con
figurationUserLevel userLevel, System.Reflection.Assembly calling_assembly, System.String exePath) [0x00107] in <c88268b2ab694baf8f53384cac3b8843>:0 
  at System.Configuration.ClientConfigurationSystem.get_Configuration () [0x00011] in <c88268b2ab694baf8f53384cac3b8843>:0 
   --- End of inner exception stack trace ---
  at System.Configuration.ClientConfigurationSystem.get_Configuration () [0x00030] in <c88268b2ab694baf8f53384cac3b8843>:0 
  at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection (System.String configKey) [0x00000] in <c88268b2ab694baf8f53384cac3b8843>:0 
  at System.Configuration.ConfigurationManager.GetSection (System.String sectionName) [0x00005] in <c88268b2ab694baf8f53384cac3b8843>:0 
  at System.Configuration.PrivilegedConfigurationManager.GetSection (System.String sectionName) [0x00000] in <3e82dae62cf64eb0b1556e80593c6b2e>:0 
  at System.Diagnostics.DiagnosticsConfiguration.GetConfigSection () [0x00000] in <3e82dae62cf64eb0b1556
e80593c6b2e>:0 
  at System.Diagnostics.DiagnosticsConfiguration.Initialize () [0x00033] in <3e82dae62cf64eb0b1556e80593c6b2e>:0 
  at System.Diagnostics.DiagnosticsConfiguration.get_Sources () [0x00000] in <3e82dae62cf64eb0b1556e80593c6b2e>:0 
  at System.Diagnostics.TraceSource.Initialize () [0x0002b] in <3e82dae62cf64eb0b1556e80593c6b2e>:0 
  at System.Diagnostics.TraceSource.TraceEvent (System.Diagnostics.TraceEventType eventType, System.Int32 id, System.String message) [0x00000] in <3e82dae62cf64eb0b1556e80593c6b2e>:0 
  at OS33.Mac.Logging.Tracer.Trace (System.Diagnostics.TraceEventType type, System.String message) [0x00010] in <8175ee0992684a48a30aacfaf4b4ecb5>:0 
  at OS33.Mac.Logging.Tracer.TraceError (System.String message) [0x00000] in <8175ee0992684a48a30aacfaf4b4ecb5>:0 
  at OS33.Mac.OsXComponents.OsXSystemService.CreateLoginItemsService () [0x0002d] in <1e225e31696a43a7993bedb7ae558cba>:0 
  at System.Lazy`1[T].CreateValue () [0x00075] in <f907cb1a62cf4887ae8c2f003ce661d7>:0 

Value of System.Runtime.InteropServices.RuntimeEnvironment.SystemConfigurationFile

Toolchain used:
Xamarin Studio Community
Version 6.3 (build 863)
Installation UUID: 9fcdda2d-e1ce-4dcf-bf42-1fc9781bb5d0
Runtime:
	Mono 4.8.1 (mono-4.8.0-branch/22a39d7) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 408010000

NuGet
Version: 3.5.0.0

Xamarin.Profiler
Version: 1.4.0
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

Xamarin.Android
Not Installed

Apple Developer Tools
Xcode 8.3.2 (12175)
Build 8E2002

Xamarin.iOS
Xamarin.iOS not installed.
Can't find mtouch or the Version file at /Library/Frameworks/Xamarin.iOS.framework/Versions/Current.

Xamarin.Mac
Version: 3.2.0.175 (Xamarin Studio Community)

Xamarin Inspector
Not Installed

Build Information
Release ID: 603000863
Git revision: a2163670efe259c85cd8f335d95b175068fbbe2a
Build date: 2017-04-03 14:33:15-04
Xamarin addins: 2045d688ea1420e0381b473360ca62a763eb7d04
Build lane: monodevelop-lion-d15-1

Operating System
Mac OS X 10.12.4
Darwin Botovs-MacBook-Pro.local 16.5.0 Darwin Kernel Version 16.5.0
    Fri Mar  3 16:52:33 PST 2017
    root:xnu-3789.51.2~3/RELEASE_X86_64 x86_64
Comment 1 Marek Safar 2017-04-27 08:17:46 UTC

*** This bug has been marked as a duplicate of bug 53461 ***
Comment 2 Igor Botov 2017-04-27 08:32:06 UTC
Marek, May I ask you for giving access to me to the original bug, so that I can make sure that issues are the same? As original bug is crossed, it seems to be fixed. If so when, in which version of mono we can expect fix?
Comment 3 Marek Safar 2017-04-27 08:41:01 UTC
Crossed only means it has been fixed (you can click on it). The fix is already included in Mono 5.0
Comment 4 Igor Botov 2017-04-27 08:45:11 UTC
Thanks! When I try to open original issue I'm getting: "You are not authorized to access bug #53461." May I request to get access to it?