- Home /
How do you debug a System.IO exception Unity won't load in WebPlayer?
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.
Okay, a few updates from my testing frustration:
One, it was suggested here to try a global exception handler, but since it won't load the exception, that's not helping...
Two, this works perfectly in PC standalone (in-editor and built), Web Player (in-editor only), and on Android (in-editor and built).
Three, what's really driving me nuts is that Unity allows me to build and run the code, but it won't load the exception. So, why the hell is it successfully compiling code that can throw the exception it can't load in the first place?
Answer by Dave-Carlile · Jun 12, 2015 at 09:22 PM
There's not stack trace because there's no stack to trace. Unity is unable to load your assembly because it is unable to load the assembly containing System.IO.InvalidDataException
that your assembly is referencing.
I would guess that the web player allows a subset of the System.IO
namespace, and that particular exception class isn't part of that subset.
Another guess is that you're referencing something that isn't part of the .NET 2.0 framework, but then it wouldn't run standalone either.
As far as Unity allowing you to compile... I assume your dll is compiled outside of Unity right? At compile time the referenced System.IO assembly has the proper pieces so it compiles okay (again, outside of Unity). But only when it actually runs under the context of the webplayer is it able to find out that the referenced type isn't available, so you get the runtime error.
Hmmm.... okay that makes sense. So, it only happens if done in an external DLL. Still doesn't explain why it runs okay in the editor, though. I'm surprised Unity wouldn't just reject DLLs that make calls into functions it can't link.
But, the bottom line, and what will get you marked as the correct answer is... how do I debug it? The code base is too big to just bring the full source into the Unity editor. If the editor won't catch it at compile or runtime, and it only occurs in the wild with no stack trace, how do I even isolate the source?
There's nothing really to debug in the code - you're referencing an assembly that Unity can't use in the web player. You said yourself, Unity won't load most of System.IO in the web player.
Okay, so start from scratch, or abandon Unity as a platform for this project. Damn, I was hoping for something better than that. Thanks for your help though.
What is it you're trying to do that requires System.IO?
Just basic socket IO. Binaryreaders, $$anonymous$$emoryStreams, some compression, etc. No file-system accessing at all. If I can't do that, then my project is simply not viable with Unity, which is a damn shame.
Answer by Jwizard93 · Dec 10, 2018 at 11:33 PM
If anyone still sees errors like this I saw one today when building to standalone. The solution was Edit->ProjectSettings-> Player. And then in the inspector there was API Compability = ".NET 2.0 Subset." I changed it to ".NET 2.0" and rebuilt.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
TCPClient and SslStreams in WebPlayer (C#) 0 Answers
Problem parsing a file by group of lines 0 Answers