Author Topic: Type.GetMethod, MissingMethodException on Windows Phone 8 and OnClick on UIButto  (Read 4298 times)

DevLabTech

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Hi guys,

I'm a new customer and I added a UIButton with a Notify that call my MainCamera public void onclick(void) Script Method.

If I play my game on wp8, when I tap my button, my application throw a MissingMethodException on Type.GetMethod().
This exception is thrown on NGUI/Scripts/Internal/EventDelegate.cs, when the execution reach

mMethod = mTarget.GetType().GetMethod(mMethodName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

inside the Cache() private method.

I have read that Type.GetMethod() is replaced by Type.GetTypeInfo().GetMethod(), but this work only on .NET 4.5.
Unity3D is using Mono/.NET 3.5 (but inside my WP8 Build Setting, there is only .NET 2.0 or .NET 2.0 Subset (.NET 2.0 Subset is currently selected)).

How can I fix this error?

Thanks!

Dario @DevLabTechnologies

PS: Sorry for my bad english

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
This code shouldn't even be compiling on WP8 due to the NETFX_CORE #ifdef at the top of the file. You can try replacing that line with:
  1. #if NETFX_CORE
  2.                                 mMethod = mTarget.GetTypeInfo().GetMethod(mMethodName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
  3. #else
  4.                                 mMethod = mTarget.GetType().GetMethod(mMethodName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
  5. #endif

DevLabTech

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Hi ArenMook,
with your code, that I have added on my Assets/NGUI/Scripts/Internal/EventDelegate.cs script, when I run my WP8 solution throw the MissingMethodException.

This code is compiled by Unity inside the Assembly-CSharp.dll.
When I choose Windows Phone 8 Platform inside Build Settings options, and I click on Build... button, Unity compile Assembly-CSharp.dll (it compile also NGUI source) and create a Visual Studio Windows Phone 8 Solution.

When I run on Emulator or Device (it's the same), and press my button created by UIButton NGUI Script, with a Notify, it crash.

It is like Unity (4.3.4f1), when compile for WP8 Platform, build as the define symbols REFLECTION_SUPPORT is defined.

I'm using NGUI 3.6.5 with Unity 4.3.4f1 on Windows 8.1 Pro.

DevLabTech

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Hi,
to fix this problem I have commented the #define REFLECTION_SUPPORT

  1. #if UNITY_EDITOR || !UNITY_FLASH && !NETFX_CORE
  2. //#define REFLECTION_SUPPORT
  3. #endif
  4.  

inside EventDelegate.cs file.
It need to fix the compile errors by adding "#if REFLECTION_SUPPORT" when it need.

So now it work properly.

But in your code there are some inconsistence issue, because if REFLECTION_SUPPORT is not defined, the "using System.Reflection" directive is not compiled and yo cannot refer to MethodInfo as the using is present.

I don't know if that problem is caused by unity or not, but with this workaround, now is ok.

Thanks!
Dario
« Last Edit: April 08, 2014, 08:01:36 AM by DevLabTech »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Yup, I fixed the inconsistencies in the Pro version. Sounds like that statement should be:
  1. #if UNITY_EDITOR || (!UNITY_FLASH && !NETFX_CORE && !UNITY_WP8)
  2. #define REFLECTION_SUPPORT
  3. #endif

DevLabTech

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Yes!
But if you don't define REFLECTION_SUPPORT, you need to fix the compile errors that occurs because Unity don't compile the "using System.Reflection;" statement ;).

There is a plan for a minor release in the Standard Licence (I bought NGUI on Asset Store for 90$).

Thanks
Dario

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
I've already fixed them on Pro a few days ago. I'll find it all working in the next update which will be on the Asset Store this week.

DevLabTech

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Great!

Thanks ;)!

Dario