diff --git a/lib/csharp/Makefile b/lib/csharp/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..5ea79f98c87c04df0e09d6d72fac9822ceeb71de
--- /dev/null
+++ b/lib/csharp/Makefile
@@ -0,0 +1,19 @@
+MODULES=LabCommDispatcher \
+	LabCommDecoderRegistry \
+	LabComm \
+	LabCommSample \
+	LabCommHandler \
+	LabCommEncoderRegistry \
+	LabCommDecoder \
+	LabCommType \
+	LabCommEncoderChannel \
+	LabCommEncoder \
+	LabCommDecoderChannel \
+
+all: labcomm.dll
+
+labcomm.dll: $(MODULES:%=se/lth/control/labcomm/%.cs) Makefile
+	mcs -out:$@ -target:library $(filter %.cs, $^)
+
+clean:
+	rm labcomm.dll
diff --git a/lib/csharp/se/lth/control/labcomm/LabCommDecoder.cs b/lib/csharp/se/lth/control/labcomm/LabCommDecoder.cs
index c01517cabbf65a9b09fce8d26df7d76bf89c8b72..bcb9dea3ba2de20d94ad76b0826048b605156ab4 100644
--- a/lib/csharp/se/lth/control/labcomm/LabCommDecoder.cs
+++ b/lib/csharp/se/lth/control/labcomm/LabCommDecoder.cs
@@ -6,6 +6,7 @@ namespace se.lth.control.labcomm {
 
     void register(LabCommDispatcher dispatcher, 
 		  LabCommHandler handler);
+
     bool decodeBoolean();
     byte decodeByte();
     short decodeShort();
@@ -14,6 +15,7 @@ namespace se.lth.control.labcomm {
     float decodeFloat();
     double decodeDouble();
     String decodeString();
+    int decodePacked32();
 
   }
 
diff --git a/lib/csharp/se/lth/control/labcomm/LabCommDecoderChannel.cs b/lib/csharp/se/lth/control/labcomm/LabCommDecoderChannel.cs
index aec8b0ae50b8a2d161cb9742122f84a76a88f4fe..953c910cff5df008a78a535ff87768d6e07cd4ae 100644
--- a/lib/csharp/se/lth/control/labcomm/LabCommDecoderChannel.cs
+++ b/lib/csharp/se/lth/control/labcomm/LabCommDecoderChannel.cs
@@ -68,7 +68,7 @@ namespace se.lth.control.labcomm {
       } break;
       case LabComm.STRUCT: {
         int fields = decodePacked32();
-        e.encodeInt(fields);
+        e.encodePacked32(fields);
         for (int i = 0 ; i < fields ; i++) {
           e.encodeString(decodeString());
           collectFlatSignature(e);
@@ -108,10 +108,11 @@ namespace se.lth.control.labcomm {
     }
 
     private Int64 ReadInt(int length) {
-      int result = 0;
+      Int64 result = 0;
       ReadBytes(buf, length);
       for (int i = 0 ; i < length ; i++) {
 	result = (result << 8) + buf[i];
+
       }
       return result;
     }
@@ -163,16 +164,13 @@ namespace se.lth.control.labcomm {
     }
 
     public int decodePacked32() {
-      TODO: Correct byteorder
       Int64 res = 0;
-      byte i = 0;
       bool cont = true; 
 
       do {
-        byte c = decodeByte();
-	res |= (uint) ((c & 0x7f) << 7*i);
+        Int64 c = decodeByte();
+	res = (res << 7) | (c & 0x7f);
         cont = (c & 0x80) != 0;
-        i++;
       } while(cont);
 
       return (int) (res & 0xffffffff);
diff --git a/lib/csharp/se/lth/control/labcomm/LabCommEncoder.cs b/lib/csharp/se/lth/control/labcomm/LabCommEncoder.cs
index 1ddadd260ec2abfdf2dd69ae2b14d9376d1ddc79..aadc98ebfc4c2cd00844ade06ae5a1dd13f19043 100644
--- a/lib/csharp/se/lth/control/labcomm/LabCommEncoder.cs
+++ b/lib/csharp/se/lth/control/labcomm/LabCommEncoder.cs
@@ -7,6 +7,7 @@ namespace se.lth.control.labcomm {
     void register(LabCommDispatcher dispatcher);
     void begin(Type c);
     void end(Type c);
+
     void encodeBoolean(bool value);
     void encodeByte(byte value);
     void encodeShort(short value);
diff --git a/lib/csharp/se/lth/control/labcomm/LabCommEncoderChannel.cs b/lib/csharp/se/lth/control/labcomm/LabCommEncoderChannel.cs
index 62d72f001d792d653c9228fcd3e70361663caa97..d13a236ea1cc0d71c206171060ac8b1cdf4fdab2 100644
--- a/lib/csharp/se/lth/control/labcomm/LabCommEncoderChannel.cs
+++ b/lib/csharp/se/lth/control/labcomm/LabCommEncoderChannel.cs
@@ -35,6 +35,7 @@ namespace se.lth.control.labcomm {
     public void end(Type c) {
       bytes.WriteTo(writer);
       bytes.SetLength(0);
+      writer.Flush();
     }
 
     private void WriteInt(Int64 value, int length) {
@@ -46,7 +47,7 @@ namespace se.lth.control.labcomm {
     }
 
     public void encodeBoolean(bool value) {
-      WriteInt(value ? 0 : 1, 1);
+      WriteInt(value ? 1 : 0, 1);
     }
 
     public void encodeByte(byte value) {
@@ -89,13 +90,16 @@ namespace se.lth.control.labcomm {
     }
 
     public void encodePacked32(Int64 value) {
-      Int64 tmp = value;
-      TODO: Correct byteorder
-      while(tmp >= 0x80) {
-        encodeByte( (byte) ((tmp & 0x7f) | 0x80 ) );
-        tmp >>= 7;           
+      byte[] tmp = new byte[5];
+      Int64 v = value & 0xffffffff;
+      int i;
+  
+      for (i = 0 ; i == 0 || v != 0 ; i++, v = (v >> 7)) {
+        tmp[i] = (byte)(v & 0x7f);
+      }
+      for (i = i - 1 ; i >= 0 ; i--) {
+        encodeByte((byte)(tmp[i] | (i!=0?0x80:0x00)));
       }
-      encodeByte( (byte) (tmp & 0x7f) );
     }
   }
 }