Skip to content

Commit 5952d77

Browse files
authored
Merge pull request #228 from jhartmann123/225-transaction
Fixed exception when enqueuing a job within an existing transaction scope
2 parents 5e4f1ae + 212ffc8 commit 5952d77

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace Hangfire.PostgreSql
6+
{
7+
internal class EnvironmentHelpers
8+
{
9+
private static bool? _isMono;
10+
11+
public static bool IsMono() =>
12+
_isMono ??= Type.GetType("Mono.Runtime") != null;
13+
}
14+
}

src/Hangfire.PostgreSql/PostgreSqlStorage.cs

+2-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// This file is part of Hangfire.PostgreSql.
1+
// This file is part of Hangfire.PostgreSql.
22
// Copyright © 2014 Frank Hommers <http://hmm.rs/Hangfire.PostgreSql>.
33
//
44
// Hangfire.PostgreSql is free software: you can redistribute it and/or modify
@@ -237,7 +237,7 @@ internal T UseTransaction<T>(DbConnection dedicatedConnection,
237237
{
238238
isolationLevel = isolationLevel ?? IsolationLevel.ReadCommitted;
239239

240-
if (IsRunningOnWindows())
240+
if (!EnvironmentHelpers.IsMono())
241241
{
242242
using (TransactionScope transaction = CreateTransaction(isolationLevel))
243243
{
@@ -319,15 +319,6 @@ private static void Current_TransactionCompleted(object sender, TransactionEvent
319319
}
320320
}
321321

322-
private static bool IsRunningOnWindows()
323-
{
324-
#if !NETSTANDARD1_3
325-
return Environment.OSVersion.Platform == PlatformID.Win32NT;
326-
#else
327-
return System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows);
328-
#endif
329-
}
330-
331322
private static TransactionScope CreateTransaction(IsolationLevel? isolationLevel)
332323
{
333324
return isolationLevel != null

0 commit comments

Comments
 (0)