private Task<bool> ProcessFile(FileInfo fileInfo)
{
// Usare il factory method CreateInstance() per ottenere una istanza di Fattura.
var fattura = Fattura.CreateInstance(Instance.PubblicaAmministrazione);
// Lettura da file XML
using (var r = XmlReader.Create(fileInfo.FullName, new XmlReaderSettings { IgnoreWhitespace = true, IgnoreComments = true }))
{
fattura.ReadXml(r);
}
// Ogni file di fattura contiene un array di elementi FatturaElettronicaBody.
_logger.LogInformation($"Numero di documenti: {fattura.Body.Count}.");
_logger.LogInformation("Documenti inclusi nel file FatturaPA:");
foreach (var doc in fattura.Body)
{
_logger.LogInformation($"Numero: {doc.DatiGenerali.DatiGeneraliDocumento.Numero}");
_logger.LogInformation($"Data: {doc.DatiGenerali.DatiGeneraliDocumento.Data.ToShortDateString()}");
_logger.LogInformation($"Totale documento: {doc.DatiGenerali.DatiGeneraliDocumento.ImportoTotaleDocumento}");
_logger.LogInformation("");
}
// Convalida del documento.
var validator = new FatturaValidator();
var result = validator.Validate(fattura);
_logger.LogInformation(result.IsValid ? "Validated!" : "Xml is not valid");
// Introspezione errori di convalida.
foreach (var error in result.Errors)
{
_logger.LogError(error.PropertyName);
_logger.LogError(error.ErrorMessage);
// Nei casi di errore 2xx e 4xx ErrorCode conterrà il codice errore (es: "00423").
_logger.LogError(error.ErrorCode);
}
if (!result.IsValid)
return Task.FromResult(false);
return Task.FromResult(true);
}
System.Xml.XmlException: Content cannot be converted to the type System.DateTime. Line 131, position 44. ---> System.FormatException: The string '2017-02-30' is not a valid AllXsd value.
at System.Xml.Schema.XsdDateTime..ctor(String text, XsdDateTimeFlags kinds)
at System.Xml.Schema.XmlUntypedStringConverter.FromString(String value, Type destinationType, IXmlNamespaceResolver nsResolver)
at System.Xml.XmlReader.ReadContentAs(Type returnType, IXmlNamespaceResolver namespaceResolver)
--- End of inner exception stack trace ---
at System.Xml.XmlReader.ReadContentAs(Type returnType, IXmlNamespaceResolver namespaceResolver)
at System.Xml.XmlReader.ReadElementContentAs(Type returnType, IXmlNamespaceResolver namespaceResolver)
at FatturaElettronica.Common.BaseClassSerializable.ReadXml(XmlReader r)
at FatturaElettronica.Common.BaseClassSerializable.ReadXmlList(Object propertyValue, Type propertyType, String elementName, XmlReader r)
at FatturaElettronica.Common.BaseClassSerializable.ReadXml(XmlReader r)
at FatturaElettronica.Common.BaseClassSerializable.ReadXmlList(Object propertyValue, Type propertyType, String elementName, XmlReader r)
at FatturaElettronica.Common.BaseClassSerializable.ReadXml(XmlReader r)
at FatturaElettronica.Common.BaseClassSerializable.ReadXmlList(Object propertyValue, Type propertyType, String elementName, XmlReader r)
at FatturaElettronica.Common.BaseClassSerializable.ReadXml(XmlReader r)
at FatturaElettronica.Fattura.ReadXml(XmlReader r)
at ProcessFile(FileInfo fileInfo) in ...
The user profile is configured with en-us settings. My guess is that the FatturaElettronica.Core assumes the localization happens with it-it settings (which rarely happens in case of server deploy such as Windows Service or Linux container).
Please consider using the Linq to Xml (XElement / XDocument) classes instead of System.Xml set of classes.