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. Dismiss Notice

When using Net Core, I receive errores about denote not valid type

Discussion in 'Windows' started by latas, Mar 30, 2014.

  1. latas

    latas

    Joined:
    Oct 9, 2013
    Posts:
    149
    When building for Windows 8.1, and using Net Core ( complete not partially ) I receive an error in several scripts saying "... denote not valid type".

    I can see that the scripts reporting that are those javascript (unityScripts) which has variable references to classes of C#. Those C# classes are stored in Standard Assets to use the feature of compilation order. In fact that works for unity Editor and also for compilation in Mac, iOS and Android. So why I've got this error trying to build my project for Windows 8.1.

    It looks the compilation order is not working.

    I'm using Unity Pro 4.3.2 ( Not using 4.3.4 because the issue with System.Reflection.GetMember ... http://forum.unity3d.com/threads/223065-Unity-4-3-3-Type-GetMembers(BindingFlags)-crash )

    Thanks.
     
    Last edited: Mar 30, 2014
  2. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,658
    That's normal, if you set Compilation Overrides to Net Core, js scripts can't reference any classes from C# scripts
     
  3. latas

    latas

    Joined:
    Oct 9, 2013
    Posts:
    149
    But If I set Net Core Partially, it looks NETFX_CORE define is not sent, because some of C# files which has NETFX_CORE #if condition looks not working. Is that correct? I mean, that working way is right? Because of that the script during compilation is taking a way which is raising API errors in the WACK validation.

    Any idea?
     
  4. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,658
    If you set Net Core Partially, then C# located in folders - Plugins, Standard Assets, Pro Standard Assets are compiled with Mono compiler (which doesn't know anything about .NET Core, thus NETFX_CORE is not defined), but then JS and Boo can reference classes from C# files located in those folders. So ye, this expected. If you want to use WinRT API with NETFX_CORE define, you should move C# files out of those folders. That said, you cannot use WinRT API in js or Boo files.
     
  5. CanisLupus

    CanisLupus

    Joined:
    Jul 29, 2013
    Posts:
    427
    @Tomas1856 Sorry for reviving this old thread, but I've just faced this problem. To be perfectly clear:

    1. JS code can only call C# code if said C# code is in the Plugins folder.
    2. For WSA, JS code can only call C# code if "Use Net Core Partially" is active.
    3. If "Use Net Core Partially" is active, Mono is used instead of the .NET compiler, therefore we can't ever use the WinRT API (and NETFX_CORE is never active).

    Is this correct?

    Does this mean that you can't use JS for WSA builds at all if you require file access, even if said file access is done in C# scripts? Is there a way to do this otherwise? Is using pre-compiled DLLs instead of straight up C# code an option?
     
  6. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,491
    @CanisLupus you have several options.

    First option is using a bridge:

    1. In C# code that's in Plugins folder make an interface that has methods you'd use NETFX_CORE API in and have a static variable somewhere of that interface type.
    2. In C# code that's in non-plugins folder (and cannot be referenced by JS directly) implement that interface and call WinRT APIs in it. At startup, set the static variable that's defined in the plugins C# code to your implementation object.
    3. Call those interface methods through JS.

    The second option is precompiling your code into a DLL, but there's a catch:

    1. You'll need to make two DLLs - one that targets .NET 3.5 and will be referenced when you press play in the editor and when Unity compiles your JS scripts for the game release, and one that actually calls into WinRT APIs (and targets .NET Core instead). These DLLs have to have identical public API surface.
    2. Put both of them into your project, then in plugin inspector make .NET 3.5 one compatible with editor, make .NET Core one compatible with Windows Store and finally on the .NET Core one set the placeholder value to .NET 3.5 one as described here: http://docs.unity3d.com/Manual/windowsstore-plugins.html
     
  7. CanisLupus

    CanisLupus

    Joined:
    Jul 29, 2013
    Posts:
    427
    @Tautvydas Zilys Thank you very much for the detailed answer. This should help! :)