diff --git a/dnSpy/dnSpy/Documents/DsDocumentService.cs b/dnSpy/dnSpy/Documents/DsDocumentService.cs index 837edaef21..b008bc8e76 100644 --- a/dnSpy/dnSpy/Documents/DsDocumentService.cs +++ b/dnSpy/dnSpy/Documents/DsDocumentService.cs @@ -346,11 +346,12 @@ IDsDocument GetOrAddTempCachedDocument(IDsDocument document) { return existing; } + // Disable mmap'd I/O before adding it to the temp cache to prevent another thread from + // getting the same file while we're disabling mmap'd I/O. Could lead to crashes. + DisableMMapdIO(document); + tempCacheLock.EnterWriteLock(); try { - // Disable mmap'd I/O before adding it to the temp cache to prevent another thread from - // getting the same file while we're disabling mmap'd I/O. Could lead to crashes. - DisableMMapdIO(document); if (!AssemblyLoadEnabled) tempCache.Add(document); }