Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MissingMethodException: Default constructor not found for type System.Diagnostics.SystemDiagnosticsSection #302

Open
Arakade opened this issue Oct 18, 2021 · 0 comments

Comments

@Arakade
Copy link

Arakade commented Oct 18, 2021

Getting the exception running a built Unity game using MoonSharp when it tries to load the UnityScriptLoader class and any amount of stripping enabled. With no stripping, it works; low or above, error.

The exception is basically line 106 trying to call System.Diagnostics.Debug.WriteLine() -- the runtime fails to load the UnityScriptLoader class due to this requiring System.Diagnostics.SystemDiagnosticsSection.

I'm using Unity 2020.3.20f1 (latest LTS) and targeting Mono with .Net 4.x API in a development build (hence DEBUG is set so the Debug.WriteLine() call isn't stripped out).

I've tried adding a link.xml with the following but still no luck.

<assembly fullname="System">
    <type fullname="System.Diagnostics.SystemDiagnosticsSection" preserve="all"/>
</assembly>

Googling found BastianBlokland/componenttask-unity#20 which sounds eerily similar.
Their workaround was disabling the calls in certain situations. (not tried yet since grep says there are quite a few.)

Full exception:

Error initializing UnityScriptLoader : System.NullReferenceException: Object reference not set to an instance of an object
  at MoonSharp.Interpreter.Loaders.UnityAssetsScriptLoader.LoadResourcesWithReflection (System.String assetsPath) [0x00080] in ...\Assets\Plugins\MoonSharp\Interpreter\Loaders\UnityAssetsScriptLoader.cs:89 
MissingMethodException: Default constructor not found for type System.Diagnostics.SystemDiagnosticsSection
  at System.RuntimeType.CreateInstanceMono (System.Boolean nonPublic) [0x0007b] in <c6b12fce3f944c56a98263b7506fd9c5>:0 
  at System.RuntimeType.CreateInstanceSlow (System.Boolean publicOnly, System.Boolean skipCheckThis, System.Boolean fillCache, System.Threading.StackCrawlMark& stackMark) [0x00009] in <c6b12fce3f944c56a98263b7506fd9c5>:0 
  at System.RuntimeType.CreateInstanceDefaultCtor (System.Boolean publicOnly, System.Boolean skipCheckThis, System.Boolean fillCache, System.Threading.StackCrawlMark& stackMark) [0x00027] in <c6b12fce3f944c56a98263b7506fd9c5>:0 
  at System.Activator.CreateInstance (System.Type type, System.Boolean nonPublic) [0x0002c] in <c6b12fce3f944c56a98263b7506fd9c5>:0 
  at System.Configuration.ConfigInfo.CreateInstance () [0x00026] in <f81481506e0240458a7971bcdf21632d>:0 
  at System.Configuration.SectionInfo.CreateInstance () [0x00000] in <f81481506e0240458a7971bcdf21632d>:0 
  at System.Configuration.Configuration.GetSectionInstance (System.Configuration.SectionInfo config, System.Boolean createDefaultInstance) [0x0001c] in <f81481506e0240458a7971bcdf21632d>:0 
  at System.Configuration.ConfigurationSectionCollection.get_Item (System.String name) [0x0002c] in <f81481506e0240458a7971bcdf21632d>:0 
  at System.Configuration.Configuration.GetSection (System.String sectionName) [0x0001e] in <f81481506e0240458a7971bcdf21632d>:0 
  at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection (System.String configKey) [0x00006] in <f81481506e0240458a7971bcdf21632d>:0 
  at System.Configuration.ConfigurationManager.GetSection (System.String sectionName) [0x00005] in <f81481506e0240458a7971bcdf21632d>:0 
  at System.Configuration.PrivilegedConfigurationManager.GetSection (System.String sectionName) [0x00000] in <3cadc1d286c84f728a6ecce7cc469c4b>:0 
  at System.Diagnostics.DiagnosticsConfiguration.GetConfigSection () [0x00000] in <3cadc1d286c84f728a6ecce7cc469c4b>:0 
  at System.Diagnostics.DiagnosticsConfiguration.Initialize () [0x0002a] in <3cadc1d286c84f728a6ecce7cc469c4b>:0 
  at System.Diagnostics.DiagnosticsConfiguration.get_IndentSize () [0x00000] in <3cadc1d286c84f728a6ecce7cc469c4b>:0 
  at System.Diagnostics.TraceInternal.InitializeSettings () [0x0004e] in <3cadc1d286c84f728a6ecce7cc469c4b>:0 
  at System.Diagnostics.TraceInternal.get_UseGlobalLock () [0x00000] in <3cadc1d286c84f728a6ecce7cc469c4b>:0 
  at System.Diagnostics.TraceInternal.WriteLine (System.String message) [0x00000] in <3cadc1d286c84f728a6ecce7cc469c4b>:0 
  at System.Diagnostics.Debug.WriteLine (System.String message) [0x00000] in <3cadc1d286c84f728a6ecce7cc469c4b>:0 
  at MoonSharp.Interpreter.Loaders.UnityAssetsScriptLoader.LoadResourcesWithReflection (System.String assetsPath) [0x00109] in ...\Assets\Plugins\MoonSharp\Interpreter\Loaders\UnityAssetsScriptLoader.cs:106 
  at MoonSharp.Interpreter.Loaders.UnityAssetsScriptLoader..ctor (System.String assetsPath) [0x0001f] in ...\Assets\Plugins\MoonSharp\Interpreter\Loaders\UnityAssetsScriptLoader.cs:37 
  at MoonSharp.Interpreter.Platforms.PlatformAutoDetector.GetDefaultScriptLoader () [0x00010] in ...\Assets\Plugins\MoonSharp\Interpreter\Platforms\PlatformAutoDetector.cs:134 
  at MoonSharp.Interpreter.Script..cctor () [0x0000c] in ...\Assets\Plugins\MoonSharp\Interpreter\Script.cs:47 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant