4

I use below code to create GameClient in Unity3d:

AmazonGameLiftClient client = 
        new AmazonGameLiftClient("accessKeyId",
                                 "accessKey",
                                  RegionEndpoint.CNNorth1);

Above code is the first line in Awake(), no any other leading codes.

I get below error:

NullReferenceException: Object reference not set to an instance of an object
Amazon.CSMSection.get_CSMEnabled ()
Amazon.Util.CSMConfig.Configure (Amazon.CSMSection section)
Amazon.Util.Internal.RootConfig..ctor ()
Amazon.AWSConfigs..cctor ()
Rethrow as TypeInitializationException: An exception was thrown by the type initializer for Amazon.AWSConfigs
Amazon.Runtime.ClientConfig..ctor ()
Amazon.GameLift.AmazonGameLiftConfig..ctor ()
Amazon.GameLift.AmazonGameLiftClient..ctor (System.String awsAccessKeyId, System.String awsSecretAccessKey, Amazon.RegionEndpoint region)

Is there anything I forgot to do? I assume the root cause is I do not put app.config in the correct place. So AWS SDK does not init correctly, but I have not found any tutorial for using Unity3d as Amazon GameLift client :(

My Environment:

  • OS: Mac OS X 10.14.1
  • Unity3d: 2018.2.12f1
  • AWS SDK Core: 3.3.29.10(.net35)
  • AWS SDK GameLift: 3.3.12.29(.net35)

Update: The AWS SDK relies on System.ConfigurationManager which seems not available in Unity3d projects. It seems the root cause of the NullReferenceException.

Yongyi
  • 327
  • 2
  • 12
  • First of all, the error gives all the details to debug it. Second, Google gives you the answers. This will help you understanding the issue -> https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it – Cabrra Nov 22 '18 at 14:09
  • This seems like a configuration issue; please provide the following details: Name the AWS SDK nuget packages you're using and which version they are on. Name the .NET framework you're on and which version it is. Any other relevant code leading up to this point or any other references you've made to the AWS SDK that executed up to this point would also be helpful for context. In the interim, make sure you're using the correct AWS SDK packages for your framework and that they are with the latest version. Also make sure you're using the correct AccessKey/SecretKey. – Anthony Neace Nov 22 '18 at 16:32
  • @AnthonyNeace you are right. It should be a configuration issue. I have no idea where to put the app.config in a Unity3d project. I am trying to figure it out. – Yongyi Nov 24 '18 at 03:26
  • I'm experiencing this issue as well after upgrading the aws sdk. @AnthonyNeace this is entry point to the api. You make a config before making a client to do other things so there is no other context. Cabrra's comment is also really shallow and unhelpful. This NRE happens within the default constructor of the config classes so there must be some kind of non-obvious external setup that needs to be done now. Perhaps some kind of factory method? – Jayd16 Nov 28 '18 at 23:49

1 Answers1

1

Please refer to this answer, it completely solves this question.

Yongyi
  • 327
  • 2
  • 12