Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Merge pull request #11275 from rahku/appdomain
Browse files Browse the repository at this point in the history
Add System.AppDomain apis
  • Loading branch information
Rahul Kumar committed Sep 13, 2016
2 parents fd90f22 + e1311a2 commit 64df6e5
Show file tree
Hide file tree
Showing 19 changed files with 192 additions and 52 deletions.
3 changes: 2 additions & 1 deletion pkg/Microsoft.Private.PackageBaseline/packageIndex.json
Expand Up @@ -678,7 +678,8 @@
"4.0.0.0": "4.0.0",
"4.1.0.0": "4.1.0",
"4.1.1.0": "4.1.1",
"4.0.1.0": "4.0.1"
"4.0.1.0": "4.0.1",
"4.2.0.0": "4.3.0"
}
},
"System.Buffers": {
Expand Down
2 changes: 1 addition & 1 deletion src/System.AppContext/dir.props
@@ -1,7 +1,7 @@
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\dir.props" />
<PropertyGroup>
<AssemblyVersion>4.1.1.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
</PropertyGroup>
</Project>

5 changes: 1 addition & 4 deletions src/System.AppContext/pkg/System.AppContext.pkgproj
Expand Up @@ -7,11 +7,8 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\ref\4.0.0\System.AppContext.depproj">
<SupportedFramework>net46;netcore50</SupportedFramework>
</ProjectReference>
<ProjectReference Include="..\ref\System.AppContext.csproj">
<SupportedFramework>net463;netcoreapp1.0;$(AllXamarinFrameworks)</SupportedFramework>
<SupportedFramework>net463;netcoreapp1.1;$(AllXamarinFrameworks)</SupportedFramework>
</ProjectReference>
<ProjectReference Include="..\src\System.AppContext.builds"/>
</ItemGroup>
Expand Down
9 changes: 9 additions & 0 deletions src/System.AppContext/ref/System.AppContext.Forwards.cs
@@ -0,0 +1,9 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
// ------------------------------------------------------------------------------
// Changes to this file must follow the http://aka.ms/api-review process.
// ------------------------------------------------------------------------------


[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.AppContext))]
19 changes: 0 additions & 19 deletions src/System.AppContext/ref/System.AppContext.cs

This file was deleted.

