BizTalk SpreadsheetDocument.Open Stream:索引超出了数组的边界

BizTalk SpreadsheetDocument.Open Stream:索引超出了数组的边界,biztalk,pipeline,import-from-excel,Biztalk,Pipeline,Import From Excel,我试图建立一个自定义管道,将能够读取Excel文件。 当我在Windows7上运行此代码时,它工作正常。 当我在Win 2k8上运行代码时,我得到一个错误:“索引超出了数组的边界。”(尝试打开流时失败) 如果我在两个框上测试组件(加载一个文件并对其进行处理),它可以正常工作。 该错误仅在通过文件适配器直接来自BizTalk时发生 如果我更改代码以加载一个文件(不管从管道中得到什么),它工作得很好 有什么想法吗 public Microsoft.BizTalk.Message.Interop.IB

我试图建立一个自定义管道,将能够读取Excel文件。 当我在Windows7上运行此代码时,它工作正常。 当我在Win 2k8上运行代码时,我得到一个错误:“索引超出了数组的边界。”(尝试打开流时失败)

如果我在两个框上测试组件(加载一个文件并对其进行处理),它可以正常工作。 该错误仅在通过文件适配器直接来自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
        {

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

  • 将excel文件作为流读取
  • 使用“.tmp”扩展名在本地保存它
  • 读取tmp文件并转换为xml
  • 删除tmp文件
  • 将消息传递给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