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

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

1 Like

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?

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…

11 Likes

Thanks! I had no idea what the error was about.

Thanks rpopic2. Bug Fixed!

Same problem,
I only found the Unity IAP plugin but it seems correct.

   public class CodelessIAPStoreListener : IStoreListener
    {
        private static CodelessIAPStoreListener instance;
        private List<IAPButton> activeButtons = new List<IAPButton> ();
        private List<IAPListener> activeListeners = new List<IAPListener> ();
        private static bool unityPurchasingInitialized;

        protected IStoreController controller;
        protected IExtensionProvider extensions;
        protected ProductCatalog catalog;

        // Allows outside sources to know whether the full initialization has taken place.
        public static bool initializationComplete;
       
        [RuntimeInitializeOnLoadMethod]
        static void InitializeCodelessPurchasingOnLoad() {
            ProductCatalog catalog = ProductCatalog.LoadDefaultCatalog();
            if (catalog.enableCodelessAutoInitialization && !catalog.IsEmpty() && instance == null)
            {
                CreateCodelessIAPStoreListenerInstance();
            }
        }

Still have the error when I comment this code.

Are you sure UnityEditor.EditorAssemblies.ProcessInitializeOnLoadAttributes ()
is being called? What does the log print?