BizTalk SpreadsheetDocument.Open 流:索引超出数组范围

BizTalk SpreadsheetDocument.Open Stream: Index was outside the bounds of the array

我正在尝试构建一个能够读取 Excel 文件的自定义管道。 当我 运行 此代码在 Windows 7 上时 - 它工作正常。 当我 运行 Win 2k8 上的代码时 - 我收到错误消息:"Index was outside the bounds of the array."(尝试打开流时失败)。

如果我在两个盒子上测试组件(加载文件并处理它)- 它工作正常。 只有当它通过文件适配器直接来自 BizTalk 时才会发生错误。

如果我更改代码以加载文件(无论管道中有什么)- 它工作正常!

有什么想法吗?

public Microsoft.BizTalk.Message.Interop.IBaseMessage Execute(Microsoft.BizTalk.Component.Interop.IPipelineContext pc, Microsoft.BizTalk.Message.Interop.IBaseMessage inmsg)
    {            

    var excelAsStream = inmsg.BodyPart.GetOriginalDataStream();

    try
    {

        //excelAsStream.Position = 0;
        using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Open(excelAsStream, false))  // Here I get the Error
        {

到目前为止,为了解决这个问题,我做了以下工作:

  1. 读取 excel 文件作为流
  2. 以“.tmp”扩展名在本地保存
  3. 读取 tmp 文件并转换为 xml
  4. 删除 tmp 文件
  5. 将消息传递给 MessageBox

代码:

var fullFileName = string.Empty; // tmp file name to be loaded via spreadsheet
IBaseMessageContext context = inmsg.Context;

try

{
if (inmsg.BodyPart == null)
    throw new ArgumentNullException("inmsg.BodyPart","Incoming Message is not Valid stream");


var srcFileName = context.Read("ReceivedFileName", "http://schemas.microsoft.com/BizTalk/2003/file-properties").ToString();
// write file to local folder as tmp
var fileTmp = Path.GetFileNameWithoutExtension(srcFileName);
var pathTmp = Path.GetDirectoryName(srcFileName) ?? string.Empty;
fullFileName = Path.Combine(pathTmp, fileTmp + ".tmp");

var excelAsStream = inmsg.BodyPart.GetOriginalDataStream(); // get the msg as Stream
using (var fileStream = File.Create(fullFileName))
{
    excelAsStream.Seek(0, SeekOrigin.Begin);
    excelAsStream.CopyTo(fileStream);
}


using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Open(fullFileName, false))
{   
    // Do code here
}

} // end try