8 changes: 6 additions & 2 deletions src/System.AppContext/ref/System.AppContext.csproj
Expand Up @@ -3,13 +3,17 @@
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<PropertyGroup>
<OutputType>Library</OutputType>
<NuGetTargetMoniker>.NETStandard,Version=v1.6</NuGetTargetMoniker>
<NuGetTargetMoniker>.NETStandard,Version=v1.7</NuGetTargetMoniker>
</PropertyGroup>
<ItemGroup>
<Compile Include="System.AppContext.cs" />
<Compile Include="System.AppContext.Forwards.cs" />
</ItemGroup>
<ItemGroup>
<None Include="project.json" />
</ItemGroup>
<ItemGroup>
<!-- Temporary till we publish System.Runtime updated package -->
<ProjectReference Include="..\..\System.Runtime\ref\System.Runtime.csproj" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>
4 changes: 3 additions & 1 deletion src/System.AppContext/src/ApiCompatBaseline.net463.txt
@@ -1,2 +1,4 @@
MembersMustExist : Member 'System.AppContext.TargetFrameworkName.get()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'System.AppContext.GetData(System.String)' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'System.AppContext.GetData(System.String)' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'System.AppContext.add_UnhandledException(System.UnhandledExceptionEventHandler)' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'System.AppContext.remove_UnhandledException(System.UnhandledExceptionEventHandler)' does not exist in the implementation but it does exist in the contract.
9 changes: 0 additions & 9 deletions src/System.AppContext/src/System.AppContext.builds
Expand Up @@ -3,18 +3,9 @@
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<ItemGroup>
<Project Include="System.AppContext.csproj" />
<Project Include="redist\System.AppContext.depproj">
<TargetGroup>net46</TargetGroup>
</Project>
<Project Include="System.AppContext.csproj">
<TargetGroup>net463</TargetGroup>
</Project>
<Project Include="System.AppContext.csproj">
<TargetGroup>netcore50</TargetGroup>
</Project>
<Project Include="System.AppContext.csproj">
<TargetGroup>netcore50aot</TargetGroup>
</Project>
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.traversal.targets))\dir.traversal.targets" />
</Project>
Expand Down
8 changes: 1 addition & 7 deletions src/System.AppContext/src/System.AppContext.csproj
Expand Up @@ -5,13 +5,12 @@
<AssemblyName>System.AppContext</AssemblyName>
<ProjectGuid>{5522BAFC-E2FF-4896-993A-401DDEDFD85F}</ProjectGuid>
<ClsCompliant>true</ClsCompliant>
<AssemblyVersion Condition="'$(TargetGroup)'=='netcore50' OR '$(TargetGroup)'=='netcore50aot'">4.0.0.0</AssemblyVersion>
<IsPartialFacadeAssembly Condition="'$(TargetGroup)'!='netcore50aot'">true</IsPartialFacadeAssembly>
<ContractProject Condition="'$(TargetGroup)'=='netcore50'">..\ref\4.0.0\System.AppContext.depproj</ContractProject>
<!-- The following line needs to be removed once we have a targeting pack for 4.6.3 -->
<TargetingPackNugetPackageId Condition="'$(TargetGroup)'=='net463'">Microsoft.TargetingPack.NETFramework.v4.6.2</TargetingPackNugetPackageId>
<ExcludeResourcesImport Condition="'$(IsPartialFacadeAssembly)'=='true'">true</ExcludeResourcesImport>
<NuGetTargetMoniker Condition="'$(TargetGroup)' == ''">.NETStandard,Version=v1.6</NuGetTargetMoniker>
<NuGetTargetMoniker Condition="'$(TargetGroup)' == ''">.NETStandard,Version=v1.7</NuGetTargetMoniker>
</PropertyGroup>
<!-- Default configurations to help VS understand the options -->
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'" />
Expand All @@ -22,11 +21,6 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcore50aot_Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'net463_Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'net463_Release|AnyCPU'" />
<ItemGroup Condition="'$(TargetGroup)'=='netcore50aot'">
<TargetingPackReference Include="Windows" />
<ProjectReference Include="$(SourceDir)/mscorlib.WinRT-Facade/mscorlib.WinRT-Facade.csproj" />
<Compile Include="System\AppContext.cs" />
</ItemGroup>
<ItemGroup Condition="'$(IsPartialFacadeAssembly)'=='true'">
<TargetingPackReference Include="mscorlib" />
</ItemGroup>
Expand Down
13 changes: 5 additions & 8 deletions src/System.AppContext/src/project.json
@@ -1,21 +1,18 @@
{
"frameworks": {
"netstandard1.6": {
"netstandard1.7": {
"dependencies": {
"Microsoft.TargetingPack.Private.CoreCLR": "1.1.0-beta-24513-04"
},
"imports": [
"dotnet5.6"
]
},
"netcore50": {
}
},
"netstandard1.6": {
"dependencies": {
"Microsoft.TargetingPack.Private.CoreCLR": "1.1.0-beta-24513-04"
}
},
"net463": {
"dependencies": {
"Microsoft.TargetingPack.NETFramework.v4.6.2": "1.0.1"
"Microsoft.TargetingPack.NETFramework.v4.6": "1.0.1"
}
}
}
Expand Down
49 changes: 49 additions & 0 deletions src/System.AppContext/tests/AppContext.UnhandledException.cs
@@ -0,0 +1,49 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Xunit;

namespace System.Tests
{
public partial class AppContextTests
{
[Fact]
public void UnhandledException_IsNull()
{
Assert.IsNull(AppContext.UnhandledException);
}

[Fact]
public void UnhandledException_Add_Remove()
{
AppContext.UnhandledException += new UnhandledExceptionEventHandler(MyHandler);
Assert.IsNotNull(AppContext.UnhandledException);
AppContext.UnhandledException -= new UnhandledExceptionEventHandler(MyHandler);
Assert.IsNull(AppContext.UnhandledException);
}

[Fact]
public void UnhandledException_NotCalled_When_Handled()
{
AppContext.UnhandledException += new UnhandledExceptionEventHandler(NotExpectedToBeCalledHandler);
try {
throw new Exception();
}
catch(Exception e)
{
}
AppContext.UnhandledException -= new UnhandledExceptionEventHandler(NotExpectedToBeCalledHandler);
}

static void NotExpectedToBeCalledHandler(object sender, UnhandledExceptionEventArgs args)
{
Assert.Fail("UnhandledException handler not expected to be called");
}

static void MyHandler(object sender, UnhandledExceptionEventArgs args)
{
Exception e = (Exception) args.ExceptionObject;
}
}
}
Expand Up @@ -8,6 +8,15 @@

namespace System
{
public partial class AppDomain
{
private AppDomain() {}
public static AppDomain CurrentDomain { get { return default(AppDomain); } }
public string BaseDirectory { get { return default(string); } }
public string RelativeSearchPath { get { return default(string); } }
public event System.UnhandledExceptionEventHandler UnhandledException { add { } remove { } }
}

[Flags]
public enum Base64FormattingOptions
{
Expand Down
Expand Up @@ -44,6 +44,9 @@
<ExcludeAssemblyInfoPartialFile>true</ExcludeAssemblyInfoPartialFile>
</PropertyGroup>
<!-- Shared CoreCLR and .NET Native -->
<ItemGroup Condition="'$(TargetGroup)' == ''">
<Compile Include="System\AppDomain.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetGroup)' != 'net462' And '$(TargetGroup)' != 'net463'">
<Compile Include="System\BitConverter.cs" />
<Compile Include="System\Diagnostics\Stopwatch.cs" />
Expand Down
30 changes: 30 additions & 0 deletions src/System.Runtime.Extensions/src/System/AppDomain.cs
@@ -0,0 +1,30 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Reflection;

namespace System
{
public partial class AppDomain
{
private static AppDomain s_domain = new AppDomain();
private AppDomain() {}
public static AppDomain CurrentDomain => s_domain;
public string BaseDirectory => AppContext.BaseDirectory;
public string RelativeSearchPath => null;
public event UnhandledExceptionEventHandler UnhandledException
{
add
{
AppContext.UnhandledException += value;
}

remove
{
AppContext.UnhandledException -= value;
}
}
}
}
Expand Up @@ -26,6 +26,7 @@
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'netstandard1.7_Debug|AnyCPU' " />
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'netstandard1.7_Release|AnyCPU' " />
<ItemGroup>
<Compile Include="System\AppDomainTests.cs" Condition="'$(TargetGroup)'=='netstandard1.7'" />
<Compile Include="System\Diagnostics\Stopwatch.cs" />
<Compile Include="System\EnvironmentTests.cs" Condition="'$(TargetGroup)'=='netstandard1.7'" />
<Compile Include="System\Environment.MachineName.cs" />
Expand Down Expand Up @@ -100,6 +101,10 @@
<Project>{1e689c1b-690c-4799-bde9-6e7990585894}</Project>
<Name>System.Runtime.Extensions.CoreCLR</Name>
</ProjectReference>
<ProjectReference Include="..\..\System.Runtime\pkg\System.Runtime.pkgproj">
</ProjectReference>
<ProjectReference Include="..\..\System.AppContext\pkg\System.AppContext.pkgproj">
</ProjectReference>
<ProjectReference Include="..\..\System.Private.Uri\pkg\System.Private.Uri.pkgproj">
</ProjectReference>
<ProjectReference Include="$(CommonTestPath)\System\Diagnostics\RemoteExecutorConsoleApp\RemoteExecutorConsoleApp.csproj">
Expand Down
38 changes: 38 additions & 0 deletions src/System.Runtime.Extensions/tests/System/AppDomainTests.cs
@@ -0,0 +1,38 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Diagnostics;
using System;
using Xunit;
using Xunit.NetCore.Extensions;

namespace System.Tests
{
public class AppDomainTests : RemoteExecutorTestBase
{
[Fact]
public void CurrentDomain_Not_Null()
{
Assert.NotNull(AppDomain.CurrentDomain);
}

[Fact]
public void CurrentDomain_Idempotent()
{
Assert.Equal(AppDomain.CurrentDomain, AppDomain.CurrentDomain);
}

[Fact]
public void BaseDirectory_Same_As_AppContext()
{
Assert.Equal(AppDomain.CurrentDomain.BaseDirectory, AppContext.BaseDirectory);
}

[Fact]
public void RelativeSearchPath_Is_Null()
{
Assert.Null(AppDomain.CurrentDomain.RelativeSearchPath);
}
}
}
19 changes: 19 additions & 0 deletions src/System.Runtime/ref/System.Runtime.cs
Expand Up @@ -54,6 +54,16 @@ public static partial class Activator
public static object CreateInstance(System.Type type, params object[] args) { return default(object); }
public static T CreateInstance<T>() { return default(T); }
}

public static partial class AppContext
{
public static string BaseDirectory { get { return default(string); } }
public static void SetSwitch(string switchName, bool isEnabled) { }
public static event System.UnhandledExceptionEventHandler UnhandledException { add { } remove { } }
public static bool TryGetSwitch(string switchName, out bool isEnabled) { isEnabled = default(bool); return default(bool); }
public static string TargetFrameworkName { get { return default(string); } }
public static object GetData(string name) { return default(object); }
}

public partial class EntryPointNotFoundException : System.TypeLoadException
{
Expand Down Expand Up @@ -2595,6 +2605,15 @@ public partial class UnauthorizedAccessException : System.Exception
public UnauthorizedAccessException(string message, System.Exception inner) { }
protected UnauthorizedAccessException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
}

public partial class UnhandledExceptionEventArgs : System.EventArgs
{
public UnhandledExceptionEventArgs(object exception, bool isTerminating) { }
public object ExceptionObject { get { throw null; } }
public bool IsTerminating { get { throw null; } }
}
public delegate void UnhandledExceptionEventHandler(object sender, System.UnhandledExceptionEventArgs e);

public partial class Uri
{
public static readonly string SchemeDelimiter;
Expand Down
8 changes: 8 additions & 0 deletions src/System.Runtime/src/ApiCompatBaseline.net463.txt
@@ -0,0 +1,8 @@
MembersMustExist : Member 'System.Type.IsSecurityCritical.get()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'System.Type.IsSecuritySafeCritical.get()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'System.Type.IsSecurityTransparent.get()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'System.Reflection.Pointer..ctor()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'System.AppContext.TargetFrameworkName.get()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'System.AppContext.GetData(System.String)' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'System.AppContext.add_UnhandledException(System.UnhandledExceptionEventHandler)' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'System.AppContext.remove_UnhandledException(System.UnhandledExceptionEventHandler)' does not exist in the implementation but it does exist in the contract.
3 changes: 3 additions & 0 deletions src/System.Runtime/src/ApiCompatBaseline.uap101aot.txt
Expand Up @@ -670,3 +670,6 @@ CannotRemoveBaseTypeOrInterface : Type 'System.Threading.Tasks.Task' does not im
MembersMustExist : Member 'System.Threading.Tasks.Task.Dispose()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'System.Threading.Tasks.Task.Dispose(System.Boolean)' does not exist in the implementation but it does exist in the contract.
CannotRemoveBaseTypeOrInterface : Type 'System.Threading.Tasks.Task<TResult>' does not implement interface 'System.IDisposable' in the implementation but it does in the contract.
TypesMustExist : Type 'System.AppContext' does not exist in the implementation but it does exist in the contract.
TypesMustExist : Type 'System.UnhandledExceptionEventArgs' does not exist in the implementation but it does exist in the contract.
TypesMustExist : Type 'System.UnhandledExceptionEventHandler' does not exist in the implementation but it does exist in the contract.

0 comments on commit 64df6e5

Please sign in to comment.