A
A
Alexander2021-12-20 19:22:02
.NET
Alexander, 2021-12-20 19:22:02

How to properly initialize an object?

It throws an error when I try to subscribe to an event.

System.NullReferenceException: 'Object reference not set to an instance of an object.'


Instance.manager.Subscribe<SteamClient.ConnectedCallback>(BinVerify.OnConnected);


The event for the subscription.
public static void OnConnected(SteamClient.ConnectedCallback callback)
        {
            Console.WriteLine($"Connected to Steam! Logging in '{Instance.botConfig.login}'...");
            byte[] sentryHash = null;
            if (File.Exists("sentry.bin"))
            {
                // if we have a saved sentry file, read and sha-1 hash it
                byte[] sentryFile = File.ReadAllBytes("sentry.bin");
                sentryHash = CryptoHelper.SHAHash(sentryFile);
            }
            Instance.steamUser.LogOn(new SteamUser.LogOnDetails
            {
                Username = Instance.botConfig.login,
                Password = Instance.botConfig.password,
                // in this sample, we pass in an additional authcode
                // this value will be null (which is the default) for our first logon attempt
                AuthCode = Instance.authCode,
                TwoFactorCode = Instance.twoFactorAuth,

                // our subsequent logons use the hash of the sentry file as proof of ownership of the file
                // this will also be null for our first (no authcode) and second (authcode only) logon attempts
                SentryFileHash = sentryHash,
                ClientLanguage = "Russian"
            });
        }


Instance is just a container of objects where all the data is.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question