ProjectRootElement.Open always uses cache
- Dominant language
- C#
- Stars
- 5.5k
- Forks
- 1.5k
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 133
Description
If I create 2 objects of `Microsoft.Build.Construction.ProjectRootElement` using `Open(string path)` method, where the file path is same but the content is altered in between the calls, the 2nd `Open` call returns content from in memory cache and not file.
```c#
var filePath = @"C:\temp\AProject.csproj";
var projectRootElement1 = Microsoft.Build.Construction.ProjectRootElement.Open(filePath)
// pause the debugger
// alter the file content slightly on disk
// resume debugger
var projectRootElement2 = Microsoft.Build.Construction.ProjectRootElement.Open(filePath)
```
**Result**: The value of `projectRootElement1.OuterElement` is same as `projectRootElement2.OuterElement`, which should not be.
___Reasoning:___
Cache is good for performance, but there should be a flag available in Open method which forces the algorithm to read from disk and not from cache.
___Workaround:___
This problem has been worked around by using `XmlReader`, which is in our control and not cache.
```c#
using (XmlReader reader = XmlReader.Create(filePath))
{
projectRootElement1 = Microsoft.Build.Construction.ProjectRootElement.Create(reader);
}
// pause the debugger
// alter the file content slightly on disk
// resume debugger
using (XmlReader reader = XmlReader.Create(filePath))
{
projectRootElement2 = ProjectRootElement.Create(reader);
}
```
**Result**: The value of `projectRootElement1.OuterElement` is **not** same as `projectRootElement2.OuterElement`, as expected.
___Tested on___:
OS: Windows
.NET Version: .NET 4.7.2 Framework
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.