我们将代码从.Net Framework 2.0迁移到.Net Framework 4.0,但是当我们测试它时,我们遇到了一个错误,即“对象引用未设置为实例对象”。
我们试图为此寻找可能的解决方案,并看到了有关.Net Framework 4.0 https://msdn.microsoft.com/en-us/library/ee471421(v=vs.100).aspx的过时类型和成员的文章。列在那里的成员之一正在我们的一个类中使用,即“System.Xml.Serialization.XmlSerializer”,但即使我们继续构建我们的解决方案,也没有发现错误。这真的是一个过时的成员/类型的行为?或者您认为“对象引用未设置为实例对象”的错误与这些过时的成员/类型有关吗?
#region Variables Setup
//Declare Variables
string orderUID = string.Empty;
string input = string.Empty;
APSArchitecture.Tools.APSLogData logData = null;
XmlDocument bodyDoc = null;
IBaseMessagePart bodyPart = null;
const string APSHEADER_PARTNAME = "APSHeader";
APSArchitecture.Tools.Serialization.APSHeader apsHeader = null;
APSArchitecture.Pipelines.NonSeekMemoryStream APSHdrStream = null;
APSArchitecture.Pipelines.NonSeekMemoryStream copyOfBodyStream = null;
**XmlSerializer serializer** = null;
Microsoft.BizTalk.Message.Interop.IBaseMessagePart part = null;
string partname = string.Empty;
XmlNamespaceManager nsmgr = null;
Stream originalBodyStream = null;
#endregion
#region Init Variables
//Initial Variables
try
{
logData = new APSArchitecture.Tools.APSLogData();
logData.SrcSystem = "AssignOrderUID.Execute";
bodyDoc = new XmlDocument();
bodyPart = pInMsg.BodyPart;
originalBodyStream = bodyPart.Data;
copyOfBodyStream = new NonSeekMemoryStream();
//
// Copy the original message to the copy stream for reading of the xml.
//
const int ONE_K = 1024;
byte[] buffer = new byte[ONE_K];
int readSize = 0;
while((readSize = originalBodyStream.Read(buffer,0,ONE_K)) != 0)
{
copyOfBodyStream.Write(buffer,0,readSize);
}
copyOfBodyStream.Seek(0,SeekOrigin.Begin);
}
catch(System.Exception ex)
{
string error = ex.Message;
if(ex.InnerException != null)
error = error + " Inner Exception Details: " + ex.InnerException.Message;
throw new ApplicationException("Error initilalizing AssignOrderUID Execute method. Exception Details: " + error, ex);
}