Search Unity

"The script behaviour could not be instantiated" - UWP error in 5.4.0f3

Discussion in 'Windows' started by samizzo, Jul 29, 2016.

  1. samizzo

    samizzo

    Joined:
    Sep 7, 2011
    Posts:
    487
    I'm getting an error running a UWP app on Windows 10. In my project I have a DLL which contains a MonoBehaviour called RemoteDebugServer that is added dynamically from another MonoBehaviour which is in the project (but not in the DLL). This is in the project:

    Code (csharp):
    1. using UnityEngine;
    2. using Hdg;
    3.  
    4. public class RemoteDebugServerFactory : MonoBehaviour
    5. {
    6.     public void Awake()
    7.     {
    8.         gameObject.AddComponent<RemoteDebugServer>();
    9.     }
    10. }
    When the AddComponent runs, in the output window in VS I see:

    Code (csharp):
    1. The script behaviour 'Hdg.RemoteDebugServer' could not be instantiated!
    In 5.3.5f1 I get a crash instead in UnityPlayer.dll!scripting_object_new(DotNetType * t) Line 79 and this message in the output:

    and a message in the output window saying instanceId != -1.

    The same code when included in the Unity project wholesale works fine. It's only when I compile it to a DLL that it doesn't work. The DLL solution is set to Target Version and Min Version 10240 and it's a UWP class library project.

    I'm running this from Windows 8.1 and deploying to a remote Windows 10 machine, if that makes any difference. I'm using Visual Studio Community 2015 with update 2.
     
  2. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,732
    This instaceId error souds like a tail of the actual problem, but we need more data on how everything looks like in your project. Can you try narrow down everything to the smallest possible project where the same error occurs?
     
  3. samizzo

    samizzo

    Joined:
    Sep 7, 2011
    Posts:
    487
    Thanks for the reply. I figured the crash had been fixed in 5.4 with the "could not be instantiated" message instead. I'll pull the DLL apart until it I have something small - there is quite a lot in there and the RemoteDebugServer class is the entry point that ties everything together, so it references almost everything.
     
  4. samizzo

    samizzo

    Joined:
    Sep 7, 2011
    Posts:
    487
    Ok I've got a super basic DLL now, with an empty MonoBehaviour-derived class, and it's still happening. I'm not sure where to start looking now for the problem. Should I submit a bug report with the Unity project and DLL solution?

    This is what my project.json looks like for the DLL:
    Code (csharp):
    1. {
    2.   "dependencies": {
    3.     "Microsoft.NETCore.UniversalWindowsPlatform": "5.0.0"
    4.   },
    5.   "frameworks": {
    6.     "uap10.0": {}
    7.   },
    8.   "runtimes": {
    9.     "win10-arm": {},
    10.     "win10-arm-aot": {},
    11.     "win10-x86": {},
    12.     "win10-x86-aot": {},
    13.     "win10-x64": {},
    14.     "win10-x64-aot": {}
    15.   }
    16. }
    My references are:
    Code (csharp):
    1. Analyzers
    2. Microsoft.NETCore.UniversalWindowsPlatform
    3. UnityEngine
    4. Universal Windows
    The only class in the DLL looks like this:
    Code (csharp):
    1. using UnityEngine;
    2.  
    3. namespace Hdg
    4. {
    5.     public class RemoteDebugServer : MonoBehaviour
    6.     {
    7.     }
    8. }
     
  5. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,732
    Can you show plugin importer settings for that dll?
     
  6. samizzo

    samizzo

    Joined:
    Sep 7, 2011
    Posts:
    487
    Yep, it's set to WSAPlayer/UWP/Any scripting backend, I've attached a screenshot.
     

    Attached Files:

  7. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,906
    Why did you mark it Dont Process, Unity cannot extract types from because of this...
     
  8. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,732
    That's what I suspected: dlls that have MonoBehaviours or anything that is serialized by Unity must be processed in order to be usable on WSA platform.
    You can only mark dll "Don't process" if it's only a code that your scripts call, but not anything that plays a role in scene etc.
     
  9. samizzo

    samizzo

    Joined:
    Sep 7, 2011
    Posts:
    487
    Ahhh, thank you so much. Man I'm so stupid, I don't know why I had that checked. I had it in my head for some reason that I needed to avoid the Unity patching, but from what you guys have said, and from reading the docs again I see that Unity needs to inject some IL if there are Unity-serialisable classes in there, which obviously MonoBehaviour is. Thank you again!