aws / aws-sdk-net

The official AWS SDK for .NET. For more information on the AWS SDK for .NET, see our web site:
http://aws.amazon.com/sdkfornet/
Apache License 2.0
2.05k stars 853 forks source link

Cases where log4net manager can be found, but Internal logger can fail initialization causing a NullReferenceException #1747

Closed jasonboukheir closed 1 month ago

jasonboukheir commented 3 years ago

Description

I'm getting NullReferenceException in my unity android build, and I sourced it to InternalLog4netLogger.ctor(Type declaringType). I'm still not sure if it's being caused because getLoggerWithTypeMethod is null, but it seems that's the case. I figure that there's some stripping happening with IL2CPP causing this condition. I don't have log4net logging enabled in my aws config. One of my 3rd party packages is using log4net.

I have a hunch there's a condition where logMangerType can be non-null, but getLoggerWithTypeMethod can be null.

Reproduction Steps

Logs

2020/11/19 08:59:48.166 8135 8160 Error Unity NullReferenceException: Object reference not set to an instance of an object.
2020/11/19 08:59:48.166 8135 8160 Error Unity   at Amazon.Runtime.Internal.Util.InternalLog4netLogger..ctor (System.Type declaringType) [0x00000] in <00000000000000000000000000000000>:0 
2020/11/19 08:59:48.166 8135 8160 Error Unity   at Amazon.Runtime.Internal.Util.Logger..ctor (System.Type type) [0x00000] in <00000000000000000000000000000000>:0 
2020/11/19 08:59:48.166 8135 8160 Error Unity   at Amazon.Runtime.Internal.Util.Logger.GetLogger (System.Type type) [0x00000] in <00000000000000000000000000000000>:0 
2020/11/19 08:59:48.166 8135 8160 Error Unity   at Amazon.Util.Internal.AmazonHookedPlatformInfo..cctor () [0x00000] in <00000000000000000000000000000000>:0 
2020/11/19 08:59:48.166 8135 8160 Error Unity   at Amazon.UnityInitializer.Awake () [0x00000] in <00000000000000000000000000000000>:0 
2020/11/19 08:59:48.166 8135 8160 Error Unity   at UnityEngine.GameObject.AddComponent[T] () [0x00000] in <00000000000000000000000000000000>:0 
2020/11/19 08:59:48.166 8135 8160 Error Unity   at Amazon.UnityInitializer.AttachToGameObject (UnityEngine.GameObject gameObject) [0x00000] in <00000000000000000000000000000000>:0 

Environment

Resolution

In lines 149-155:

if (loadState == LoadState.Uninitialized)
{
    loadStatics();
}

if (logMangerType == null)
    return;

this.internalLogger = getLoggerWithTypeMethod.Invoke(null, new object[] { TypeFactory.GetTypeInfo(declaringType).Assembly, declaringType }); //Assembly.GetCallingAssembly()

There are conditions where loadStatics() can fail, but logMangerType != null. My suggestion is to check for loadState == LoadState.Failed instead of logMangerType == null to make sure that getLoggerWithTypeMethod is not null.


This is a :bug: bug-report

AdamBebko commented 3 years ago

I'm also having this issue. Any resolution yet?

jasonboukheir commented 3 years ago

@AdamBebko I have a suggested fix above, but I haven't heard anything yet.

I'm away from my desktop for holidays atm, but can update next week.

AdamBebko commented 3 years ago

I don’t know how to do that haha. I’m using the AWS SDK dlls

If it helps resolve things I’m getting the error in IOS. I also suspected code stripping being the culprit. I also don’t have log4net.dll in my project. When I do, the game won’t even boot and crashes on launch.

For me, I’m getting errors when I hit the buttons in my game that calls the methods that try to sign into or sign up for cognito. I think it’s when I create the clientprovider object.

I’ve tried playing around with link.XML in unity but no success so far.

I’ve also tried setting disablelogging = true. It that didn’t change anything.

Rockbag commented 3 years ago

I'm facing a similar issue; I'm trying to get a WebGL build in Unity for my game to work, so I'm also using IL2CPP. I pulled this repo, added the fix that @jasonboukheir suggested, built the Cognito and GameLift related libraries and used those in my project. At first it was promising, I got through the logger initialization error, however, when the execution proceeds, it fails later downstream when the SDK attempts to encrypt data through the UserCrypto module as it's trying to import Crypt32.dll which is a Windows native library. So it looks like I'm giving up. In any case I pushed the newly built DLLs to S3 if you guys want to give it a try in your builds. Hands on heart there's no destructive code in there. :)

