Search Unity

Editor error after run

Discussion in 'Scripting' started by Alex1337rus, Jan 28, 2019.

  1. Alex1337rus

    Alex1337rus

    Joined:
    Mar 30, 2016
    Posts:
    37
    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):
    1.  
    2. class ChainClass
    3. {
    4.     public unsafe struct HashForgetfulChain
    5.     {
    6.         private fixed ushort banks_[1524288];
    7.     }
    8.  
    9.     public static HashForgetfulChain m2()
    10.     {
    11.         return new HashForgetfulChain();
    12.     }
    13. }
    14.  
    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)
     
    Last edited: Jan 30, 2019
  2. Alex1337rus

    Alex1337rus

    Joined:
    Mar 30, 2016
    Posts:
    37
    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?
     
  3. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,196
    One thing to check if whether you've got "Allow 'unsafe' code" checked in the Player project settings.
     
  4. Alex1337rus

    Alex1337rus

    Joined:
    Mar 30, 2016
    Posts:
    37
    Yes, it's enabled.
     
  5. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,196
    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?
     
  6. Alex1337rus

    Alex1337rus

    Joined:
    Mar 30, 2016
    Posts:
    37
    Oh sorry, I have modified the code and forgot to change the error. Now it's correct.
     
  7. Alex1337rus

    Alex1337rus

    Joined:
    Mar 30, 2016
    Posts:
    37
  8. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,196
    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?
     
  9. Alex1337rus

    Alex1337rus

    Joined:
    Mar 30, 2016
    Posts:
    37
    I have modified code and now HashForgetfulChain used only in "m2" method.
     
  10. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,196
    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.
     
    Alex1337rus likes this.
  11. Alex1337rus

    Alex1337rus

    Joined:
    Mar 30, 2016
    Posts:
    37
    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!