UnityとiOSでSmtpを叩くと怒られる奴の解決方法
iPhone XsMaxがなんとか手に入りました。
お ま た せ pic.twitter.com/XF1RO10wqH
— JackMasaki T265 (@JackMasaki) 2018年10月13日
諸事情でsmtpをiPhoneから叩こうということになり、UnityからビルドしてXcodeでデプロイし、実機でテスト!という段階でエラーが発生しました。
発生したエラーは次の通りです。
MissingMethodException: Method not found: 'Default constructor not found...ctor() of System.Net.Configuration.MailSettingsSectionGroup'. at System.Activator.CreateInstance (System.Type type, Boolean nonPublic) [0x00000] in
:0 at System.Configuration.Configuration.GetSectionGroupInstance (System.Configuration.SectionGroupInfo group) [0x00000] in :0 at System.Configuration.ConfigurationSectionGroupCollection.get_Item (System.String name) [0x00000] in :0 at System.Configuration.Configuration.GetSection (System.String path) [0x00000] in :0 at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection (System.String configKey) [0x00000] in :0 at System.Configuration.ConfigurationManager.GetSection (System.String sectionName) [0x00000] in :0 at System.Net.Mail.SmtpClient..ctor (System.String host, Int32 port) [0x00000] in :0 at EmailHandler.SendEmail (System.String from, System.String password, System.String to, System.String subject, System.String body) [0x00000] in :0 at UnityEngine.Events.UnityEvent.Invoke () [0x00000] in :0 at UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.EventFunction 1 functor) [0x00000] in <filename unknown>:0 at UnityEngine.EventSystems.StandaloneInputModule.ProcessTouchPress (UnityEngine.EventSystems.PointerEventData pointerEvent, Boolean pressed, Boolean released) [0x00000] in <filename unknown>:0 at UnityEngine.EventSystems.StandaloneInputModule.ProcessTouchEvents () [0x00000] in <filename unknown>:0 at UnityEngine.EventSystems.StandaloneInputModule.Process () [0x00000] in <filename unknown>:0 UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction
1) UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchPress(PointerEventData, Boolean, Boolean) UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchEvents() UnityEngine.EventSystems.StandaloneInputModule:Process() (Filename: currently not available on il2cpp Line: -1)
どうやらIL2CPPのバグのようです。
解決法としてはlink.xmlに以下のものを追加、もしくはlink.xmlがない場合にはAssetフォルダに作成し以下のものを記述し、再度UnityからiOS向けにビルドすることで解決します。
<linker> <assembly fullname="System"> <type fullname="System.Net.Configuration.MailSettingsSectionGroup" preserve="all"/> <type fullname="System.Net.Configuration.SmtpSection" preserve="all"/> <type fullname="System.Net.Configuration.SmtpNetworkElement" preserve="all"/> <type fullname="System.Net.Configuration.SmtpSpecifiedPickupDirectoryElement" preserve="all"/> </assembly> </linker>
参考になったQ&A