public unsafe void DateTimeLimits() { byte[] data; using (MemoryStream ms = new MemoryStream()) { using (BinaryWriter writer = new BinaryWriter(ms)) writer.Write(DateTime.UtcNow.Ticks); data = ms.ToArray(); } fixed(byte *pData = data) { BinaryMemoryReader reader = new BinaryMemoryReader(pData, data.Length - 1); try { reader.ReadDateTime(); Assert.Fail("Should have thrown an OutOfMemoryException."); } catch (OutOfMemoryException) { } catch (Exception) { Assert.Fail("Should have thrown an OutOfMemoryException."); } BinaryMemoryWriter writer = new BinaryMemoryWriter(pData, data.Length - 1); try { writer.Write(DateTime.UtcNow); Assert.Fail("Should have thrown an OutOfMemoryException."); } catch (OutOfMemoryException) { } catch (Exception) { Assert.Fail("Should have thrown an OutOfMemoryException."); } } }