Biztalk 自定义管道组件中出现错误

Biztalk 自定义管道组件中出现错误,biztalk,biztalk-2010,custom-pipeline-component,Biztalk,Biztalk 2010,Custom Pipeline Component,一个.txt文件,其格式如下所示 111515161515950000055 00012913702613000000000003000 139C000007000000 12151516151215100054 000229138036030000000000009000 000279A000009000 1315115950000065516515 00032813104643000000000007000399B000003000 12151511600032900032900000000

一个.txt文件,其格式如下所示

111515161515950000055 00012913702613000000000003000 139C000007000000 12151516151215100054 000229138036030000000000009000 000279A000009000 1315115950000065516515 00032813104643000000000007000399B000003000 121515116000329000329000000000003000

前3行是主体元素,但主体部分中的行数未知,可能从1到无界。主体部分中没有标记标识符。文件中的最后一行始终是尾部。在解析之前,将删除文件中的尾部,以便只需要解析记录。创建了自定义管道组件以向主体部分添加标记。 但当我将工具箱中的组件添加到IPersistPropertyBag实现上的接收Piepline管道组件加载失败时显示错误

管道组件的代码为

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.IO;
using Microsoft.BizTalk.Message.Interop;
using Microsoft.BizTalk.Component.Interop;
namespace PipelinezTrailerPrj
{
    [ComponentCategory(CategoryTypes.CATID_PipelineComponent)]

    [ComponentCategory(CategoryTypes.CATID_DisassemblingParser)]

    [System.Runtime.InteropServices.Guid("6118B8F0-8684-4ba2-87B4-8336D70BD4F7")]
    public class CRemoveTrailer : IBaseComponent, IComponentUI, IComponent, IPersistPropertyBag
    {
        #region IBaseComponent
        public string Description
        {
            get
            {
                return "Pipeline component used to delete the Trailer in The Incoming messages";
            }
        }
        public string Name
        {
            get
            {
                return "CRemoveTrailer";
            }
        }
        public string Version
        {
            get
            {
                return "1.0.0.0";
            }
        }
        #endregion

        #region IComponentUI
        public IntPtr Icon
        {
            get
            {
                return new System.IntPtr();
            }
        }

        public System.Collections.IEnumerator Validate(object projectSystem)
        {
            return null;
        }
        #endregion

        #region IPersistPropertyBag
        private string _NewNameSpace;
        public string NewNameSpace
        {
            get { return _NewNameSpace; }
            set { _NewNameSpace = value; }
        }

        public void GetClassID(out Guid classID)
        {
            classID = new Guid("ACC3F15A-C389-4a5d-8F8E-2A951CDC4C19");
        }

        public void InitNew()
        {

        }

        public void Load(IPropertyBag propertyBag, int errorLog)
        {
            object val = null;
            try
            {
                propertyBag.Read("PipelinezTrailerPrj", out val, 0);
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Error reading propertybag: " + ex.Message);
            }
            if (val != null)
                _NewNameSpace = (string)val;
            else
                _NewNameSpace = "http://PipelinezTrailerPrj";
        }

        public void Save(IPropertyBag propertyBag, bool clearDirty, bool saveAllProperties)
        {
            object val = (object)_NewNameSpace;
            propertyBag.Write("PipelinezTrailerPrj", ref val);
        }
        #endregion
        #region IComponent
        public IBaseMessage Execute(IPipelineContext pContext, IBaseMessage pInMsg)
        {
            if (pContext == null) throw new ArgumentNullException("pContext");

            if (pInMsg == null) throw new ArgumentNullException("pInMsg");

            IPipelineContext pipelineContext = pContext;
            IBaseMessage baseMessage = pInMsg;
            //Validate parameters

            string partName;

            for (int i = 0; i < baseMessage.PartCount; i++)

            {
                MemoryStream outStream = new MemoryStream();

                partName = null;

                IBaseMessagePart part = baseMessage.GetPartByIndex(i, out partName);

                StreamReader reader = new StreamReader(part.GetOriginalDataStream());

                string partBody = reader.ReadToEnd();

                StreamWriter writer = new StreamWriter(outStream, new UTF8Encoding());               


                string[] separator = new string[] {"\r\n"};

                string[] strArray = partBody.Split(separator, StringSplitOptions.None);



                for (int n = 0; n < strArray.Length; n++)

                {

                    //There will be a blank string in the last line of the array. So we don't need to add tag to the last 2 lines.

                    if (n < (strArray.Length - 2))     

                    {

                        strArray[n] = "BODY" + strArray[n];

                    }


                    //Add the line break back.

                    writer.Write(strArray[n] + "\r\n");

                }                             

                writer.Flush();

                outStream.Seek(0, SeekOrigin.Begin);

                part.Data = outStream;

            }

            return baseMessage;

        }

        #endregion

}

}

查看propertyBag.Read引发异常,然后捕获它并引发applicationException

请参阅,与您的问题相同。建议的方法是

 propertyBag.Read("System", strValue, errorLog)

您使用管道组件向导了吗?没有,我没有向导为什么您要创建自定义管道组件而不是使用标准平面文件管道组件?如果你回答了另一个问题中的问题,那么这将是一个更简单、更干净的方法。