Bug 17066 - ExecutionEngineException when calling ConfigurationManager.GetSection("system.codedom") with appdomain
Summary: ExecutionEngineException when calling ConfigurationManager.GetSection("system...
Status: RESOLVED NOT_REPRODUCIBLE
Alias: None
Product: Runtime
Classification: Mono
Component: Reflection ()
Version: unspecified
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-01-06 06:19 UTC by Alistair Bush
Modified: 2017-07-08 03:23 UTC (History)
3 users (show)

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

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 NOT_REPRODUCIBLE

Description Alistair Bush 2014-01-06 06:19:40 UTC
When you call ConfigurationManager.GetSection("system.codedom") within an appdomain running with ShadowCopyFiles="true" mono will throw an "System.ExecutionEngineException: Failed to create shadow copy (CopyFile)" exception as it will attempt to copy a dll from /usr/lib and fail.

This is because CompilerCollection registers a number of types [2] which are not available within mono ( on linux at least ).  Specifically "Microsoft.JScript.JScriptCodeProvider, Microsoft.JScript" is not found by mono.

When Calling GetSection from within a console application or one running without shadow copying no exception will be throw and the application will behave as expected.

Type.GetType (string) is documented at [3] as having the ability to return null when types are not found.  There is also no mention which I am able to find that mentions that the behaviour is different for app domains with shadow copy enabled.  Also the related code to this bug, that actually calls Type.GetType expects null to be return in some cases [4]


I ran the reproduction project as follows

MONO_LOG_LEVEL="debug" MONO_LOG_MASK="asm" mono AssemblyTypeListTest.exe

which captures the following output of interest

Mono: The request to load the assembly System v2.0.0.0 was remapped to v4.0.0.0
Mono: The request to load the assembly System v2.0.0.0 was remapped to v4.0.0.0
Mono: Assembly Loader probing location: '/usr/lib/mono/gac/Microsoft.JScript/8.0.1100.0__b03f5f7f11d50a3a/Microsoft.JScript.dll'.
Mono: Assembly Loader probing location: '/usr/lib/Microsoft.JScript.dll'.

Unhandled Exception:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.

Server stack trace: 
  at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00000] in <filename unknown>:0 
  at System.Activator.CreateInstance (System.Type type, Boolean nonPublic) [0x00000] in <filename unknown>:0 
  at System.Configuration.ConfigInfo.CreateInstance () [0x00000] in <filename unknown>:0 
  at System.Configuration.SectionInfo.CreateInstance () [0x00000] in <filename unknown>:0 
  at System.Configuration.Configuration.GetSectionInstance (System.Configuration.SectionInfo config, Boolean createDefaultInstance) [0x00000] in <filename unknown>:0 
  at System.Configuration.ConfigurationSectionCollection.get_Item (System.String name) [0x00000] in <filename unknown>:0 
  at System.Configuration.Configuration.GetSection (System.String path) [0x00000] in <filename unknown>:0 
  at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection (System.String configKey) [0x00000] in <filename unknown>:0 
  at System.Configuration.ConfigurationManager.GetSection (System.String sectionName) [0x00000] in <filename unknown>:0 
  at AssemblyTypeListTest.Proxy.Go () [0x00000] in <filename unknown>:0 
  at (wrapper managed-to-native) System.Runtime.Remoting.RemotingServices:InternalExecute (System.Reflection.MethodBase,object,object[],object[]&)
  at System.Runtime.Remoting.RemotingServices.InternalExecuteMessage (System.MarshalByRefObject target, IMethodCallMessage reqMsg) [0x00000] in <filename unknown>:0 

