About the link.xml setting problem(with Strip Function)

The game I’m working on using several classes from the System.Net.Sockets package. If I run it on a normal build it works perfectly, but if I try to strip it using either StrippingLevel.StripAssemblies or StrippingLevel.StripByteCode stripping levels, it crashes with a exception.

This is the exception:


Unhandled Exception: System.TypeInitializationException: An exception was thrown by the type initializer for System.Net.WebRequest ---> System.ArgumentNullException: Argument cannot be null.
Parameter name: type
  at System.Activator.CheckType (System.Type type) [0x00000] in <filename unknown>:0 
  at System.Activator.CreateInstance (System.Type type, Boolean nonPublic) [0x00000] in <filename unknown>:0 
  at System.Net.WebRequest.AddPrefix (System.String prefix, System.Type type) [0x00000] in <filename unknown>:0 
  at System.Net.WebRequest..cctor () [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at HttpUtil.GetHttp (System.String httpUrl) [0x00000] in <filename unknown>:0 
  at NetManager.ExecuteGetHttp () [0x00000] in <filename unknown>:0 

This is my link.xml :


<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.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>

Here’s what I’d do to try and figure out what’s happening:

  1. Enter mono system.net.webrequest into Google.
  2. Take the first github hit (https://github.com/mono/mono/blob/master/mcs/class/System/System.Net/WebRequest.cs) since the source code to the Mono libraries is in github.
  3. Look through the code trying to figure out what calls are made. (So, for example, line 85 calls AddPrefix() which agrees with the call stack you supplied in the question. Presumably it’s when AddPrefix() calls Activator.CreateInstance() at line 509 that the problems start.
  4. Working back to the constructor for WebRequest there is a list of the protocols that it has to support. It’s one of these types that causes the error, so, I guess you need to modify your link.xml to make sure that these types are not removed by the stripper.

Note: I am only trying to teach you how you can troubleshoot this error, I’ve not got any more insight into the problem than you have. It’s the use of the Mono source that should get you to a solution. You could legitimately say “why should I need to know how Mono implement the runtime and class libraries?” but I’d then say well, stripping removes types that it doesn’t think are used. These types are referenced only as strings, so either learn how Mono does things, or don’t use stripping.:wink: