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.

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.

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.