无法将 System.IO.Stream 隐式转换为 System.IO.MemoryStream。 C#

Cannot implicitly convert System.IO.Stream to System.IO.MemoryStream. c#

此代码用于在 VB 中工作,无法确定我在这里缺少的内容。

System.IO.MemoryStream oStream = new System.IO.MemoryStream();

if (rptName == "rpt_BankFormatExCopy.rpt" | rptName == "GIS_reportExFormat.rpt" | rptName == "GPFDeductionRepExFormat.rpt")
    oStream = rptObject.ExportToStream(CrystalDecisions.Shared.ExportFormatType.ExcelRecord);
else
    oStream = rptObject.ExportToStream(CrystalDecisions.Shared.ExportFormatType.Excel);

看起来 rptObjectStream

在那种情况下你可以只使用 CopyTo

var oStream = new MemoryStream();
Stream stream = null;

if (rptName == "rpt_BankFormatExCopy.rpt" | rptName == "GIS_reportExFormat.rpt" | rptName == "GPFDeductionRepExFormat.rpt")
    stream = rptObject.ExportToStream(CrystalDecisions.Shared.ExportFormatType.ExcelRecord);
else
    stream = rptObject.ExportToStream(CrystalDecisions.Shared.ExportFormatType.Excel);

stream.CopyTo(oStream);