ScriptableObject private readonly field is null on Mono build

Hi, I have a private readonly class field of a ScriptableObject, named IntPlayerPref, which inherits from PlayerPref (abstract class), it works in Editor but in Mono build the ServerEnvironment getter down below throws a NullReferenceException.

Is this a known issue?

        private readonly IntPlayerPref ServerEnvironmentPref = new IntPlayerPref(nameof(ServerEnvironment), PathHashPostfix.OnlyInEditor, (int)GameApplicationBuildArgs.GetDefaultServerEnvironment());

        [ShowInInspector, Title("Server Environment"), PropertyOrder(100)]
        public ServerEnvironment ServerEnvironment
        {
            get
            {
                // This throws NullReferenceException on build, ServerEnvironmentPref is null
                return (ServerEnvironment)ServerEnvironmentPref.Value;
            }
            set => ServerEnvironmentPref.Value = (int)value;
        }

Edit: This is solved. It’s not a Unity bug, the Constructor was throwing an exception on build

You probably need to turn line 1 into a lazy getter that you access and it calls a constructor the first time, storing it to a backing store and returning that instance after that. The reason is that lots of Unity stuff cannot be called at typical Monobehaviour “constructor” time, since those are called on another thread when you hit .AddComponent() or the object gets stood up in the scene.