Search Unity

Sending Email, Stripping, and Link.xml -- Runtime Exception

Discussion in 'Android' started by cbireley, Aug 22, 2016.

  1. cbireley

    cbireley

    Joined:
    Aug 22, 2016
    Posts:
    2
    I'm having issues sending an email from an Android device if I turn on any level of stripping.

    I have tried the following versions of my link.xml, but all of them give this exception:
    Code (csharp):
    1. System.MissingMethodException: Method not found: 'Default constructor not found...ctor() of System.Configuration.ExeConfigurationHost' at System.Activator.CreateInstance
    Version A:

    Version B:

    Version C:
    Version D:
    I've already referenced these threads:
    http://forum.unity3d.com/threads/i-have-a-problem-with-link-xml.181099/
    https://issuetracker.unity3d.com/issues/il2cpp-crashes-when-using-smtpclient
    http://forum.unity3d.com/threads/code-stripping-issues-on-android-with-system-net-webclient.385524/
     
  2. cbireley

    cbireley

    Joined:
    Aug 22, 2016
    Posts:
    2
    Not sure why, but for some reason, when it was grouped like this, it finally worked :-\


    Questions:
    • Does anyone have any idea when stuff should or should not be nested?
      • e.g., Above I have stuff nested under "System" and stuff separated out to "System.XYZ"
    • Does anyone know when you should use "mscorlib" vs. "System?"
     
    SweatyChair likes this.
  3. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    @cbireley

    > Does anyone know when you should use "mscorlib" vs. "System?"

    This is really the key issue here. You need to make sure that the proper namespace or type elements in the link.xml file are in the proper assembly element. Often it is not clear which assembly a given namespace or type is in. I like to look up the MSDN documentation for the type in question. It lists the proper assembly for each type.
     
    SweatyChair and cbireley like this.
  4. kayy

    kayy

    Joined:
    Jul 26, 2011
    Posts:
    110
    Another thing to pay attention to (at least on macOS / Linux): It is link.xml in lower case not Link.xml like in this post's headine.
     
  5. SweatyChair

    SweatyChair

    Joined:
    Feb 15, 2016
    Posts:
    140
    I'm having the same problem doing the link.xml, your code saved me. I think your link.xml is not fully correct because you put a class as namespace. E.g. System.Net.Configuration.MailSettingsSectionGroup is class, so it's enough to simply put System.Net.Configuration.

    This is the version I got:
    Code (CSharp):
    1.     <assembly fullname="System">
    2.         <namespace fullname="System.Net.Configuration" preserve="all" />
    3.         <namespace fullname="System.Configuration" preserve="all" />
    4.     </assembly>
    5.     <assembly fullname="mscorlib">
    6.         <namespace fullname="System.Threading" preserve="all" />
    7.     </assembly>
    So the right way to get the assembly:
    1. Search the class/namespace your needed in MSDN documentation
    2. It shows the assembly on the top of the page. If there's mscorlib.dll, use mscorlib in link.xml. Then the same for System.dll.

    I assume Unity should have a better place to document this! It's really confusing this is hard for beginners or who don't know much able C#'s assembly and namespace. (For me at the beginning I thought the first term in a namespace is the assembly, it turns out it's not!)
     
    Last edited: Aug 9, 2019