state.speed lead to System.TypeInitializationException in VS with.NET native

Hello I have some trouble with my build for UWP. My script as shown below works great in editor, pc stand alone , Mac stand alone, Mac App Store, but throw Exception in master build with .NET native and it come up that it could be because of my script that manage animation speed of a key-frame animation single layer
I have already ask for help in the windows part of the forum but I would like to know if you guys from the "script department " you see anything wrong with my script it may look messy but it works everywhere except in master build +.NET native
it says that state.speed is the issue but I don’t know how to fix that I need state.speed to define my animation speed :s
could you guys please have a quick look at it and maybe tel me where I’m wrong ?
here is the javascript ( sorry I m not good at C#):

#pragma strict 
var speed=1.0;
var speed2=-1.0;
var speed3=0.0;
var speed4=2.0;
var speed5=0.3;
var Cam12: Camera;


function Update () {
   // Set all animations to pingpong
   //
  
   GetComponent.<Animation>().wrapMode = WrapMode.Loop;
   for (var state : AnimationState in GetComponent.<Animation>()) {
  
    if ( Input.GetMouseButtonDown(0) )
   {
   // bit shift the index of the layer to get a bit mask
var layerMask = 1 << 9;
// Does the ray intersect any objects which are in the player layer.
//if (Physics.Raycast (transform.position, Vector3.forward, Mathf.Infinity, layerMask))
    //print ("The ray hit the player");

      var hit : RaycastHit;
      var ray : Ray = Cam12.ScreenPointToRay (Input.mousePosition);
      if (Physics.Raycast (ray, hit, 1000.0))
     {
         Debug.Log(hit.collider.gameObject.name);
        if (hit.collider.gameObject.tag== "stop")
        {
state.speed = speed;
GetComponent.<Animation>().Rewind();

GetComponent.<Animation>().Play();

   }
    if (hit.collider.gameObject.tag== "fastrewind")
        {
state.speed =speed2;

   }
   if (hit.collider.gameObject.tag== "pause")
        {
state.speed =speed3;

   }
   if (hit.collider.gameObject.tag== "play")
        {
state.speed =speed;

   }
   if (hit.collider.gameObject.tag== "fastforward")
        {
state.speed =speed4;

   }
   if (hit.collider.gameObject.tag== "slowmo")
        {
state.speed =speed5;

   }
  // else  state.speed =speed; 

}
}
}
}

and here is the VS error

Thank you very much!

This is what I get without optimisation the error is still here

Could you write out the entire text of the error message you’ve got on top of your first screen shot? The one that says “TypeInitializationError”? It ends with “but was referenced in Exten…”

It looks like it’s saying “but was referenced in Extension method Foo”, where Foo is whatever you want to put in the bug report to Unity. We’ve had issues in the past - not on UWP but for consoles - where Unity’s put code in their core somewhere that simply can’t run on that platform.

By the way, Unity announced on Unite this year that they’re deprecating UnityScript, so time to learn C#!

1 Like

I know I have to learn C#, I am just scared of the big complicated C# lol, jvs is some how more syntax intuitive and like the previous language Iearned ( I learn first with qbasic then amstrad c++… lol), but time to evolve I guess lol . Does it mean that I have to rewrite all my javascript scripts into C#? or will they still work? Deprecating mean no new insertion, what is in the project still compile isn’t it?

Would that specific script work with .NET if it was a C# script?

Here is the full statement for this particular error :

  • $exception
    {System.TypeInitializationException: TypeInitialization_Type_NoTypeAvailable —> System.Exception: Method ‘Type.GetMembers(BindingFlags)’ was not included in compilation, but was referenced in ExtensionRegistry.AddExtensionMembers(List, Type). There may have been a missing assembly.
    at Boo.Lang.Runtime.ExtensionRegistry.Register(Type type)
    at Boo.Lang.Runtime.RuntimeServices.RegisterExtensions(Type extensions)
    at UnityScript.Lang.UnityRuntimeServices…cctor()
    at System.Runtime.CompilerServices.ClassConstructorRunner.Call[T](IntPtr pfn)
    at System.Runtime.CompilerServices.ClassConstructorRunner.EnsureClassConstructorRun(Void* returnValue, StaticClassConstructionContext* pContext) in f:\dd\ndp\fxcore\CoreRT\src\System.Private.CoreLib\src\System\Runtime\CompilerServices\ClassConstructorRunner.cs:line 72
    Exception_EndOfInnerExceptionStack} System.Exception {System.TypeInitializationException}

What should I do?

I don’t run any Boo script by the way
Thanks for your help!

I’m pretty sure Boo is used to make UnityScript work behind the scenes. Which is why you’ll see Boo.Lang deep in the stack trace for UnityScript stuff. That’s based on a rumor I heard once, so take that with a grain of salt.

The error is that the method Type.GetMembers can’t be found, but it’s used by “Boo.Lang.Runtime.ExtensionRegistry.Register”. I don’t know what ExtensionRegistry is, but I know what Type.GetMembers is - it’s a reflection method that gives you the members (variables, methods, etc.) of a type.

Reflection is dissallowed by quite a few platforms, because it enables developers to do quite a few tricky things that could get around safety features. It might be that Unity’s using some reflection things behind the scenes to make UnityScript work on on UWP? Not sure.

This very much looks like a bug in the engine, and not your fault. You should send a bug report detailing what’s wrong. If you include your project, and the message “this 100% does not compile on UWP, but compiles on every other platform”, that’ll be a big red flag and might get fixed fast.

To try to fix it, mess around with the player settings. Check if changing to IL2CPP (or changing away from it) helps. Switch to/from .NET2 subset. If none of those work, consider re-writing this specific script in C#, if that’s viable.

If it has dependencies to other things or other things depend on it, create a small C# script that does the little thing that’s failing to compile, put that script in plugins, and use it to do the work you’re trying to do.

Deprecation means that feature will stop getting support. Unity will not create documentation for it. Unity will not create bug fixes for it. Unity will not support it in other products they make - like collaborate and and such. In essence, it’s a message that “you should stop using this ASAP” and “we don’t guarantee that this works anymore”.

You can still write boo scripts, and Unity compiles them just fine. We’ve got some years old boo scripts for the editor that we never got around to updating. But they can break at any update, and we can’t complain to Unity if they do.

Great thank you very much this problem is really annoying cause it is only a problem with .NET native :s I am in contact with Tautvydas-Zilys from Unity tech. So hopefully something should happen :), cannot really send my project the whole project from unity unbuild is about few gigas I am trying to translate my code into C# do you think it will work then ? man I try hard but I am more reading the unity documentation then typing coding goes really slowly lol I need a drink cheers!