diff --git a/src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs b/src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs
index 388157a11b..e859162980 100644
--- a/src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs
+++ b/src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs
@@ -2026,17 +2026,22 @@ private static class ThreadSafeRandom {
///
/// A thread-local instance of
///
- private static readonly ThreadLocal threadRandom = new ThreadLocal(delegate {
- lock (threadRandomInitializer) {
- return new Random(threadRandomInitializer.Next());
- }
- });
+ [ThreadStatic]
+ private static Random threadRandom;
///
/// Gets a random number generator for use on the current thread only.
///
public static Random RandomNumberGenerator {
- get { return threadRandom.Value; }
+ get {
+ if (threadRandom == null) {
+ lock (threadRandomInitializer) {
+ threadRandom = new Random(threadRandomInitializer.Next());
+ }
+ }
+
+ return threadRandom;
+ }
}
}