Search Unity

Unity 4.3.3 Type.GetMembers(BindingFlags) crash

Discussion in 'Windows' started by koblykdmitry, Jan 17, 2014.

  1. koblykdmitry

    koblykdmitry

    Joined:
    Jan 17, 2014
    Posts:
    14
    After upgrade to 4.3.3 Type.GetMethods(BindingFlags) and other abstract methods in Type class don't work in windows phone. All builds fine, but on execution we get MissingMethodException. In Unity 4.3.2 all worked.

    I attached test project that illustrates this problem.
     

    Attached Files:

  2. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,736
    Please, submit a bug report.
     
  3. Qbit86

    Qbit86

    Joined:
    Sep 2, 2013
    Posts:
    487
    Run into the similar problem: “Exception: Method not found: 'System.TypeCode System.Type.GetTypeCode(System.Type)'.”
    http://goo.gl/DvQ8NH
    Please notify me if there are some updates on this topic.

    Upd. Script to reproduce:
    Code (csharp):
    1. sealed class IssueReproductionScript : UnityEngine.MonoBehaviour
    2. {
    3.     internal void OnGUI()
    4.     {
    5.         UnityEngine.GUILayout.Label(_label);
    6.     }
    7.  
    8.     internal void Start()
    9.     {
    10.         try
    11.         {
    12.             var typeCode = System.Type.GetTypeCode(typeof(System.DateTime));
    13.             _label = typeCode.ToString();
    14.             UnityEngine.Debug.Log(_label);
    15.         }
    16.         catch (System.Exception ex)
    17.         {
    18.             _label = ex.ToString();
    19.             UnityEngine.Debug.LogError(_label);
    20.         }
    21.     }
    22.  
    23.     private string _label = System.DateTime.Now.ToString("s");
    24. }
     
  4. adbourdages

    adbourdages

    Joined:
    Jul 8, 2012
    Posts:
    75
    I've been facing the same issue all day with 4.3.3. After reading the thread, I downgraded to 4.3.2 and the game now runs perfectly fine.

    The missing methods were [List<PropertyInfo>[] Type.GetProperties(BindingFlags)] and [System.TypeCode System.Type.GetTypeCode(System.Type)].

    Alain-Daniel
     
  5. bem13

    bem13

    Joined:
    Jul 1, 2010
    Posts:
    64
    I have been having same Missing Method exception problem with System.Type.GetMethod (and System.Type.GetFields ??).

    I have been trying to write a workaround that calls through to the WP8 side, but this hits the problem that when I try to write a function inside my VS project that uses binding flags it tells me it has been defined twice. (once in WinRTLegacy.dll, once somewhere else that I think comes from windows.. mscorelib perhaps?)

    I can use an alias to reference the BindingFlags inside WinRTLegacy, but have not yet figured out how to reference the other version in order to try to call the original, correct functions from inside by WP8 visual studio project.

    Sorry about fuzzy description. Since this apparently is a bug, I can give a proper bug report when I get back to work.
     
  6. adbourdages

    adbourdages

    Joined:
    Jul 8, 2012
    Posts:
    75
    @bem13: I "solved" the problem by going back to version 4.3.2 of Unity. Unless there is something specific you need from 4.3.3, it shouldn't cause trouble at all.
     
  7. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    Hi,

    we found the cause of this. It's a regression that made its way with updated WinRTLegacy.dll. We added bunch of types unavailable to WP8/Windows Store Apps to it in 4.3.3, like System.IO.StreamReader and System.Reflection.BindingFlags. We didn't notice that the latter is actually available on Windows Phone 8, so by adding it, we introduced the bug where type assembly and method assembly doesn't match, thus the error.

    There's a workaround, though:

    Install Unity 4.3.2 to a separate folder, and copy Editor\Data\PlaybackEngines\wp8support\Managed\WinRTLegacy.dll to the same place in Unity 4.3.3 installation folder. I know it's not very nice, but that's the best solution we can offer you at this moment.

    NOTE: Always backup your project before trying something like this.
     
  8. Qbit86

    Qbit86

    Joined:
    Sep 2, 2013
    Posts:
    487
    Tautvydas, thank you very much for response!

    Are there any estimates when the next fixed version of Unity will be available?
     
  9. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    I don't think so. I wouldn't count on it coming very soon, though, especially since there is a workaround.
     
  10. adbourdages

    adbourdages

    Joined:
    Jul 8, 2012
    Posts:
    75
    Thanks guys for looking into this!
     
  11. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    Just an FYI, I filed a bug report on this as well as it completely broke my JSON .NET Serializer running on the device for Windows Phone using Unity 4.3.3. This update has broken some very basic underlying functionality and I'm hoping it is fixed soon. I'm finding it a bit hard to believe that there is no plan to fix a bug that was just introduced simply because there's a workaround for it. It's one thing if it had broken something in the Unity API, but it broke some basic .NET functionality.
     
  12. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,462
    It's really not at all a professional and responsible attitude for an Awesome company like Unity to create a bug and then let its customers to "work around" the bug.
     
  13. Peter Rush

    Peter Rush

    Joined:
    Mar 25, 2013
    Posts:
    9
    Hi, I couldnt spot this in the issue tracker but I didn't see mention of it being fixed in 4.3.4. (havent installed 4.3.4 yet because I dont know if the workaround is still robust)

    Any updates? I would certainly vote this one up if it is in the tracker!
     
  14. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    I submitted a bug on the 27th:

    #587845

    It's still marked as "Open" and hasn't made it into the issue tracker yet. I'm assuming the same workaround will work and it's not fixed yet in 4.3.4 since that update only fixed an iOS issue. If it's still not working on 4.3.4 you should submit another bug. By the sound of the developer's comments above, this one will likely go largely ignored unless some folks push for it. I'll update here if my bug ever gets put into the issue tracker so you can vote for it.
     
  15. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    Hi,

    when I wrote that we discovered what was wrong, that was the day we fixed it internally. Sorry for not making it clear. The fix will be included in the very next Unity release (not 4.3.x).

    As for the workaround, it will work on 4.3.4 as well.
     
    Last edited: Feb 3, 2014
  16. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    Thanks for the clarification. Glad you guys are fixing it. I realize it may not have been the highest priority because Windows Phone has a lower saturation and I think any level headed individual would understand that. I was just concerned because of this comment:

    Which made it appear that you had completely deprioritized it.
     
  17. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    I see. By that I meant that we aren't pushing a hotfix for this issue.
     
  18. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,072
    Tautvydas: Will the missing GetTypeCode get fixed in the next update?
    4.3.x won't get the fixes?
     
  19. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    That's what he's saying yes. It won't be hotfixed but it will be included in the next release (probably 4.4.0 would be my guess). It'll be in the next minor revision but not hot fixed into a 4.3.x release.
     
  20. zzeettoo

    zzeettoo

    Joined:
    Apr 26, 2013
    Posts:
    23
    i did the workaround and copied the dll from 4.3.2 to my 4.3.3 folder.
    no i'm getting the next error:
    Error building Player: Exception: Failed to run assembly preprocessor with command line "Temp/StagingArea/Data/Managed\Boo.Lang.dll" -injectCtor -assemblyPath "Temp/StagingArea" -pdb.[Temp/StagingArea/Data/Managed\Boo.Lang.dll]
    No symbols for Temp/StagingArea/Data/Managed\Boo.Lang.dll
    Injecting ctor
    Error while in assembly preprocessor Temp/StagingArea/Data/Managed\Boo.Lang.dll
     
  21. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    Can you post the full error message?
     
  22. zzeettoo

    zzeettoo

    Joined:
    Apr 26, 2013
    Posts:
    23
    well, right now i 'solved' the problem by using 4.3.2 completely instead of just copying the dll.
    So i work within the latest version and for wp8 network builds i use 4.3.2 :(
     
  23. latas

    latas

    Joined:
    Oct 9, 2013
    Posts:
    149
    But using 4.3.2 has other issue which is trying to pass the Microsoft App Kit Store validation. You get something like this:

    API System.Reflection.MemberTypes in MSCORLIB, PUBLICKEYTOKEN=B77A5C561934E089 is not supported for this application type. Assembly-CSharp-firstpass.dll calls this API.
    API System.IO.File in MSCORLIB, PUBLICKEYTOKEN=B77A5C561934E089 is not supported for this application type. Assembly-CSharp-firstpass.dll calls this API.
    API System.Threading.Thread.VolatileWrite(System.Int32@,System.Int32) in MSCORLIB, PUBLICKEYTOKEN=B77A5C561934E089 is not supported for this application type. Assembly-CSharp-firstpass.dll calls this API.
    API System.Reflection.MemberInfo.get_MemberType in MSCORLIB, PUBLICKEYTOKEN=B77A5C561934E089 is not supported for this application type. Assembly-CSharp-firstpass.dll calls this API.
    API System.IO.File.Exists(System.String) in MSCORLIB, PUBLICKEYTOKEN=B77A5C561934E089 is not supported for this application type. Assembly-CSharp-firstpass.dll calls this API.
    API System.IO.File.Delete(System.String) in MSCORLIB, PUBLICKEYTOKEN=B77A5C561934E089 is not supported for this application type. Assembly-CSharp-firstpass.dll calls this API.
    API System.IO.File.ReadAllBytes(System.String) in MSCORLIB, PUBLICKEYTOKEN=B77A5C561934E089 is not supported for this application type. Assembly-CSharp-firstpass.dll calls this API.
    API System.IO.File.WriteAllBytes(System.String,System.Byte[]) in MSCORLIB, PUBLICKEYTOKEN=B77A5C561934E089 is not supported for this application type. Assembly-CSharp-firstpass.dll calls this API.
    API System.Delegate.CreateDelegate(System.Type,System.Object,System.String) in MSCORLIB, PUBLICKEYTOKEN=B77A5C561934E089 is not supported for this application type. Assembly-CSharp-firstpass.dll calls this API.

    Probably Unity has tried to solve this issues, and because of that in 4.3.4 we've got problems with System.Reflection.MemberTypes.
     
  24. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    Assembly-CSharp-Firstpass.dll is your own C# code, not Unity. Is this targetting Windows Store? If so, go to player settings, and under compilation overrides select "Use .NET Core". That should help you find places where you use invalid APIs (when you build the project).
     
  25. sevensails

    sevensails

    Joined:
    Aug 22, 2013
    Posts:
    483
    Someone could please share the WinRTLegacy.dll from Unity 4.3.2?
     
  26. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    Not sure what the redistribution rules are for the assemblies otherwise I could post it. :/ easiest thing is to just install 4.3.2 in a different folder and copy from there.
     
  27. WalterKognito

    WalterKognito

    Joined:
    Dec 12, 2013
    Posts:
    11
    Error building Player: Exception: Failed to run assembly preprocessor with command line "Temp/StagingArea/Data/Managed\Boo.Lang.dll" -injectCtor -assemblyPath "Temp/StagingArea" -pdb.[Temp/StagingArea/Data/Managed\Boo.Lang.dll]
    No symbols for Temp/StagingArea/Data/Managed\Boo.Lang.dll
    Injecting ctor
    Error while in assembly preprocessor Temp/StagingArea/Data/Managed\Boo.Lang.dll
    Object reference not set to an instance of an object.
    at AssemblyPreprocessor.Utils.<>c__DisplayClass3.<IsInWhitelist>b__0(String namespaze)
    at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
    at AssemblyPreprocessor.Utils.IsInWhitelist(TypeDefinition definition)
    at AssemblyPreprocessor.Utils.IsInWhitelist(TypeDefinition definition)
    at AssemblyPreprocessor.ConstructorInjector.ShouldInject(TypeDefinition typeDefinition)
    at AssemblyPreprocessor.ConstructorInjector.InjectConstructorsForTypesIn(ModuleDefinition moduleDefinition)
    at AssemblyPreprocessor.Program.Main(String[] args)

    I get the same error he did. Should I copy over the whole managed folder?
     
  28. WalterKognito

    WalterKognito

    Joined:
    Dec 12, 2013
    Posts:
    11
    Okay if you copy over Boo.Lang.dll and UnityScript.Lang.dll over it'll work...but now I lost ArrayList support...sigh...this is ridiculous. Can Unity just host the hotfixed .dll's until the next version? I can't downgrade to 4.3.2 and now I essentially can't build to wp8...

    Alternatively if I get the beta and bring over the .dlls from there, will that work and still have ArrayList support?
     
  29. WalterKognito

    WalterKognito

    Joined:
    Dec 12, 2013
    Posts:
    11
    This works (taking the three .dll's from the latest 4.6 beta)! I'm not sure how I feel about using .dll's from a beta though...oh well, will have to do for now.
     
  30. Qbit86

    Qbit86

    Joined:
    Sep 2, 2013
    Posts:
    487
    Could you please provide these three assemblies from 4.6 beta; place it on some file hosting like https://mega.co.nz/ or smth. It will be very much appreciated!

    Boo.Lang.dll
    UnityScript.Lang.dll
    WinRTLegacy.dll

    DLLs from 4.3.2 didn't help, because of mentioned reason — deprecated Hashtable and ArrayList are heavily used by some plugins.

    Sorry for bothering, I'm a little in time pressure of our schedule. Managers say we need to release an update for WP8 edition of our game ASAP because of some marketing reasons. And compilation issues we got after updating to Unity 4.3.4 seem to be showstopper. (We delayed updating from 4.3.2 as long as we could, but newly introduced features of our game for iOS and Android required us to update to 4.3.4. So we could not downgrade back to 4.3.2.)
     
  31. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,919
    Wrote you a PM.
     
  32. imp91

    imp91

    Joined:
    May 14, 2014
    Posts:
    2
    The same situation, can't wait for the new version :(
    Can you please provide the dll's from 4.6 beta?
     
  33. PlayMagicLtd

    PlayMagicLtd

    Joined:
    Aug 23, 2012
    Posts:
    48
    This bug is still present in Unity version 4.6.7p1, we already tried to patch using the dll from 4.6.0p1 but this had not fixed the issue.
    please we are in a hurry to deliver our game, there is any other workaround available?

    Following are the error log and corresponding source code:


    A first chance exception of type 'System.MissingMethodException' occurred in Assembly-CSharp.DLL
    An exception of type 'System.MissingMethodException' occurred in Assembly-CSharp.DLL but was not handled in user code
    Additional information: Method not found: 'System.Reflection.FieldInfo[] System.Type.GetFields(System.Reflection.BindingFlags)'.

    Exception: Method not found: 'System.Reflection.FieldInfo[] System.Type.GetFields(System.Reflection.BindingFlags)'.
    Type: System.MissingMethodException
    Module: Assembly-CSharp
    InnerException: <No Data>
    AdditionalInfo:<No Data>
    at vp_EventHandler.GetFields()
    at vp_EventHandler.StoreHandlerEvents()
    at vp_EventHandler.Awake()
    at vp_StateEventHandler.Awake()
    at vp_PlayerEventHandler.Awake()
    at vp_PlayerEventHandler.$Invoke0(Int64 instance, Int64* args)
    at UnityEngine.Internal.$MethodUtility.InvokeMethod(Int64 instance, Int64* args, IntPtr method)



    public List<FieldInfo> GetFields()
    {
    List<FieldInfo> info = new List<FieldInfo>();
    Type currentType = this.GetType();
    Type nextType = null;
    do
    {
    if (nextType != null)
    currentType = nextType;
    info.AddRange(currentType.GetFields((BindingFlags.Public | BindingFlags.NonPublic
    | BindingFlags.Instance | BindingFlags.DeclaredOnly)));
    if (currentType.BaseType != typeof(vp_StateEventHandler) &&
    currentType.BaseType != typeof(vp_EventHandler))
    nextType = currentType.BaseType;
    }
    while (currentType.BaseType != typeof(vp_StateEventHandler) &&
    currentType.BaseType != typeof(vp_EventHandler) &&
    currentType != null);

    if(info == null || info.Count == 0)
    Debug.LogWarning("Warning: (" + this + ") Found no fields to store as events.");

    return info;
    }
     
  34. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    @Twelve Games:

    which platform are you targeting? It's kinda strange you're running into this issue as I highly doubt it's same bug. If you patched any DLLs, I recommend reinstalling Unity and checking whether it still happens. The workaround I supplied was valid for only Unity 4.3.3 and 4.3.4 and will corrupt your installation when done on any newer Unity version.
     
    Last edited: Jul 28, 2015
  35. PlayMagicLtd

    PlayMagicLtd

    Joined:
    Aug 23, 2012
    Posts:
    48
  36. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    Well, that kinda answers my question why it didn't work - you're not supposed to use this API on Windows Phone 8.1 (you probably get a warning when you build your project, something like
    Code (csharp):
    1. Error: method `System.Reflection.FieldInfo[] System.Type::GetFields(System.Reflection.BindingFlags)` doesn't exist in target framework".
    Use this instead:

    Code (csharp):
    1.  
    2. List<FieldInfo> info = new List<FieldInfo>();
    3.  
    4. Type currentType = GetType();
    5. do
    6. {
    7. #if NETFX_CORE
    8.     foreach (var field in currentType.GetTypeInfo().DeclaredFields)
    9. #else
    10.     foreach (var field in currentType.GetFields((BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly))
    11. #endif
    12.     {
    13.         if (!field.IsStatic)
    14.         info.Add(field);
    15.     }
    16.  
    17. #if NETFX_CORE
    18.     currentType = currentType.GetTypeInfo().BaseType;
    19. #else
    20.     currentTime = currentType.BaseType;
    21. #endif
    22. }
    23. while (currentType != null);
    24.  
    25. return info;
    26.  
    You'll also have to select compilation overrides to .NET Core in player settings.