1
Good morning, usually I avoid to the maximum to ask questions here in the forum because I always find many answers that supply my situation.
I am doing an integration with Sefaz, using Ws Nfe 4.00 Authorization, but when I will do the validation of my XML is returned the error:
Type 'http://www.portalfiscal.inf.br/nfe:TNFe' is not declared
I created my project in Asp.Net Core (Web Api) and this is the code I use to validate:
XmlReaderSettings xmlReaderSettings = new XmlReaderSettings();
xmlReaderSettings.ValidationType = ValidationType.Schema;
xmlReaderSettings.Schemas = new XmlSchemaSet();
xmlReaderSettings.XmlResolver = new XmlUrlResolver() { Credentials = CredentialCache.DefaultCredentials };
xmlReaderSettings.Schemas.Add(null, localSchema);
xmlReaderSettings.ValidationEventHandler += new ValidationEventHandler(delegate (object sender, ValidationEventArgs e)
{
var ex = new Exception(string.Format("Falha ao validar Xml! Linha: {0}, Coluna: {1}, Mensagem: {2}",
e.Exception.LineNumber, e.Exception.LinePosition, e.Exception.Message));
ex.Data.Add("statusCode", HttpStatusCode.BadRequest);
throw ex;
});
using (var stringReader = new StringReader(xml.InnerXml))
{
var xmlReader = XmlReader.Create(stringReader, xmlReaderSettings);
while (xmlReader.Read()) { }
xmlReader.Close();
Remembering that:
- Same code works on different Core projects;
- The error happens in the following line "var xmlReader = Xmlreader.Create(stringReader, xmlReaderSettings);"
- All Nfe 4.00 schemas are up to date;
- I know the error is not in XML because it works smoothly in a version of an old project;
- I’ve tried some tips from others who asked and it didn’t work;
- The schemas I use, can be downloaded in the following link: "http://www.nfe.fazenda.gov.br/PORTAL/exibirArquivo.aspx?conteudo=CoNA9VIgZ3E="
Thanks in advance for the help.
Hello Leonardo, in which line occurs the exception?
– Bruno Soares