AspNetIdentity
AspNetIdentity copied to clipboard
Using MemoryStream in Using block or not...
I just wonder, is there a special reason why you don't use MemoryStream in using blocks?
https://github.com/aspnet/AspNetIdentity/blob/9c48993a446288032f9824633e6dae81257da06e/src/Microsoft.AspNet.Identity.Owin/DataProtectorTokenProvider.cs#L71
On the other hand, it's used in a using block in this code: https://github.com/aspnet/Mvc/blob/00c6b53b062e7996c85873754c3b79f50db67ee1/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/TempDataSerializer.cs#L50
I'm also confused.
You wouldn't need to pack MemoryStream
into a using
, cause the BinaryReader
and BinaryWriter
closes the underlying stream on Dispose
.
But both of them are instantiated with the parameter leaveOpen
set to true
.
https://github.com/aspnet/AspNetIdentity/blob/9c48993a446288032f9824633e6dae81257da06e/src/Microsoft.AspNet.Identity.Owin/DataProtectorTokenProvider.cs#L174
https://github.com/aspnet/AspNetIdentity/blob/9c48993a446288032f9824633e6dae81257da06e/src/Microsoft.AspNet.Identity.Owin/DataProtectorTokenProvider.cs#L179
So it won't be closed anymore.