Unity using AWS Gamelift. Editor fine, but NotSupportedException in build to IOS

846 views Asked by At

I'm completely stuck. My game in unity works well in the editor, but crashes on launch on IOS. I'm using AWS Gamelift for multiplayer, which might be the culprit since it built fine before integrating it. For the actual networking code I'm using the new unity DOTS Netcode package.

In my plugins folder I have the following dlls for the client.

  • AWSSDK.CognitoIdentity
  • AWSSDK.CognitoIdentityProvider
  • AWSSDK.CognitoSync
  • AWSSDK.Core
  • AWSSDK.Extensions.CognitoAuthentication
  • AWSSDK.Gamelift
  • AWSSDK.Lambda
  • AWSSDK.SecurityToken
  • Microsoft.Bcl.AsyncInterfaces
  • System.Threading.Tasks.Extensions
  • log4net

In the editor everything runs perfectly. I can connect to GameLift, create a game session etc. When I build, it completes successfully, but crashes on launch, showing a empty scene with a skybox, and the following error in Xcode console:

... some other outputs for initialization...

NotSupportedException: System.Web.UI.WebResourceAttribute::set_CdnSupportsSecureConnection
  at System.Web.UI.WebResourceAttribute.set_CdnSupportsSecureConnection (System.Boolean value) [0x00000] in <00000000000000000000000000000000>:0 
  at System.MonoCustomAttrs.GetCustomAttributesBase (System.Reflection.ICustomAttributeProvider obj, System.Type attributeType, System.Boolean inheritedOnly) [0x00000] in <00000000000000000000000000000000>:0 
  at System.MonoCustomAttrs.GetCustomAttributes (System.Reflection.ICustomAttributeProvider obj, System.Type attributeType, System.Boolean inherit) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Attribute.GetCustomAttributes (System.Reflection.Assembly element, System.Type attributeType, System.Boolean inherit) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Reflection.CustomAttributeExtensions.GetCustomAttributes[T] (System.Reflection.Assembly element) [0x00000] in <00000000000000000000000000000000>:0 
  at Unity.Entities.TypeManager.InitializeAllComponentTypes () [0x00000] in <00000000000000000000000000000000>:0 
  at Unity.Entities.TypeManager.Initialize () [0x00000] in <00000000000000000000000000000000>:0 
  at Unity.Entities.EntityGuid..cctor () [0x00000] in <00000000000000000000000000000000>:0 
  at Unity.Entities.World..ctor (System.String name, Unity.Entities.WorldFlags flags) [0x00000] in <00000000000000000000000000000000>:0 
  at Unity.Entities.DefaultWorldInitialization.Initialize (System.String defaultWorldName, System.Boolean editorWorld) [0x00000] in <00000000000000000000000000000000>:0 
 
(Filename: currently not available on il2cpp Line: -1)

ArgumentException: Unknown Type:`Unity.Entities.CompanionLink` All ComponentType must be known at compile time. For generic components, each concrete type must be registered with [RegisterGenericComponentType].
  at Unity.Entities.TypeManager.ManagedException (System.Type type) [0x00000] in <00000000000000000000000000000000>:0 
  at Unity.Entities.TypeManager.GetTypeIndex (System.Type type) [0x00000] in <00000000000000000000000000000000>:0 
  at Unity.Entities.AttachToEntityClonerInjection.Initialize () [0x00000] in <00000000000000000000000000000000>:0 
Rethrow as TypeInitializationException: The type initializer for 'Unity.Entities.AttachToEntityClonerInjection' threw an exception.

 
(Filename: currently not available on il2cpp Line: -1)

[Subsystems] Loading plugin UnityARKit for subsystem ARKit-Input...
[Subsystems] UnityARKit successfully registered Provider for ARKit-Input
NullReferenceException: Object reference not set to an instance of an object.
  at Unity.NetCode.ConvertToClientServerEntity.Awake () [0x00000] in <00000000000000000000000000000000>:0 

