c # xml.Load () bloqueando o arquivo no disco causando erros
Eu tenho uma classe simples XmlFileHelper da seguinte maneira:
public class XmlFileHelper
{
#region Private Members
private XmlDocument xmlDoc = new XmlDocument();
private string xmlFilePath;
#endregion
#region Constructor
public XmlFileHelper(string xmlFilePath)
{
this.xmlFilePath = xmlFilePath;
xmlDoc.Load(xmlFilePath);
}
#endregion
#region Public Methods
public XmlNode SelectSingleNode(string xPathQuery)
{
return xmlDoc.SelectSingleNode(xPathQuery);
}
public string GetAttributeValueByName(XmlNode node, string attributeName)
{
return node.Attributes.GetNamedItem(attributeName).Value;
}
#endregion
#region Public Properties
public string XmlFilePath
{
get
{
return xmlFilePath;
}
}
#endregion
}
O problema é que estou recebendo o seguinte erro no Load:
System.IO.IOException: The process cannot access the file ''C:\CvarUAT\ReportWriterSettings.xml'' **because it is being used by another process**
isso ocorre quando essa classe é usada por duas instâncias em execução de um componente em execução em paralelo, ambas tentando carregar o arquivo xml acima, isso é um comportamento legítimo e requerido pelo aplicativo.
Eu só quero ler no xml off disk uma vez e liberar qualquer referência ao arquivo no disco e usar uma representação na memória desse ponto em diante.
Eu teria assumido que o Load funciona de maneira não convencional e não teria necessidade de bloquear o arquivo. Qual é a melhor maneira de obter o resultado desejado e contornar esse problema?
obrigado