有一个错误反映了类型'MAH.Tools.LicenseModel.CustomerLicense'

时间:2017-03-21 14:31:38

标签: c# xml xmlserializer

我在我的许可证类中有这些方法,如下所示。

    public void CreateTestLincense(LicenseModel.CustomerLicense objData)
    {
        string data = CreateXML(objData);
        File.WriteAllText(licensePath, data);
    }
    private string CreateXML(Object YourClassObject)
    {
        XmlDocument xmlDoc = new XmlDocument();
        XmlSerializer xmlSerializer = new XmlSerializer(YourClassObject.GetType());
        using (MemoryStream xmlStream = new MemoryStream())
        {
            xmlSerializer.Serialize(xmlStream, YourClassObject);
            xmlStream.Position = 0;

            xmlDoc.Load(xmlStream);

            return xmlDoc.InnerXml;
        }
    }

但是我试图在传递其属性后保存xml。

CustomerLicense custLic = new CustomerLicense();
custLic.CustomerId = 1;
custLic.Names = "David Okwudili";
custLic.Email = "michealdavid910@yahoo.com";
custLic.Phone = "09089786756";
custLic.ExpiringDate = DateTime.Now;
custLic.Serial = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
//Create XML Documant
MAH.Tools.Licensing.License lic = new MAH.Tools.Licensing.License(true);
lic.CreateTestLincense(custLic);

但它已经从XmlSerializer xmlSerializer = new XmlSerializer(YourClassObject.GetType());抛出异常'反映类型的错误'。 我需要帮助,谢谢。

0 个答案:

没有答案