... some other debug messages spamming null reference exceptions that seem to be related to the above errors...
 

I suspected this has something to do with code stripping for IOS builds. my link.xml file is the following (Based on googling, no idea what I'm doing here).

<?xml version="1.0" encoding="utf-8"?>

<linker>

    <assembly fullname="UnityEngine">
         <type fullname="UnityEngine.Experimental.Networking.UnityWebRequest" preserve="all" />
         <type fullname="UnityEngine.Experimental.Networking.UploadHandlerRaw" preserve="all" />
         <type fullname="UnityEngine.Experimental.Networking.UploadHandler" preserve="all" />
         <type fullname="UnityEngine.Experimental.Networking.DownloadHandler" preserve="all" />
         <type fullname="UnityEngine.Experimental.Networking.DownloadHandlerBuffer" preserve="all" />
     </assembly>
    
    <assembly fullname="log4net"/>
    <assembly fullname="Google.Protobuf"/>
    <assembly fullname="System.Runtime.CompilerServices.Unsafe"/>
    <assembly fullname="websocket-sharp"/>
    
    <assembly fullname="AWSSDK.Core" preserve="all">
        <type fullname ="Amazon.*" preserve = "all" />
          <namespace fullname="Amazon.Util.Internal.PlatformServices" preserve="all"/>
      </assembly>
    
      <assembly fullname="AWSSDK.CognitoIdentity" preserve="all">
          <type fullname ="Amazon.*" preserve = "all" />
          <namespace fullname="Amazon.Util.Internal.PlatformServices" preserve="all"/>
      </assembly>
      
      <assembly fullname="AWSSDK.CognitoIdentityProvider" preserve="all">
          <type fullname ="Amazon.*" preserve = "all" />
          <namespace fullname="Amazon.Util.Internal.PlatformServices" preserve="all"/>
      </assembly>
      
      <assembly fullname="AWSSDK.CognitoSync" preserve="all">
        <type fullname ="Amazon.*" preserve = "all" />
        <namespace fullname="Amazon.Util.Internal.PlatformServices" preserve="all"/>
      </assembly>
      
      <assembly fullname="AWSSDK.IdentityManagement" preserve="all">
        <type fullname ="Amazon.*" preserve = "all" />
        <namespace fullname="Amazon.Util.Internal.PlatformServices" preserve="all"/>
      </assembly>
      
      <assembly fullname="AWSSDK.SecurityToken" preserve="all">
        <type fullname ="Amazon.*" preserve = "all" />
        <namespace fullname="Amazon.Util.Internal.PlatformServices" preserve="all"/>
      </assembly>
      
      <assembly fullname="AWSSDK.DynamoDBv2" preserve="all">
        <type fullname ="Amazon.*" preserve = "all" />
        <namespace fullname="Amazon.Util.Internal.PlatformServices" preserve="all"/>
      </assembly>
      
      <assembly fullname="AWSSDK.Lambda" preserve="all">
        <type fullname ="Amazon.*" preserve = "all" />
        <namespace fullname="Amazon.Util.Internal.PlatformServices" preserve="all"/>
      </assembly>
      
      <assembly fullname="AWSSDK.Extensions.CognitoAuthentication" preserve="all">
        <type fullname ="Amazon.*" preserve = "all" />
        <namespace fullname="Amazon.Util.Internal.PlatformServices" preserve="all"/>
      </assembly>
      
      
      <assembly fullname="AWSSDK.GameLift" preserve="all">
        <type fullname ="Amazon.*" preserve = "all" />
        <namespace fullname="Amazon.Util.Internal.PlatformServices" preserve="all"/>
      </assembly>
      
</linker>

The weird thing is I can get the program to boot if I remove the line to preserve log4net.dll.

However, after doing so, when I click the sign in to gamelift button I get a different error that seems to be missing something to do with log4net. (I get the same error for signup, and other things). The thing that's strange is that the program boots up and works fine until I try something with gamelift.

Here is the different error in Xcode. This is the only thing that appears after I try to connect to Cognito to sign in.

NullReferenceException: Object reference not set to an instance of an object.
  at Amazon.Runtime.Internal.Util.InternalLog4netLogger..ctor (System.Type declaringType) [0x00000] in <00000000000000000000000000000000>:0 
  at Amazon.Runtime.Internal.Util.Logger..ctor (System.Type type) [0x00000] in <00000000000000000000000000000000>:0 
  at Amazon.Runtime.Internal.Util.Logger.GetLogger (System.Type type) [0x00000] in <00000000000000000000000000000000>:0 
  at Amazon.Runtime.Internal.EnvironmentVariableInternalConfiguration..ctor () [0x00000] in <00000000000000000000000000000000>:0 
  at Amazon.Runtime.Internal.FallbackInternalConfigurationFactory.Reset () [0x00000] in <00000000000000000000000000000000>:0 
  at Amazon.Runtime.ClientConfig.get_RetryMode () [0x00000] in <00000000000000000000000000000000>:0 
  at Amazon.Runtime.AmazonServiceClient.BuildRuntimePipeline () [0x00000] in <00000000000000000000000000000000>:0 
  at SignInManager+<TrySignIn>d__10.MoveNext () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Runtime.CompilerServices.AsyncTaskCache.CreateCacheableTask[TResult] (TResult result) [0x00000] in <00000000000000000000000000000000>:0 
  at SignInManager.TrySignIn (EmailAddress email, Password password, LoginEvents+SignInCallback callback) [0x00000] in <00000000000000000000000000000000>:0 
  at LoginEvents+SignInEvent.Invoke (EmailAddress email, Password password, LoginEvents+SignInCallback callback) [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.UIElements.EventCallback`1[TEventType].Invoke (TEventType evt) [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.UIElements.EventCallbackFunctor`1[TEventType].Invoke (UnityEngine.UIElements.EventBase evt) [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.UIElements.EventCallbackRegistry.InvokeCallbacks (UnityEngine.UIElements.EventBase evt) [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.UIElements.CallbackEventHandler.HandleEvent (UnityEngine.UIElements.EventBase evt) [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.UIElements.EventDispatchUtilities.PropagateEvent (UnityEngine.UIElements.EventBase evt) [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.UIElements.PointerEventDispatchingStrategy.DispatchEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel) [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.UIElements.EventDispatcher.ApplyDispatchingStrategies (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel, System.Boolean imguiEventIsInitiallyUsed) [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.UIElements.EventDispatcher.ProcessEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel) [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.UIElements.EventDispatcher.ProcessEventQueue () [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.UIElements.EventDispatcher.ProcessEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel) [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.UIElements.EventSystem.SendPositionBasedEvent[TArg] (UnityEngine.Vector3 mousePosition, UnityEngine.Vector3 delta, System.Func`4[T1,T2,T3,TResult] evtFactory, TArg arg) [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.UIElements.EventSystem.SendIMGUIEvents () [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.UIElements.EventSystem.Update () [0x00000] in <00000000000000000000000000000000>:0 
Rethrow as TypeInitializationException: The type initializer for 'Amazon.Runtime.Internal.FallbackInternalConfigurationFactory' threw an exception.
  at Amazon.Runtime.ClientConfig.get_RetryMode () [0x00000] in <00000000000000000000000000000000>:0 
  at Amazon.Runtime.AmazonServiceClient.BuildRuntimePipeline () [0x00000] in <00000000000000000000000000000000>:0 
  at SignInManager+<TrySignIn>d__10.MoveNext () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Runtime.CompilerServices.AsyncTaskCache.CreateCacheableTask[TResult] (TResult result) [0x00000] in <00000000000000000000000000000000>:0 
  at SignInManager.TrySignIn (EmailAddress email, Password password, LoginEvents+SignInCallback callback) [0x00000] in <00000000000000000000000000000000>:0 
  at LoginEvents+SignInEvent.Invoke (EmailAddress email, Password password, LoginEvents+SignInCallback callback) [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.UIElements.EventCallback`1[TEventType].Invoke (TEventType evt) [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.UIElements.EventCallbackFunctor`1[TEventType].Invoke (UnityEngine.UIElements.EventBase evt) [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.UIElements.EventCallbackRegistry.InvokeCallbacks (UnityEngine.UIElements.EventBase evt) [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.UIElements.CallbackEventHandler.HandleEvent (UnityEngine.UIElements.EventBase evt) [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.UIElements.EventDispatchUtilities.PropagateEvent (UnityEngine.UIElements.EventBase evt) [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.UIElements.PointerEventDispatchingStrategy.DispatchEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel) [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.UIElements.EventDispatcher.ApplyDispatchingStrategies (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel, System.Boolean imguiEventIsInitiallyUsed) [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.UIElements.EventDispatcher.ProcessEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel) [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.UIElements.EventDispatcher.ProcessEventQueue () [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.UIElements.EventDispatcher.ProcessEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel) [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.UIElements.EventSystem.SendPositionBasedEvent[TArg] (UnityEngine.Vector3 mousePosition, UnityEngine.Vector3 delta, System.Func`4[T1,T2,T3,TResult] evtFactory, TArg arg) [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.UIElements.EventSystem.SendIMGUIEvents () [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.UIElements.EventSystem.Update () [0x00000] in <00000000000000000000000000000000>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.SendOrPostCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.UnitySynchronizationContext.Exec () [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.UnitySynchronizationContext.Exec () [0x00000] in <00000000000000000000000000000000>:0 
UnityEngine.UnitySynchronizationContext:Exec()
UnityEngine.UnitySynchronizationContext:Exec()
 
(Filename: currently not available on il2cpp Line: -1)

So because it's a type initialization problem that's why I suspected a problem with code stripping. But I don't understand code stripping at all, this hunch is just based on some forum posts I read.

Any ideas at all would be super helpful. I'm stuck.

1

There are 1 answers

0
Adam B On BEST ANSWER

I managed to solve this issue with much difficulty and a solid week of work. Here are the steps I did to fix it. in case anyone else has problems in the future.

  1. Make sure I had updated AWS SDK dlls. I got these with nuget in rider, then dragged the netstandard2.0 dll into the plugins folder. Note: Look very carefully at the dependencies listed in nuget. I had to use a slightly older version the AWS SDK to be compatible with the cognitoAuthentification.dll.

Here is a screenshot of the packages in rider. The package versions seemed to matter a lot. Check the dependencies carefully.

enter image description here

  1. Use Amazon.Extensions.CognitoAuthentication.dll and NOT AWSSDK.Extensions.CognitoAuthentication.dll

  2. Delete everything in link.xml file. Only include the following entry:

     <linker>
     <assembly fullname="AWSSDK.Core">
         <type fullname="Amazon.Util.Internal.PlatformServices.NetworkReachability" preserve="all"/>
         <namespace fullname="Amazon.Util.Internal.PlatformServices" preserve="all"/>
     </assembly>
     </linker>
    
  3. Go through ALL the other plugins, and checking exclude iOS, one by one. First, check if it breaks desktop play in editor. Then check if it breaks anything in iOS build. I think this might have been the most important step.

  4. Go into the unity editor.app package contents, go down into monobleedingedge/unityjit/ and drag Mono.Posix, System.Core, System.Configuration into my plugins folder.

Note every single time I changed dlls in unity plugins folder, I had to reboot unity to get rid of console errors and failure to reload scripts.

Here is a screenshot of my plugins folder if anyone is curious

screenshot

Anyway... the true answer is this is not a user friendly system to use.