Skip to content

Commit 95908fe

Browse files
authored
Merge branch 'master' into GH-1300
2 parents c704765 + 5e8f2c8 commit 95908fe

File tree

6 files changed

+68
-15
lines changed

6 files changed

+68
-15
lines changed

src/NHibernate/Bytecode/Lightweight/ReflectionOptimizer.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,22 @@ protected virtual void ThrowExceptionForNoDefaultCtor(System.Type type)
101101

102102
protected DynamicMethod CreateDynamicMethod(System.Type returnType, System.Type[] argumentTypes)
103103
{
104-
System.Type owner = mappedType.IsInterface ? typeof (object) : mappedType;
105-
#pragma warning disable 612,618
106-
bool canSkipChecks = SecurityManager.IsGranted(new ReflectionPermission(ReflectionPermissionFlag.MemberAccess));
107-
#pragma warning restore 612,618
104+
var owner = mappedType.IsInterface ? typeof (object) : mappedType;
105+
var canSkipChecks = CanSkipVisibilityChecks();
108106
return new DynamicMethod(string.Empty, returnType, argumentTypes, owner, canSkipChecks);
109107
}
110108

109+
private static bool CanSkipVisibilityChecks()
110+
{
111+
#if NETFX
112+
var permissionSet = new PermissionSet(PermissionState.None);
113+
permissionSet.AddPermission(new ReflectionPermission(ReflectionPermissionFlag.MemberAccess));
114+
return permissionSet.IsSubsetOf(AppDomain.CurrentDomain.PermissionSet);
115+
#else
116+
return false;
117+
#endif
118+
}
119+
111120
private static void EmitCastToReference(ILGenerator il, System.Type type)
112121
{
113122
if (type.IsValueType)

src/NHibernate/Context/WcfOperationSessionContext.cs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
using System;
1+
// There is no support of WCF Server under .Net Core, so it makes little sense to provide
2+
// a WCF OperationContext for it. Since it adds additional heavy dependencies, it has been
3+
// considered not desirable to provide it for .Net Standard. (It could be useful in case some
4+
// WCF server becames available in another frameworks or if a .Net Framework application
5+
// consumes the .Net Standard distribution of NHibernate instead of the .Net Framework one.)
6+
// See https://github.com/dotnet/wcf/issues/1200 and #1842
7+
#if NETFX
28
using System.Collections;
39
using System.ServiceModel;
410

@@ -50,3 +56,36 @@ public void Attach(OperationContext owner) { }
5056
public void Detach(OperationContext owner) { }
5157
}
5258
}
59+
#else
60+
// 6.0 TODO: remove the whole #else
61+
using System;
62+
using System.Collections;
63+
using NHibernate.Engine;
64+
65+
namespace NHibernate.Context
66+
{
67+
/// <summary>
68+
/// Obsolete class not usable with the current framework. Use the
69+
/// .Net Framework distribution of NHibernate if you need it. See
70+
/// https://github.com/nhibernate/nhibernate-core/issues/1842
71+
/// </summary>
72+
[Obsolete("Not supported in this platform", true)]
73+
public class WcfOperationSessionContext : MapBasedSessionContext
74+
{
75+
public WcfOperationSessionContext(ISessionFactoryImplementor factory) : base(factory)
76+
{
77+
throw new PlatformNotSupportedException(
78+
"WcfOperationSessionContext is not supported for the current framework");
79+
}
80+
81+
protected override IDictionary GetMap()
82+
{
83+
return null;
84+
}
85+
86+
protected override void SetMap(IDictionary value)
87+
{
88+
}
89+
}
90+
}
91+
#endif

src/NHibernate/Driver/OdbcDriver.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Collections.Generic;
33
using System.Data;
44
using System.Data.Common;
5-
using System.Data.Odbc;
65
using NHibernate.SqlTypes;
76
using NHibernate.Util;
87
using Environment = NHibernate.Cfg.Environment;
@@ -47,12 +46,12 @@ public OdbcDriver()
4746
#else
4847
public override DbConnection CreateConnection()
4948
{
50-
return new OdbcConnection();
49+
return new System.Data.Odbc.OdbcConnection();
5150
}
5251

5352
public override DbCommand CreateCommand()
5453
{
55-
return new OdbcCommand();
54+
return new System.Data.Odbc.OdbcCommand();
5655
}
5756
#endif
5857

src/NHibernate/Driver/OleDbDriver.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Data.Common;
3-
using System.Data.OleDb;
43

54
namespace NHibernate.Driver
65
{
@@ -26,12 +25,12 @@ public OleDbDriver()
2625
#else
2726
public override DbConnection CreateConnection()
2827
{
29-
return new OleDbConnection();
28+
return new System.Data.OleDb.OleDbConnection();
3029
}
3130

3231
public override DbCommand CreateCommand()
3332
{
34-
return new OleDbCommand();
33+
return new System.Data.OleDb.OleDbCommand();
3534
}
3635
#endif
3736

src/NHibernate/Impl/SessionFactoryImpl.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,7 +1276,18 @@ private ICurrentSessionContext BuildCurrentSessionContext()
12761276
case "web":
12771277
return new WebSessionContext(this);
12781278
case "wcf_operation":
1279+
#if NETFX
12791280
return new WcfOperationSessionContext(this);
1281+
#else
1282+
// There is no support of WCF Server under .Net Core, so it makes little sense to provide
1283+
// a WCF OperationContext for it. Since it adds additional heavy dependencies, it has been
1284+
// considered not desirable to provide it for .Net Standard. (It could be useful in case some
1285+
// WCF server becames available in another frameworks or if a .Net Framework application
1286+
// consumes the .Net Standard distribution of NHibernate instead of the .Net Framework one.)
1287+
// See https://github.com/dotnet/wcf/issues/1200 and #1842
1288+
throw new PlatformNotSupportedException(
1289+
"WcfOperationSessionContext is not supported for the current framework");
1290+
#endif
12801291
}
12811292

12821293
try

src/NHibernate/NHibernate.csproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,11 @@
5252
</ItemGroup>
5353

5454
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.0'">
55-
<PackageReference Include="System.ServiceModel.Primitives" Version="4.4.0" />
5655
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.4.1" />
57-
<PackageReference Include="System.Security.Permissions" Version="4.4.1" />
5856
</ItemGroup>
5957

6058
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
61-
<PackageReference Include="System.ServiceModel.Primitives" Version="4.4.0" />
6259
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.4.1" />
63-
<PackageReference Include="System.Security.Permissions" Version="4.4.1" />
6460
<PackageReference Include="System.Reflection.Emit" Version="4.3.0" />
6561
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.3.0" />
6662
</ItemGroup>

0 commit comments

Comments
 (0)