Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

2018.1) TargetException: Non-static method requires a target.

Discussion in 'Editor & General Support' started by rpopic2, May 3, 2018.

  1. rpopic2

    rpopic2

    Joined:
    Apr 15, 2018
    Posts:
    15
    Edit: This issue is now solved. Please check the reply at the bottom.

    Anyone who is using "Narrate" plugin in 2018.1, and having this issue, please check the reply at the bottom


    I updated my project to 2018.1.0f2 from 2017.4.2f2.
    And I am somehow having really hard time upgrading to it.

    And this is the last error left, I've searched forums, and I have no idea where this error is coming from:




    TargetException: Non-static method requires a target.
    System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:236)
    System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115)
    UnityEditor.EditorAssemblies.ProcessInitializeOnLoadMethod (System.Reflection.MethodInfo method) (at C:/buildslave/unity/build/Editor/Mono/EditorAssemblies.cs:116)
    UnityEditor.EditorAssemblies.ProcessInitializeOnLoadAttributes () (at C:/buildslave/unity/build/Editor/Mono/EditorAssemblies.cs:135)



    It seems like it is pointing my unity's internal folder? Is my unity editor corrupt?
    How should I fix this?

    Edit :
    Now I'm getting these messages when I enter play mode

    Allocation of 33 bytes at 00000000062E60E0



    Assertion failed: TLS Allocator ALLOC_TEMP_THREAD, underlying allocator ALLOC_TEMP_THREAD has unfreed allocations, size 33



    Please help
     
    Last edited: May 3, 2018
  2. rpopic2

    rpopic2

    Joined:
    Apr 15, 2018
    Posts:
    15
    Well, I figured out that this was caused by an asset called "Narrate", and seems it is not compatible with 2018.1.
    I'm still figuring out how can I fix this asset.. Anyone got some idea? Where should I look at?
     
  3. rpopic2

    rpopic2

    Joined:
    Apr 15, 2018
    Posts:
    15
    I finally solved the problem. It has to do with the [InitializeOnLoadMethod] attribute.
    So, every method that has [InitializeOnLoadMethod] attribute, should be a static function, according to the manual.
    And versions prior to 2018.1.0f2 seems like it doesn't care whether the function is static or not.


    But when you are using 2018.1.0f2, it throws

    TargetException: Non-static method requires a target.

    And in the details you will see

    UnityEditor.EditorAssemblies.ProcessInitializeOnLoadAttributes ()


    is being called.

    So when such error occurs, just search [InitializeOnLoadMethod] attribute on your entire solution, and make sure that method is static.

    The "Narrate" plugin (link) has such attribute without static modifier in NarrationManagerInspector.cs, and all you have to do is putting static modifier in front of the method.

    Hope this helps. It took my whole day to solve this problem..lol..
     
    Last edited: May 16, 2018
    azicii, Laiken, zerosimms and 6 others like this.
  4. IvyKun

    IvyKun

    Joined:
    Sep 28, 2013
    Posts:
    131
    Thanks! I had no idea what the error was about.
     
  5. BugKiller

    BugKiller

    Joined:
    May 8, 2014
    Posts:
    23
    Thanks rpopic2. Bug Fixed!
     
  6. BenoitFreslon

    BenoitFreslon

    Joined:
    Jan 16, 2013
    Posts:
    163
    Same problem,
    I only found the Unity IAP plugin but it seems correct.
    Code (CSharp):
    1.    public class CodelessIAPStoreListener : IStoreListener
    2.     {
    3.         private static CodelessIAPStoreListener instance;
    4.         private List<IAPButton> activeButtons = new List<IAPButton> ();
    5.         private List<IAPListener> activeListeners = new List<IAPListener> ();
    6.         private static bool unityPurchasingInitialized;
    7.  
    8.         protected IStoreController controller;
    9.         protected IExtensionProvider extensions;
    10.         protected ProductCatalog catalog;
    11.  
    12.         // Allows outside sources to know whether the full initialization has taken place.
    13.         public static bool initializationComplete;
    14.        
    15.         [RuntimeInitializeOnLoadMethod]
    16.         static void InitializeCodelessPurchasingOnLoad() {
    17.             ProductCatalog catalog = ProductCatalog.LoadDefaultCatalog();
    18.             if (catalog.enableCodelessAutoInitialization && !catalog.IsEmpty() && instance == null)
    19.             {
    20.                 CreateCodelessIAPStoreListenerInstance();
    21.             }
    22.         }
    23.        
    Still have the error when I comment this code.
     
  7. rpopic2

    rpopic2

    Joined:
    Apr 15, 2018
    Posts:
    15
    Are you sure UnityEditor.EditorAssemblies.ProcessInitializeOnLoadAttributes ()
    is being called? What does the log print?