NULL reference exception while reading user sessions (Reflection)

前端 未结 6 1121
傲寒
傲寒 2021-01-12 17:54

I have implemented the code for reading the active sessions using the reference Reading All Users Session and Get a list of all active sessions in ASP.NET.

P         


        
6条回答
  •  清酒与你
    2021-01-12 18:38

    It sounds like a different version (or update) of .NET is running on 2003 than you have on XP / Win7, although it could also just be a platform-specific difference. If it was permissions / trust, you would have seen an exception. Instead, it seems more likely that simply: _caches does not exist on whatever version is on the 2003 machine. If you use reflection to access private state: you should entirely expect it to explode between versions / updates / platforms / at-whim / etc.

    To investigate:

    • check whether obj is null
    • check whether obj.GetType().GetField("_caches", BindingFlags.NonPublic | BindingFlags.Instance) is null

    (either of those things could cause this exception on the line you cite)

提交回复
热议问题