Tuesday, February 1, 2011

Multi-Platform development and preprocessing.

Yesterday, while working for our school's third year project, I came across a problem, the code we were going to use and compile for 2 C# platforms (Asp.net 3.5 compact and Asp.net 4.0 normal) wasn't compatible for both platform. It took a hard time to realize since our compilator was giving an error like:
"I was waiting for an argument of type System.Net.IPAdress[], but received an argument of type System.Net.IPAdress[C:\System32]"

It took a while to actually figure out what was the problem. As it turns out, it was because i was trying to include files compiled for a not-compact version of Asp.net. The fix?(thanks to Julien Gascon-Samson on this one) incorporate the source files in a new project that would compile for a compact .net version. Once we did that, we tried recompiling and realized, there is a lot of different stuff on the compact framework, and that's where the pre-processing directives came into play.

We added every part of code that caused problem in a different "Utilities" static class which would help us code different behaviors on different platforms. The part to do that was quite simple:

[code lang="csharp"]

#if !PocketPC
return (int)e.SocketErrorCode;
#else
return e.ErrorCode;
#endif
[/code]
After i found out about this, everything became much easier, i was able to continue on implementing the lightweight client. What is the lightweight client is the title for another post..maybe!

No comments:

Post a Comment