So I Instantiated the vars in the Money class, but now get thrown a:
[ 2360953] Failed to instantiate instance of script EGRP.Client.Classes.Environment.UI.Money: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object.
[ 2360968] at EGRP.Client.Classes.Managers.Session..ctor (System.Int32 netId, EGRP.Shared.Data.SessionDataModel model) [0x0003e] in E:\Git\FiveM\EGRP\EGRP\Classes\Managers\Session.cs:35
[ 2360968] at EGRP.Client.Classes.Environment.UI.Money..ctor () [0x00026] in E:\Git\FiveM\EGRP\EGRP\Classes\Environment\UI\Money.cs:37
[ 2360968] at (wrapper managed-to-native) System.Reflection.MonoCMethod:InternalInvoke (System.Reflection.MonoCMethod,object,object[],System.Exception&)
[ 2360968] at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00002] in <f0e9de1592254c6a8c7c298c474f20de>:0
[ 2360968] --- End of inner exception stack trace ---
[ 2360968] at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00014] in <f0e9de1592254c6a8c7c298c474f20de>:0
[ 2360968] at System.RuntimeType.CreateInstanceMono (System.Boolean nonPublic) [0x000a8] in <f0e9de1592254c6a8c7c298c474f20de>:0
[ 2360968] at System.RuntimeType.CreateInstanceSlow (System.Boolean publicOnly, System.Boolean skipCheckThis, System.Boolean fillCache, System.Threading.StackCrawlMark& stackMark) [0x00009] in <f0e9de1592254c6a8c7c298c474f20de>:0
[ 2360968] at System.RuntimeType.CreateInstanceDefaultCtor (System.Boolean publicOnly, System.Boolean skipCheckThis, System.Boolean fillCache, System.Threading.StackCrawlMark& stackMark) [0x00027] in <f0e9de1592254c6a8c7c298c474f20de>:0
[ 2360968] at System.Activator.CreateInstance (System.Type type, System.Boolean nonPublic) [0x00020] in <f0e9de1592254c6a8c7c298c474f20de>:0
[ 2360968] at System.Activator.CreateInstance (System.Type type) [0x00000] in <f0e9de1592254c6a8c7c298c474f20de>:0
[ 2360968] at CitizenFX.Core.InternalManager.CreateAssemblyInternal (System.String assemblyFile, System.Byte[] assemblyData, System.Byte[] symbolData) [0x000bb] in C:\gl\builds\edf06b9b\0\cfx\fivem\code\client\clrcore\InternalManager.cs:103
[ 2360968] Instantiated instance of script EGRP.Client.Classes.Environment.UI.UI.
I dont understand if I have done something wrong on the UI side or if its the Session side, If its the session side Im not sure how to instantiate it there because of the foreach.
Here is the Session.cs, The error is on the first foreach for ProtectedData
private readonly Dictionary<string, dynamic> _protectedData = new Dictionary<string, dynamic>();
private readonly Dictionary<string, dynamic> _sharedData = new Dictionary<string, dynamic>();
/// <summary>
/// The time the session was created in UTC. Not accurate to the exact time they connected as this is dependent
/// on the time it takes for them to load in.
/// </summary>
public readonly DateTime JoinTime = DateTime.UtcNow;
public Session(int netId, SessionDataModel model)
{
NetId = netId;
Name = model.Name;
foreach (var kvp in model.ProtectedData)
{
_protectedData[kvp.Key] = kvp.Value;
}
foreach (var kvp in model.SharedData)
{
_sharedData[kvp.Key] = kvp.Value;
}
}
My Money UI.cs
public Money()
{
Tick += OnTick;
//Loading the SessionDataModel from Shared
data = new SessionDataModel();
//Loading the Session for Client
session = new Session(Player.ServerId, data);
}
private async Task OnTick()
{
//if (CinematicMode.DoHideHud) return;
try
{
// Setting the Text Color
var color = System.Drawing.Color.FromArgb(255, 255, 255, 255);
// Setting the Text Position
Vector2 position = new Vector2(0.18f, 0.93f);
/*
*
* Need to Instantiate both var data and var session for the UI to work...
*
*/
// Setting Cash UI Text
string cashText = $"${session.GetProtectedData("Bank.Cash")}";
DrawText($"{cashText}", 1617f, 43f, 0.7f, 255, 255, 255, 255, 0, 0, false, false, 0, 0, 0);
Log.Info(cashText);
}
catch (Exception ex)
{
Log.Info(ex.Message);
}
await Task.FromResult(0);
}