In any case it would be great if the SDK team could make these modules available for platforms that require AOT compilation and don't have access to Win native libraries. I'd imagine there's plenty of use-cases where people might want to use Cognito, DynamoDB and GameLift in their Unity games on various platforms, which is quite impossible at the moment.

Rockbag commented 3 years ago

I ended up going slightly deeper and fixed the UserCrypt issue as well; it seems there's a guard that should protect against this behaviour but ultimately ends up causing the failure. There's a check to see if Crypt32.dll is available on the current system by actually calling out to the DLL, however, the exception is still bubbled up for some reason.

Fixing that, however, caused another issue where I don't even have a stack trace anymore. All it says is a StreamReader has received a null value somewhere, but tracking that down would take me way too long unfortunately.

Would love to hear if anyone's managed to solve this.

github-actions[bot] commented 2 years ago

We have noticed this issue has not received attention in 1 year. We will close this issue for now. If you think this is in error, please feel free to comment and reopen the issue.

gabetoth-alder commented 2 years ago

This is still happening:

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.GetLogger (System.Type type) [0x00000] in <00000000000000000000000000000000>:0 
  at Amazon.Runtime.AmazonServiceClient..ctor (Amazon.Runtime.AWSCredentials credentials, Amazon.Runtime.ClientConfig config) [0x00000] in <00000000000000000000000000000000>:0 
  at Framework.Core.Managers.GameLiftClientManager+<GameLiftClientInit>d__22.MoveNext () [0x00000] in <00000000000000000000000000000000>:0 
  at Aws.GameLift.Server.ProcessParameters+OnStartGameSessionDelegate.Invoke (Aws.GameLift.Server.Model.GameSession gameSession) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00000] in <00000000000000000000000000000000>:0 
  at Framework.Utility.ScriptableEvent+ScriptableDelegate.Invoke () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.TimerCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.UnitySynchronizationContext.Exec () [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.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in <00000000000000000000000000000000>:0 
  at Framework.Core.Managers.GameLiftClientManager+<Start>d__20.MoveNext () [0x00000] in <00000000000000000000000000000000>:0 
  at Aws.GameLift.Server.ProcessParameters+OnStartGameSessionDelegate.Invoke (Aws.GameLift.Server.Model.GameSession gameSession) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00000] in <00000000000000000000000000000000>:0 
  at Framework.Utility.ScriptableEvent+ScriptableDelegate.Invoke () [0x00000] in <00000000000000000000000000000000>:0 
  at Aws.GameLift.Server.ProcessParameters+OnStartGameSessionDelegate.Invoke (Aws.GameLift.Server.Model.GameSession gameSession) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.AwaitTaskContinuation.RunCallback (System.Threading.ContextCallback callback, System.Object state, System.Threading.Tasks.Task& currentTask) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation.Run (System.Threading.Tasks.Task task, System.Boolean canInlineContinuationTask) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.Task.FinishContinuations () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.Task.Finish (System.Boolean bUserDelegateExecuted) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.Task`1[TResult].TrySetException (System.Object exceptionObject) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[TResult].SetException (System.Exception exception) [0x00000] in <00000000000000000000000000000000>:0 
  at Framework.Core.Managers.GameLiftClientManager+<GameLiftClientInit>d__22.MoveNext () [0x00000] in <00000000000000000000000000000000>:0 
  at Aws.GameLift.Server.ProcessParameters+OnStartGameSessionDelegate.Invoke (Aws.GameLift.Server.Model.GameSession gameSession) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00000] in <00000000000000000000000000000000>:0 
  at Framework.Utility.ScriptableEvent+ScriptableDelegate.Invoke () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.TimerCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.UnitySynchronizationContext.Exec () [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.TimerCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.UnitySynchronizationContext.Exec () [0x00000] in <00000000000000000000000000000000>:0 
Framework.Core.Managers.ServerLogHandler:LogException(Exception, Object)
UnityEngine.Logger:LogException(Exception, Object)
UnityEngine.Debug:LogException(Exception)
UnityEngine.WorkRequest:Invoke()
UnityEngine.UnitySynchronizationContext:Exec()

Edit: I built the latest SDK and it works. I'm not sure what is the difference between the download and the buillt one, but it works.

ashishdhingra commented 1 month ago

Closing this due to lack of traction and based on last comment that it's fixed with latest version of SDK. Feel free to open new issue in case problem still occurs.

github-actions[bot] commented 1 month ago

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.