Search Unity

How do you debug a System.IO exception Unity won't load?

Discussion in 'Web' started by FortisVenaliter, Jun 12, 2015.

  1. FortisVenaliter

    FortisVenaliter

    Joined:
    Mar 23, 2013
    Posts:
    48
    I'm working on a Web Player application with socket networking. Apparently Unity won't load most of System.IO on Web Player, which makes socket IO much harder.

    My networking code is in a C# Managed DLL compiled against .NET 3.5 client profile.

    The problem I'm running into now is that after connecting to the server and sending it a message, my program won't receive a message back. Looking at the logs, I see the following repeatedly:

    Could not load type 'System.IO.InvalidDataException' from assembly 'MyAssembly'.​

    But, it won't give me a stack trace. And since it won't load the exception, I have no idea what the problem actually is.

    The worst part, though, is that this code works perfectly every time in the editor, but fails with that unloadable exception every time in any browser. Also, this same netcode has been used in a .NET WinForms application for over two years now with the same server, so it's well tested outside of Unity, but it's also very complex, so I can't just guess and check or I'll be at it for a month.

    I've also tried adding extra try/catch blocks, but since it won't load the exception, it can't catch it.

    So, my question is, how can I debug this? I'm hoping someone has an outside-of-the-box idea, because I've exhausted my store...
     
  2. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    WinForms and Unity in the WebPlayer probably have different .NET APIs available to them.

    Not sure it would help, but you could try to hook into the AppDomain UnhandledException event and print the error, possibly with its full stack trace:
    Code (CSharp):
    1. AppDomain currentDomain = AppDomain.CurrentDomain;
    2. currentDomain.UnhandledException += MyHandler;
    3.  
    4.  
    5. private static void MyHandler(object sender, UnhandledExceptionEventArgs args)
    6. {
    7.    Exception e = (Exception) args.ExceptionObject;
    8.    Debug.Log("MyHandler caught : " + e.ToString());
    9. }
    Not sure it would work though.
     
  3. FortisVenaliter

    FortisVenaliter

    Joined:
    Mar 23, 2013
    Posts:
    48
    Yeah, good idea. I did try it though... Since Unity refuses to load the exception (but is somehow fine with compiling code that will throw it... wtf), it still gives the same crash with no additional details.

    Thanks for your reply though.
     
  4. FortisVenaliter

    FortisVenaliter

    Joined:
    Mar 23, 2013
    Posts:
    48
    Been trying to test some other platforms while I work on this and, sure enough, works just fine on Android. This is driving me nuts... ><