Exception rethrown at [0]: 
 ---> System.TypeInitializationException: An exception was thrown by the type initializer for System.CodeDom.Compiler.CodeDomConfigurationHandler ---> System.TypeInitializationException: An exception was thrown by the type initializer for System.CodeDom.Compiler.CompilerCollection ---> System.ExecutionEngineException: Failed to create shadow copy (CopyFile).
  at (wrapper managed-to-native) System.Type:internal_from_name (string,bool,bool)
  at System.Type.GetType (System.String typeName) [0x00000] in <filename unknown>:0 
  at System.CodeDom.Compiler.CompilerInfo.Init () [0x00000] in <filename unknown>:0 
  at System.CodeDom.Compiler.CompilerCollection.AddCompilerInfo (System.CodeDom.Compiler.CompilerInfo ci) [0x00000] in <filename unknown>:0 
  at System.CodeDom.Compiler.CompilerCollection..cctor () [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at System.CodeDom.Compiler.CodeDomConfigurationHandler..cctor () [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at (wrapper managed-to-native) System.Reflection.MonoCMethod:InternalInvoke (System.Reflection.MonoCMethod,object,object[],System.Exception&)
  at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke (System.Runtime.Remoting.Proxies.RealProxy rp, IMessage msg, System.Exception& exc, System.Object[]& out_args) [0x00000] in <filename unknown>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.

Server stack trace: 
  at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00000] in <filename unknown>:0 
  at System.Activator.CreateInstance (System.Type type, Boolean nonPublic) [0x00000] in <filename unknown>:0 
  at System.Configuration.ConfigInfo.CreateInstance () [0x00000] in <filename unknown>:0 
  at System.Configuration.SectionInfo.CreateInstance () [0x00000] in <filename unknown>:0 
  at System.Configuration.Configuration.GetSectionInstance (System.Configuration.SectionInfo config, Boolean createDefaultInstance) [0x00000] in <filename unknown>:0 
  at System.Configuration.ConfigurationSectionCollection.get_Item (System.String name) [0x00000] in <filename unknown>:0 
  at System.Configuration.Configuration.GetSection (System.String path) [0x00000] in <filename unknown>:0 
  at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection (System.String configKey) [0x00000] in <filename unknown>:0 
  at System.Configuration.ConfigurationManager.GetSection (System.String sectionName) [0x00000] in <filename unknown>:0 
  at AssemblyTypeListTest.Proxy.Go () [0x00000] in <filename unknown>:0 
  at (wrapper managed-to-native) System.Runtime.Remoting.RemotingServices:InternalExecute (System.Reflection.MethodBase,object,object[],object[]&)
  at System.Runtime.Remoting.RemotingServices.InternalExecuteMessage (System.MarshalByRefObject target, IMethodCallMessage reqMsg) [0x00000] in <filename unknown>:0 

Exception rethrown at [0]: 
 ---> System.TypeInitializationException: An exception was thrown by the type initializer for System.CodeDom.Compiler.CodeDomConfigurationHandler ---> System.TypeInitializationException: An exception was thrown by the type initializer for System.CodeDom.Compiler.CompilerCollection ---> System.ExecutionEngineException: Failed to create shadow copy (CopyFile).
  at (wrapper managed-to-native) System.Type:internal_from_name (string,bool,bool)
  at System.Type.GetType (System.String typeName) [0x00000] in <filename unknown>:0 
  at System.CodeDom.Compiler.CompilerInfo.Init () [0x00000] in <filename unknown>:0 
  at System.CodeDom.Compiler.CompilerCollection.AddCompilerInfo (System.CodeDom.Compiler.CompilerInfo ci) [0x00000] in <filename unknown>:0 
  at System.CodeDom.Compiler.CompilerCollection..cctor () [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at System.CodeDom.Compiler.CodeDomConfigurationHandler..cctor () [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at (wrapper managed-to-native) System.Reflection.MonoCMethod:InternalInvoke (System.Reflection.MonoCMethod,object,object[],System.Exception&)
  at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke (System.Runtime.Remoting.Proxies.RealProxy rp, IMessage msg, System.Exception& exc, System.Object[]& out_args) [0x00000] in <filename unknown>:0

[1] https://github.com/alistair/mono_appdomain_investigation/tree/codedom_investigation/
[2] https://github.com/mono/mono/blob/master/mcs/class/System/System.CodeDom.Compiler/CompilerCollection.cs?source=cc#L52-L97
[3] http://msdn.microsoft.com/en-us/library/w3f99sx1(v=vs.110).aspx
[4] https://github.com/mono/mono/blob/master/mcs/class/System/System.CodeDom.Compiler/CompilerInfo.cs#L62-L65
Comment 1 Rodrigo Kumpera 2014-01-08 18:04:56 UTC
Please provide a test case that shows this problem.
Comment 2 Alistair Bush 2014-01-09 05:31:27 UTC
Hi Rodrigo.

A test case is actually located here (https://github.com/alistair/mono_appdomain_investigation/tree/codedom_investigation/)

I have also created a pull request which fixes the issue

https://github.com/mono/mono/pull/869

Basically mono_make_shadow_copy should not error (ExecutionRuntimeException) if it can't shadow copy an assembly which is can't find.  It should just be letting the type resolution just not find the type at all.
Comment 3 Ludovic Henry 2017-07-08 03:23:46 UTC
Can you still reproduce with latest mono? If that's the case, feel free to reopen, and please provide a repro case. Thank you.