diff --git a/tests/ImageSharp.Tests/TestFile.cs b/tests/ImageSharp.Tests/TestFile.cs
index ed5c4a0f09..8a14a6be2e 100644
--- a/tests/ImageSharp.Tests/TestFile.cs
+++ b/tests/ImageSharp.Tests/TestFile.cs
@@ -29,7 +29,12 @@ public sealed class TestFile
///
/// The image (lazy initialized value)
///
- private Image image;
+ private volatile Image image;
+
+ ///
+ /// Used to ensure image loading is threadsafe.
+ ///
+ private readonly object syncLock = new();
///
/// The image bytes
@@ -65,7 +70,21 @@ public sealed class TestFile
///
/// Gets the image with lazy initialization.
///
- private Image Image => this.image ??= ImageSharp.Image.Load(this.Bytes);
+ private Image Image
+ {
+ get
+ {
+ if (this.image is null)
+ {
+ lock (this.syncLock)
+ {
+ this.image ??= ImageSharp.Image.Load(this.Bytes);
+ }
+ }
+
+ return this.image;
+ }
+ }
///
/// Gets the input image directory.