Files
Marc Schier a9a3e021ee Fix VirtualFileSystem compiler crashes under memory pressure (#4246)
# Description

Replace `VirtualFileSystem`'s per-file delayed-commit memory mapping
with a
growable managed buffer made of 64 KB chunks. The mapping was private
and
non-shared, but reserved 64 MB on 32-bit processes or 256 MB on 64-bit
processes for every virtual file. Under commit pressure, touching a
lazily
allocated page could raise an uncatchable `AccessViolationException`
inside the
source generator and terminate the compiler.

The new implementation:

- allocates memory in 64 KB chunks as content grows;
- preserves the existing synchronous stream contract and adds direct
span and
  asynchronous stream paths;
- zero-fills sparse gaps and discarded content when files shrink and
regrow;
- supports empty physical files, preserves their last-write timestamps,
and
  prevents read-stream seeks from extending file length;
- seals `VirtualFileSystem`, which was not intended as a supported
subclassing
  API.

## Related Issues

- Fixes #4233

## Validation

- `dotnet test tests\Opc.Ua.Types.Tests\Opc.Ua.Types.Tests.csproj -f
net10.0 --filter "Category=FileSystem"`
- `dotnet test tests\Opc.Ua.Types.Tests\Opc.Ua.Types.Tests.csproj -f
net48 --filter "Category=FileSystem"`
- `dotnet test
tests\Opc.Ua.SourceGeneration.Core.Tests\Opc.Ua.SourceGeneration.Core.Tests.csproj
-f net10.0`
- Scoped whitespace, style, and analyzer formatting checks for the
changed
  source and test files

## Checklist

- [ ] I have signed the
[CLA](https://opcfoundation.org/license/cla/ContributorLicenseAgreementv1.0.pdf)
and read the
[CONTRIBUTING](https://github.com/OPCFoundation/UA-.NETStandard/blob/master/CONTRIBUTING.md)
doc.
- [x] I have added tests that prove my fix is effective or that my
feature works and increased code coverage.
- [x] I have added all necessary documentation.
- [x] I have verified that my changes do not introduce (new) build or
analyzer warnings.
- [ ] I ran **all** tests locally using the **UA.slnx** solution against
at least .net **framework** and .net **10**, and all passed.
- [ ] I fixed **all** failing and flaky tests in the CI pipelines and
**all** CodeQL warnings.
- [x] I have addressed **all** PR feedback received.

---------

Copilot-Session: 38223d6a-b707-4255-940f-9e67f666590c
2026-08-12 14:33:35 +00:00
..