planetarium / libplanet

Blockchain in C#/.NET for on-chain, decentralized gaming
https://docs.libplanet.io/
GNU Lesser General Public License v2.1
505 stars 139 forks source link

Currency structure occurs CS0188 error in TargetFramework net6.0 or greater #3844

Open s2quake opened 1 week ago

s2quake commented 1 week ago

The detailed message of the CS0188 error is shown below

error CS0188: The 'this' object cannot be used before all of its fields have been assigned.

In the Currency struct constructor, it uses a local method called GetHash to set a value in a field called Hash. This violates the rule described above. I think the problem would be solved if the field Hash didn't need to be defined, but rather calculated and used as needed.

        public Currency(IValue serialized)
        {
            ...
            Hash = GetHash(); // CS0188 error
        }

https://github.com/planetarium/libplanet/blob/87c5fdffc0d7e81e9694b3ce45b27d66677b6767/Libplanet.Types/Assets/Currency.cs#L246