Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
1 task done
jasonboukheir opened this issue Nov 19, 2020 · 9 comments
Labels
bug This issue is a bug. module/unity p2 This is a standard priority issue queued

Comments

@jasonboukheir
Copy link

jasonboukheir commented Nov 19, 2020

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

  • SDK Version: 3.3.802
  • Package Version:
  • OS Info: Android
  • Build Environment Unity
  • Targeted .NET Platform: 4.7 Framework (Android IL2CPP)

Resolution

  • 👋 I can/would-like-to implement a fix for this problem myself -- I just need a little support on how I can rebuild it with the suggested changes below:

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-report

@jasonboukheir jasonboukheir added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Nov 19, 2020
@ashishdhingra ashishdhingra added module/unity and removed needs-triage This issue or PR still needs to be triaged. labels Nov 19, 2020
@AdamBebko
Copy link

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

@jasonboukheir
Copy link
Author

jasonboukheir commented Nov 29, 2020

@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
Copy link

AdamBebko commented Nov 29, 2020

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
Copy link

Rockbag commented Dec 4, 2020

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
Copy link

Rockbag commented Dec 7, 2020

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
Copy link

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.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Jan 12, 2022
@hunanniu hunanniu reopened this Feb 14, 2022
@gabetoth-alder
Copy link

gabetoth-alder commented Jul 12, 2022

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 ashishdhingra added p2 This is a standard priority issue and removed A labels Nov 1, 2022
@ashishdhingra
Copy link
Contributor

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.

@ashishdhingra ashishdhingra closed this as not planned Won't fix, can't repro, duplicate, stale Jul 25, 2024
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. module/unity p2 This is a standard priority issue queued
Projects
None yet
Development

No branches or pull requests

6 participants