Stripping causing Exceptions due to missing types

Posting this in case its useful to anyone else.

When attempting to run our game built using Mono and with stripping set to High we encountered the following exception upon connecting a web socket (ISocket.ConnectAsync).

The type initializer for ‘System.Net.HttpWebRequest’ threw an exception.

This does not effect IL2CPP builds with the same level of stripping nor does it effect mono builds with stripping disabled. I did not try the other stripping levels.

The root cause of the issue seems to be that the static constructor for System.Net.HttpWebRequest attempts to create an instance of ExeConfigurationHost via reflection, and that static constructor for whatever reason gets invoked when you attempt to connect the websocket.

In order to work around this I had to add a link.xml to tell the stripper to not strip various types, find my link.xml below

<linker>
    <assembly fullname="System">
        <type fullname="System.Net.Configuration.NetSectionGroup" preserve="all"/>
        <type fullname="System.Net.Configuration.SettingsSection" preserve="all"/>
        <type fullname="System.Net.Configuration.Ipv6Element" preserve="all"/>
        <type fullname="System.Net.Configuration.WebRequestModulesSection" preserve="all"/>
        <type fullname="System.Net.Configuration.WebRequestModuleElementCollection" preserve="all"/>
        <type fullname="System.Net.Configuration.HttpWebRequestElement" preserve="all"/>
        <type fullname="System.Net.Configuration.PerformanceCountersElement" preserve="all"/>
        <type fullname="System.Net.Configuration.ServicePointManagerElement" preserve="all"/>
        <type fullname="System.Net.Configuration.WebProxyScriptElement" preserve="all"/>
        <type fullname="System.Net.Configuration.SocketElement" preserve="all"/>
        <type fullname="System.Net.Configuration.ConnectionManagementSection" preserve="all"/>
        <type fullname="System.Net.Configuration.ConnectionManagementElementCollection" preserve="all"/>
        <type fullname="System.ComponentModel.TypeConverter" preserve="all"/>
        <type fullname="System.ComponentModel.ArrayConverter" preserve="all"/>
        <type fullname="System.ComponentModel.BaseNumberConverter" preserve="all"/>
        <type fullname="System.ComponentModel.BooleanConverter" preserve="all"/>
        <type fullname="System.ComponentModel.ByteConverter" preserve="all"/>
        <type fullname="System.ComponentModel.CharConverter" preserve="all"/>
        <type fullname="System.ComponentModel.CollectionConverter" preserve="all"/>
        <type fullname="System.ComponentModel.ComponentConverter" preserve="all"/>
        <type fullname="System.ComponentModel.CultureInfoConverter" preserve="all"/>
        <type fullname="System.ComponentModel.DateTimeConverter" preserve="all"/>
        <type fullname="System.ComponentModel.DecimalConverter" preserve="all"/>
        <type fullname="System.ComponentModel.DoubleConverter" preserve="all"/>
        <type fullname="System.ComponentModel.EnumConverter" preserve="all"/>
        <type fullname="System.ComponentModel.ExpandableObjectConverter" preserve="all"/>
        <type fullname="System.ComponentModel.Int16Converter" preserve="all"/>
        <type fullname="System.ComponentModel.Int32Converter" preserve="all"/>
        <type fullname="System.ComponentModel.Int64Converter" preserve="all"/>
        <type fullname="System.ComponentModel.NullableConverter" preserve="all"/>
        <type fullname="System.ComponentModel.SByteConverter" preserve="all"/>
        <type fullname="System.ComponentModel.SingleConverter" preserve="all"/>
        <type fullname="System.ComponentModel.StringConverter" preserve="all"/>
        <type fullname="System.ComponentModel.TimeSpanConverter" preserve="all"/>
        <type fullname="System.ComponentModel.UInt16Converter" preserve="all"/>
        <type fullname="System.ComponentModel.UInt32Converter" preserve="all"/>
        <type fullname="System.ComponentModel.UInt64Converter" preserve="all"/>
    </assembly>
    <assembly fullname="System.Configuration">
        <type fullname="System.Configuration.ExeConfigurationHost" preserve="all"/>
    </assembly>
    <assembly fullname="mscorlib">
        <namespace fullname="System.Security.Cryptography" preserve="all"/>
        <namespace fullname="System.Reflection.TargetInvocationException" preserve="all"/>
    </assembly>
</linker>

The inclusion of this file resolved the issues.

Thanks @Ryan_Hardball