Skip to content

Commit 9190a1c

Browse files
Fixed wrong application domain selected (#410)
This change fixed the FileNotFoundException at SqlDependency.Start() by replacing the default AppDomain with the current.
1 parent 7a2120d commit 9190a1c

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/Interop/SNINativeMethodWrapper.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,7 @@ internal static int SniMaxComposedSpnLength
8080

8181
static AppDomain GetDefaultAppDomainInternal()
8282
{
83-
var host = new mscoree.CorRuntimeHost();
84-
host.GetDefaultDomain(out object temp);
85-
AppDomain defaultAppDomain = temp as AppDomain;
86-
return defaultAppDomain;
83+
return AppDomain.CurrentDomain;
8784
}
8885

8986
internal static _AppDomain GetDefaultAppDomain()

src/Microsoft.Data.SqlClient/tests/ManualTests/Microsoft.Data.SqlClient.ManualTesting.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
<Compile Include="SQL\SqlBulkCopyTest\CopyWidenNullInexactNumerics.cs" />
122122
<Compile Include="SQL\SqlCommand\SqlCommandSetTest.cs" />
123123
<Compile Include="SQL\SqlCredentialTest\SqlCredentialTest.cs" />
124+
<Compile Include="SQL\SqlDependencyTest\SqlDependencyTest.cs" />
124125
<Compile Include="SQL\SqlSchemaInfoTest\SqlSchemaInfoTest.cs" />
125126
<Compile Include="SQL\SqlStatisticsTest\SqlStatisticsTest.cs" />
126127
<Compile Include="SQL\SqlBulkCopyTest\AdjustPrecScaleForBulkCopy.cs" />
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using Xunit;
7+
8+
namespace Microsoft.Data.SqlClient.ManualTesting.Tests
9+
{
10+
public class SqlDependencyTest
11+
{
12+
[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureServer))]
13+
public void SqlDependencyStartStopTest()
14+
{
15+
try
16+
{
17+
SqlDependency.Start(DataTestUtility.TCPConnectionString);
18+
SqlDependency.Stop(DataTestUtility.TCPConnectionString);
19+
}
20+
catch (Exception e)
21+
{
22+
Assert.True(false, e.Message);
23+
}
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)