facebookarchive / RakNet

RakNet is a cross platform, open source, C++ networking engine for game programmers.
Other
3.3k stars 1.02k forks source link

[C#] System.TypeInitializationException whenever creating BitStream #59

Open alejzeis opened 9 years ago

alejzeis commented 9 years ago

Hey guys,

I am mostly a Java guy doing a lot of Minecraft: Pocket Edition Server development. MCPE uses RakNet as it's networking library, so with the Oculus purchase I thought that maybe I could use RakNet with C# as C# is similar to Java. I had some trouble compiling, but I finally got the C# code generated somehow, and I used VS2013 Community to compile it into a DLL. I added it into my project, and once I start receiving packets, the program crashes as I try to create a BitStream for each packet. A System.TypeInitalizationException is thrown. I have searched google for this, and turned up with nothing.

private void handlePacket(byte[] buffer)
        {
            BitStream bs = new BitStream(buffer, (uint)buffer.Length, false);

            byte packetID;
            bs.Read(out packetID);
            switch (packetID)
            {
                default:
                    logger.Info("Got a packet: " + packetID);
                    break;
            }
        }