Hi! I have TypeLoadException after running my project without any object on scene. I have only file with this code in project directory. Code (CSharp): class ChainClass { public unsafe struct HashForgetfulChain { private fixed ushort banks_[1524288]; } public static HashForgetfulChain m2() { return new HashForgetfulChain(); } } StackTrace: TypeLoadException: Could not load type 'HashForgetfulChain' from assembly 'Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'. System.Reflection.MonoMethodInfo.GetMethodInfo (IntPtr handle) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:59) System.Reflection.MonoMethodInfo.GetAttributes (IntPtr handle) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:75) System.Reflection.MonoMethod.get_Attributes () (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:245) System.Reflection.MethodBase.get_IsSpecialName () (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MethodBase.cs:184) UnityEditor.Build.BuildPipelineInterfaces.InitializeBuildCallbacks (Boolean findBuildProcessors, Boolean findSceneProcessors) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/BuildPipelineInterfaces.cs:149)
This is not my code, but only part of a project from github. I left only the minimum part to reproduce the error. How can i fix this?
One thing to check if whether you've got "Allow 'unsafe' code" checked in the Player project settings.
Oh. So your exception is complaining about the class HashForgetfulChain, which you haven't shown here. Is that in a DLL you've imported? Is it a Native or Managed plugin? Or, where is the HashForgetfulChain class?
Can you show a line of code that's calling or trying to use the HashForgetfulChain struct? I don't know much of anything about unsafe code, and I understand that nested classes/structs can be public even if the outer class is private, but maybe see if making ChainClass public changes the behavior?
I just tried out this code to see what was going on, and got the same error. Look carefully at the error and you should hopefully see the issue: It seems that trying to initialize banks_ to contain so many elements (about 1.5 million) causes the error. Changing `banks_[1524288];` to `banks_[10];`, for example, caused the code to run without issue. So you'd have to decide whether that array really needs to be so large, or whether it'll work fine with a small size.
This error really explains what the problem is in the size of the structure and not in something else. I will try to do something with this. Thanks for the help!