diff --git a/docs/coding-guidelines/project-guidelines.md b/docs/coding-guidelines/project-guidelines.md
index f0050a58588096..6a8f0bae4ac0dd 100644
--- a/docs/coding-guidelines/project-guidelines.md
+++ b/docs/coding-guidelines/project-guidelines.md
@@ -169,8 +169,8 @@ The output for the src product build will be a flat runtime folder into the foll
`bin\runtime\$(BuildSettings)`
-Note: The `BuildSettings` is a global property and not the project setting because we need all projects to output to the same runtime directory no matter which compatible target framework we select and build the project with.
-```$(BuildTargetFramework)-$(TargetOS)-(Configuration)-(TargetArchitecture)```
+Note: The `BuildSettings` is a global property and not the project setting because we need all projects to output to the same runtime directory no matter which compatible target framework we select and build the project with.
+```$(BuildTargetFramework)-$(TargetOS)-(Configuration)-(TargetArchitecture)```
## pkg
In the pkg directory for the library there should be only **one** `.pkgproj` for the primary package for the library. If the library has platform-specific implementations those should be split into platform specific projects in a subfolder for each platform. (see [Package projects](./package-projects.md))
@@ -216,7 +216,6 @@ Each source file should use the following guidelines
- Where `` is the name of something that causes a fork in code that isn't a single configuration. Examples:
- `.CoreCLR.cs` - implementation specific to CoreCLR runtime
- `.Win32.cs` - implementation based on [Win32](https://en.wikipedia.org/wiki/Windows_API)
- - `.WinRT.cs` - implementation based on [WinRT](https://en.wikipedia.org/wiki/Windows_Runtime)
## Define naming convention
diff --git a/docs/design/features/WinRT-activation.md b/docs/design/features/WinRT-activation.md
deleted file mode 100644
index e8a72d5dd92ec3..00000000000000
--- a/docs/design/features/WinRT-activation.md
+++ /dev/null
@@ -1,53 +0,0 @@
-# Managed WinRT Activation of .NET Core components
-
-As part of supporting a complete story for XAML Islands on .NET Core, we should provide a mechanism of activating .NET Core WinRT components. To do so, we will follow the path of the COM and IJW activations and provide a new host for activating these components in a manner similar to native WinRT components, which we will call the `winrthost`. We are creating a separate host instead of combining with the COM host because the COM and WinRT hosts (although generally similar in design in Windows) have very different activation and resolution paths. As a result, we would not be able to reuse much code at all. Additionally, the WinRT host does not require a `clsidmap` or similar functionality to function. If we were to combine the two hosts, we would have to emit an empty clsidmap when creating the host and modify it even though the WinRT portion has no dependencies on any embedded resources.
-
-## Requirements
-
-* Discover all installed versions of .NET Core.
-* Load the appropriate version of .NET Core for the class if a .NET Core instance is not running, or validate the currently existing .NET Core instance can satisfy the class requirement.
-* Return an [`IActivationFactory`](https://docs.microsoft.com/windows/desktop/api/activation/nn-activation-iactivationfactory) implementation that will construct an instance of the .NET WinRT class.
-
-## Native WinRT Activation
-
-In the native (C++/CX, C++/WRL, or C++/WinRT) world, building a WinRT Component named `MyComponent` produces files named `MyComponent.dll`, `MyComponent.winmd`. In this world, the `winmd` contains the metadata describing the types provided by the component, and the code implementing said types is compiled into the `dll`. When an application wants to activate a component, it will call [`RoGetActivationFactory`](https://docs.microsoft.com/windows/desktop/api/roapi/nf-roapi-rogetactivationfactory). The operating system will then search through various areas in the filesystem to find the correct component for the class name. Starting in Windows 10 19H1, there is now support for declaring that specific classes come from components that live side-by-side with the application, similar to Reg-Free COM. After finding the correct component, the OS will load the component via `CoLoadLibrary` and then call the `DllGetActivationFactory` entrypoint, which gets an activation factory for the class by name.
-
-## Proposed Managed WinRT Activation
-
-In the managed (.NET) world, we put all of the code that implements the component into the `winmd`. So, when running in an AppContainer/`.appx`, a .NET component only needs one file. However, when outside of an AppContainer, there needs to be some sort of host to activate runtime. We will supply a host that implements the [`DllGetActivationFactory`](https://docs.microsoft.com/previous-versions//br205771(v=vs.85)) entrypoint. When `DllGetActivationFactory` is called, the following will occur:
-
-1) If a [`.runtimeconfig.json`](https://github.com/dotnet/cli/blob/master/Documentation/specs/runtime-configuration-file.md) file exists adjacent to the shim assembly (`.runtimeconfig.json`), that file will be used to describe CLR configuration details. The documentation for the `.runtimeconfig.json` format defines under what circumstances this file may be optional.
-2) Using the existing `hostfxr` library, attempt to discover the desired CLR and target [framework](https://docs.microsoft.com/en-us/dotnet/core/packages#frameworks).
- * If a CLR is active with the process, the requested CLR version will be validated against that CLR. If version satisfiability fails, activation will fail.
- * If a CLR is **not** active with the process, an attempt will be made to create a satisfying CLR instance.
- * Failure to create an instance will result in activation failure.
-3) A request to the CLR will be made to load the corresponding WinRT type for the given type name into the runtime.
- * This request will use the runtime's current support for resolving WinRT types to correctly resolve them.
- * The ability to load an assembly from memory will require exposing a new function that can be called from `hostfxr`, as well as a new API in `System.Private.CoreLib` on a new class in `Internal.Runtime.InteropServices`:
-
-```csharp
-namespace Internal.Runtime.InteropServices.WindowsRuntime
-{
- public static class ActivationFactoryLoader
- {
- public unsafe static int GetActivationFactory(
- char* componentPath,
- [MarshalAs(UnmanagedType.HString)] string typeName,
- [MarshalAs(UnmanagedType.Interface)] out IActivationFactory activationFactory);
- }
-}
-```
-
-Note this API would not be exposed outside of `System.Private.CoreLib` unless we decide to do so. The runtime loads WinRT components via a different binder than .NET assemblies, so the WinRT component assemblies themselves will be loaded by the WinRT binder, but all assemblies that the WinRT component depends on will be loaded into an isolated `AssemblyLoadContext`.
-
-To match the user-visible architecture of native WinRT Activation, when building a Windows Metadata component (`winmdobj`), we will copy the `winrthost` to the user's output directory and rename it to be the same name as the `.winmd` but with a `.dll` extension. For example, if the user creates a project `MyComponent` and is building a Windows Metadata component, we will copy the `winrthost` to the output directory for `MyComponent` and rename it to be `MyComponent.dll`. From a user's perspective, they will activate WinRT objects via `MyComponent.dll`, the same as if the component was a native WinRT component.
-
-## Error reporting
-
-If the runtime activation fails, we want to ensure that the user can diagnose the failure. However, we don't want to write directly to the `stderr` of a process that we don't own. So, we will redirect the trace stream to point to a local stream. In the case of failure to activate the runtime, we will report the error code via [`RoOriginateErrorW`](https://docs.microsoft.com/windows/desktop/api/roerrorapi/nf-roerrorapi-rooriginateerrorw), which will present the user with the error according to the error reporting flags they have set via [`RoSetErrorReportingFlags`](https://docs.microsoft.com/windows/desktop/api/roerrorapi/nf-roerrorapi-roseterrorreportingflags).
-
-## Open issues
-
-* The tool that converts the `.winmdobj` to a `.winmd`, WinMDExp, is only available in Desktop MSBuild and is not available in the .NET Core MSBuild distribution. Additionally, WinMDExp only supports full PDBs and will fail if given portable PDBs.
-* To build a `.winmdobj`, the user will need to reference a contract assembly that includes the `Windows.Foundation` namespace. There are new packages that expose these contract assemblies, but we should ensure that these contract assemblies will be released by the time that we finalize our Managed WinRT Component support.
-* Writing unit tests for the WinRT host without modifying system-global state requires the new Reg-Free WinRT support, which is Windows 10 19H1 only.
diff --git a/docs/design/features/host-components.md b/docs/design/features/host-components.md
index ca351fb970c9d1..59669d661d39e8 100644
--- a/docs/design/features/host-components.md
+++ b/docs/design/features/host-components.md
@@ -8,15 +8,14 @@ The .NET Core default hosting setup consists of several components which are des
* `apphost` (executable) - which is used to give app an actual executable which can be run directly. The executable will be named using the application name. The advantage of having an app-local executable is that it can be customized for each app (not just the name, but icon, OS behavior and so on).
* `comhost` (library) - which is used to enable COM server hosting. Component which wants to expose COM server objects will be built with this dynamic library in its output. The `comhost` then acts as the main entry point for the OS.
* `ijwhost` (library) - which is used to enable loading of IJW assemblies. The library exposes functionality needed by the C++ compiler to generate mixed mode assemblies.
-* `winrthost` (library) - which is used to enable WinRT component hosting. Any component which wants to be a WinRT component will be built with this library in its output. The `winrthost` then acts as the main entry point for the OS (very similar to `comhost`).
* `nethost` (library) - which is used by native apps (any app which is not .NET Core) to load .NET Core code dynamically.
The entry-point typically does just one thing: it finds the `hostfxr` library and passes control to it. It also exposes the right entry points for its purpose (so the "main" for `dotnet` and `apphost`, the COM exports for `comhost` and so on).
* `dotnet` host - `hostfxr` is obtained from the `./host/fxr/` folder (relative to the location of the `dotnet` host).
* `apphost`, `comhost` and the others - `hostfxr` is located using this process:
1. The app's folder is searched first. This is either the folder where the entry-point host lives or in case of `apphost` it is the path it has embedded in it as the app path.
- 1. If the `DOTNET_ROOT` environment variable is defined, that path is searched
- 1. The default shared locations are searched
+ 2. If the `DOTNET_ROOT` environment variable is defined, that path is searched
+ 3. The default shared locations are searched
## Host FXR
This library finds and resolves the runtime and all the frameworks the app needs. Then it loads the `hostpolicy` library and transfers control to it.
diff --git a/docs/design/features/localization-options.md b/docs/design/features/localization-options.md
index f2a1b5bc3f1a6c..a32be0f24ae8cf 100644
--- a/docs/design/features/localization-options.md
+++ b/docs/design/features/localization-options.md
@@ -67,7 +67,7 @@ Each host component will include English resource strings by default. If the res
`apphost` will have a single localized message. All languages will be included in the executable itself. The message will direct the user to a URL that will contain localized content.
-`ijwhost`, `winrthost`, and `nethost` intentionally do not show messages by default. They will not be localized.
+`ijwhost`, and `nethost` intentionally do not show messages by default. They will not be localized.
`comhost` also intentionally does not show messages, but it does populate an `IErrorInfo` with an error string, allowing consumers to access any error messages. This can take the same approach as `apphost`, but would be a lower priority for localization.
@@ -75,7 +75,7 @@ Each host component will include English resource strings by default. If the res
`dotnet`, `hostfxr`, and `hostpolicy` are all included as part of a .NET Core install. They can each carry their own separate resources in a known path relative next to their current install locations.
-The other entry-point hosts (`apphost`, `comhost`, `ijwhost`, `winrthost`, `nethost`) add some complication as they represent and ship as part of the developer's application or component. They are also the most impactful in terms of file size, as they are not shared across applications the way that other components can be.
+The other entry-point hosts (`apphost`, `comhost`, `ijwhost`, `nethost`) add some complication as they represent and ship as part of the developer's application or component. They are also the most impactful in terms of file size, as they are not shared across applications the way that other components can be.
The messaging coming from the hosts themselves is a small portion of the host messaging. They are mostly around:
- Failure to find `hostfxr` (all hosts)
@@ -119,9 +119,9 @@ Possible options for hosts:
2. Option: Shared resource for all hosts (except `dotnet`)
- Compatibility requirement for resource shared between hosts
-`comhost`, `ijwhost`, `winrthost`, and `nethost` are designed to be consumed by a component that .NET Core does not own and intentionally do not show messages to the user. As such, they sit at a low priority for localization support.
+`comhost`, `ijwhost`, and `nethost` are designed to be consumed by a component that .NET Core does not own and intentionally do not show messages to the user. As such, they sit at a low priority for localization support.
-`apphost` is the end-user-facing host. The amount of logic and messaging in `apphost` is intentionally limited. The most important message it contains for an end-user is for the missing .NET runtime scenario, so it should not rely on resources installed via the .NET runtime.
+`apphost` is the end-user-facing host. The amount of logic and messaging in `apphost` is intentionally limited. The most important message it contains for an end-user is for the missing .NET runtime scenario, so it should not rely on resources installed via the .NET runtime.
Embedding resources in the `apphost` would make for the most stream-lined user experience (particularly around deployment). Since the `apphost` is sensitive to size, the number of messages will be pared down to one generic localized message which directs the user to a URL.
diff --git a/docs/design/features/native-hosting.md b/docs/design/features/native-hosting.md
index fabe5a1576daf3..b5a3ea4a895d58 100644
--- a/docs/design/features/native-hosting.md
+++ b/docs/design/features/native-hosting.md
@@ -300,7 +300,7 @@ Starts the runtime and returns a function pointer to specified functionality of
* `hdt_load_assembly_and_get_function_pointer` - entry point which loads an assembly (with dependencies) and returns function pointer for a specified static method. See below for details (Loading managed components)
* `hdt_com_activation`, `hdt_com_register`, `hdt_com_unregister` - COM activation entry-points - see [COM activation](https://github.com/dotnet/runtime/tree/master/docs/design/features/COM-activation.md) for more details.
* `hdt_load_in_memory_assembly` - IJW entry-point - see [IJW activation](https://github.com/dotnet/runtime/tree/master/docs/design/features/IJW-activation.md) for more details.
- * `hdt_winrt_activation` - WinRT activation entry-point - see [WinRT activation](https://github.com/dotnet/runtime/tree/master/docs/design/features/WinRT-activation.md) for more details.
+ * `hdt_winrt_activation` - removed WinRT activation entry-point. This delegate is not supported for .NET 5 or newer.
* `delegate` - when successful, the native function pointer to the requested runtime functionality.
Initially the function will only work if `hostfxr_initialize_for_runtime_config` was used to initialize the host context. Later on this could be relaxed to allow being used in combination with `hostfxr_initialize_for_dotnet_command_line`.
diff --git a/eng/Signing.props b/eng/Signing.props
index 463c3602bb7f94..d2bd5b84e50198 100644
--- a/eng/Signing.props
+++ b/eng/Signing.props
@@ -67,7 +67,6 @@
-
diff --git a/eng/Versions.props b/eng/Versions.props
index 2b5fb65ed88e5f..38fadfa98f9877 100644
--- a/eng/Versions.props
+++ b/eng/Versions.props
@@ -90,7 +90,6 @@
99.99.99-master-20200228.399.99.99-master-20200228.3
- 1.0.51.7.02.0.0-beta1.20253.1
diff --git a/src/coreclr/clr.featuredefines.props b/src/coreclr/clr.featuredefines.props
index b4074674e5744e..151f7b29025e55 100644
--- a/src/coreclr/clr.featuredefines.props
+++ b/src/coreclr/clr.featuredefines.props
@@ -32,7 +32,6 @@
truetruetrue
- truetruetruetrue
@@ -59,7 +58,6 @@
$(DefineConstants);FEATURE_COMINTEROP$(DefineConstants);FEATURE_COMINTEROP_APARTMENT_SUPPORT$(DefineConstants);FEATURE_COMINTEROP_UNMANAGED_ACTIVATION
- $(DefineConstants);FEATURE_COMINTEROP_WINRT_MANAGED_ACTIVATION$(DefineConstants);FEATURE_MANAGED_ETW$(DefineConstants);FEATURE_MANAGED_ETW_CHANNELS$(DefineConstants);FEATURE_PERFTRACING
diff --git a/src/coreclr/clrdefinitions.cmake b/src/coreclr/clrdefinitions.cmake
index 469e0090271094..c77feb696f978e 100644
--- a/src/coreclr/clrdefinitions.cmake
+++ b/src/coreclr/clrdefinitions.cmake
@@ -99,7 +99,6 @@ if(CLR_CMAKE_TARGET_WIN32)
add_definitions(-DFEATURE_COMINTEROP)
add_definitions(-DFEATURE_COMINTEROP_APARTMENT_SUPPORT)
add_definitions(-DFEATURE_COMINTEROP_UNMANAGED_ACTIVATION)
- add_definitions(-DFEATURE_COMINTEROP_WINRT_MANAGED_ACTIVATION)
endif(CLR_CMAKE_TARGET_WIN32)
add_definitions(-DFEATURE_BASICFREEZE)
@@ -220,7 +219,6 @@ endif(CLR_CMAKE_TARGET_ARCH_AMD64 OR CLR_CMAKE_TARGET_ARCH_ARM64)
if(NOT CLR_CMAKE_TARGET_UNIX)
add_definitions(-DFEATURE_WIN32_REGISTRY)
endif(NOT CLR_CMAKE_TARGET_UNIX)
-add_definitions(-DFEATURE_WINMD_RESILIENT)
add_definitions(-D_SECURE_SCL=0)
add_definitions(-DUNICODE)
add_definitions(-D_UNICODE)
diff --git a/src/coreclr/src/CMakeLists.txt b/src/coreclr/src/CMakeLists.txt
index 262e6b7d021c3e..68e7221c8299b3 100644
--- a/src/coreclr/src/CMakeLists.txt
+++ b/src/coreclr/src/CMakeLists.txt
@@ -1,5 +1,4 @@
include_directories("inc")
-include_directories("inc/winrt")
include_directories("debug/inc")
include_directories("debug/inc/${ARCH_SOURCES_DIR}")
include_directories("debug/inc/dump")
diff --git a/src/coreclr/src/System.Private.CoreLib/ILLinkTrim.xml b/src/coreclr/src/System.Private.CoreLib/ILLinkTrim.xml
index ff08dc62974c14..e839f843700dba 100644
--- a/src/coreclr/src/System.Private.CoreLib/ILLinkTrim.xml
+++ b/src/coreclr/src/System.Private.CoreLib/ILLinkTrim.xml
@@ -64,12 +64,9 @@
-
-
-
@@ -382,9 +331,6 @@
Windows_NT
-
- true
-
diff --git a/src/coreclr/src/System.Private.CoreLib/src/Internal/Runtime/InteropServices/WindowsRuntime/ActivationFactoryLoader.cs b/src/coreclr/src/System.Private.CoreLib/src/Internal/Runtime/InteropServices/WindowsRuntime/ActivationFactoryLoader.cs
deleted file mode 100644
index a6ddce7c53bbe1..00000000000000
--- a/src/coreclr/src/System.Private.CoreLib/src/Internal/Runtime/InteropServices/WindowsRuntime/ActivationFactoryLoader.cs
+++ /dev/null
@@ -1,71 +0,0 @@
-// 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.Collections.Generic;
-using System.Runtime.InteropServices;
-using System.Runtime.InteropServices.WindowsRuntime;
-using System.Runtime.Loader;
-
-namespace Internal.Runtime.InteropServices.WindowsRuntime
-{
- internal static class ActivationFactoryLoader
- {
- // Collection of all ALCs used for WinRT activation.
- // Since each of the assemblies that act as the "key" here are WinRT assemblies
- // we don't need to share this dictionary with the COM activation dictionary
- // since there will be no overlap.
- private static readonly Dictionary s_assemblyLoadContexts = new Dictionary(StringComparer.InvariantCultureIgnoreCase);
-
- private static AssemblyLoadContext GetALC(string assemblyPath)
- {
- AssemblyLoadContext? alc;
-
- lock (s_assemblyLoadContexts)
- {
- if (!s_assemblyLoadContexts.TryGetValue(assemblyPath, out alc))
- {
- alc = new IsolatedComponentLoadContext(assemblyPath);
- s_assemblyLoadContexts.Add(assemblyPath, alc);
- }
- }
-
- return alc;
- }
-
- /// Get a WinRT activation factory for a given type name.
- /// The path to the WinRT component that the type is expected to be defined in.
- /// The name of the component type to activate
- /// The activation factory
- public static unsafe int GetActivationFactory(
- char* componentPath,
- [MarshalAs(UnmanagedType.HString)] string typeName,
- [MarshalAs(UnmanagedType.Interface)] out IActivationFactory? activationFactory)
- {
- activationFactory = null;
- try
- {
- if (typeName is null)
- {
- throw new ArgumentNullException(nameof(typeName));
- }
-
- AssemblyLoadContext context = GetALC(Marshal.PtrToStringUni((IntPtr)componentPath)!);
-
- Type winRTType = context.LoadTypeForWinRTTypeNameInContext(typeName);
-
- if (winRTType is null || !winRTType.IsExportedToWindowsRuntime)
- {
- throw new TypeLoadException(typeName);
- }
- activationFactory = WindowsRuntimeMarshal.GetManagedActivationFactory(winRTType);
- }
- catch (Exception ex)
- {
- return ex.HResult;
- }
- return 0;
- }
- }
-}
diff --git a/src/coreclr/src/System.Private.CoreLib/src/Internal/Runtime/InteropServices/WindowsRuntime/ExceptionSupport.cs b/src/coreclr/src/System.Private.CoreLib/src/Internal/Runtime/InteropServices/WindowsRuntime/ExceptionSupport.cs
deleted file mode 100644
index c7feb47db624e7..00000000000000
--- a/src/coreclr/src/System.Private.CoreLib/src/Internal/Runtime/InteropServices/WindowsRuntime/ExceptionSupport.cs
+++ /dev/null
@@ -1,76 +0,0 @@
-// 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.Diagnostics.CodeAnalysis;
-using System.Runtime.InteropServices.WindowsRuntime;
-
-namespace Internal.Runtime.InteropServices.WindowsRuntime
-{
- public static class ExceptionSupport
- {
- ///
- /// Attach restricted error information to the exception if it may apply to that exception, returning
- /// back the input value
- ///
- [return: NotNullIfNotNull("e")]
- public static Exception? AttachRestrictedErrorInfo(Exception? e)
- {
- // If there is no exception, then the restricted error info doesn't apply to it
- if (e != null)
- {
- try
- {
- // Get the restricted error info for this thread and see if it may correlate to the current
- // exception object. Note that in general the thread's IRestrictedErrorInfo is not meant for
- // exceptions that are marshaled Windows.Foundation.HResults and instead are intended for
- // HRESULT ABI return values. However, in many cases async APIs will set the thread's restricted
- // error info as a convention in order to provide extended debugging information for the ErrorCode
- // property.
- IRestrictedErrorInfo restrictedErrorInfo = UnsafeNativeMethods.GetRestrictedErrorInfo();
- if (restrictedErrorInfo != null)
- {
- restrictedErrorInfo.GetErrorDetails(out string description,
- out int restrictedErrorInfoHResult,
- out string restrictedDescription,
- out string capabilitySid);
-
- // Since this is a special case where by convention there may be a correlation, there is not a
- // guarantee that the restricted error info does belong to the async error code. In order to
- // reduce the risk that we associate incorrect information with the exception object, we need
- // to apply a heuristic where we attempt to match the current exception's HRESULT with the
- // HRESULT the IRestrictedErrorInfo belongs to. If it is a match we will assume association
- // for the IAsyncInfo case.
- if (e.HResult == restrictedErrorInfoHResult)
- {
- restrictedErrorInfo.GetReference(out string errorReference);
-
- e.AddExceptionDataForRestrictedErrorInfo(restrictedDescription,
- errorReference,
- capabilitySid,
- restrictedErrorInfo);
- }
- }
- }
- catch
- {
- // If we can't get the restricted error info, then proceed as if it isn't associated with this
- // error.
- }
- }
-
- return e;
- }
-
- ///
- /// Report that an exception has occurred which went user unhandled. This allows the global error handler
- /// for the application to be invoked to process the error.
- ///
- /// true if the error was reported, false if not (ie running on Win8)
- public static bool ReportUnhandledError(Exception? ex)
- {
- return WindowsRuntimeMarshal.ReportUnhandledError(ex);
- }
- }
-}
diff --git a/src/coreclr/src/System.Private.CoreLib/src/Microsoft/Win32/UnsafeNativeMethods.cs b/src/coreclr/src/System.Private.CoreLib/src/Microsoft/Win32/UnsafeNativeMethods.cs
deleted file mode 100644
index 423af0af538ea8..00000000000000
--- a/src/coreclr/src/System.Private.CoreLib/src/Microsoft/Win32/UnsafeNativeMethods.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-// 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.Runtime.InteropServices;
-
-namespace Microsoft.Win32
-{
- internal static class UnsafeNativeMethods
- {
-#if FEATURE_COMINTEROP
- [DllImport("api-ms-win-core-winrt-l1-1-0.dll", PreserveSig = true)]
- internal static extern int RoGetActivationFactory(
- [MarshalAs(UnmanagedType.HString)] string activatableClassId,
- [In] ref Guid iid,
- [Out, MarshalAs(UnmanagedType.IInspectable)] out object factory);
-#endif
- }
-}
diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Environment.CoreCLR.cs b/src/coreclr/src/System.Private.CoreLib/src/System/Environment.CoreCLR.cs
index f141b1e9cfeb73..8e2a9dccf8a2c5 100644
--- a/src/coreclr/src/System.Private.CoreLib/src/System/Environment.CoreCLR.cs
+++ b/src/coreclr/src/System.Private.CoreLib/src/System/Environment.CoreCLR.cs
@@ -110,20 +110,5 @@ public static extern long TickCount64
[MethodImpl(MethodImplOptions.InternalCall)]
get;
}
-
-#if FEATURE_COMINTEROP
- // Separate type so a .cctor is not created for Enviroment which then would be triggered during startup
- private static class WinRT
- {
- // Cache the value in readonly static that can be optimized out by the JIT
- public static readonly bool IsSupported = WinRTSupported() != Interop.BOOL.FALSE;
- }
-
- // Does the current version of Windows have Windows Runtime suppport?
- internal static bool IsWinRTSupported => WinRT.IsSupported;
-
- [DllImport(RuntimeHelpers.QCall, CharSet = CharSet.Unicode)]
- private static extern Interop.BOOL WinRTSupported();
-#endif // FEATURE_COMINTEROP
}
}
diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Exception.CoreCLR.cs b/src/coreclr/src/System.Private.CoreLib/src/System/Exception.CoreCLR.cs
index 903760a6109915..165811f913f1a5 100644
--- a/src/coreclr/src/System.Private.CoreLib/src/System/Exception.CoreCLR.cs
+++ b/src/coreclr/src/System.Private.CoreLib/src/System/Exception.CoreCLR.cs
@@ -56,73 +56,6 @@ private IDictionary CreateDataContainer()
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern bool IsImmutableAgileException(Exception e);
-#if FEATURE_COMINTEROP
- //
- // Exception requires anything to be added into Data dictionary is serializable
- // This wrapper is made serializable to satisfy this requirement but does NOT serialize
- // the object and simply ignores it during serialization, because we only need
- // the exception instance in the app to hold the error object alive.
- // Once the exception is serialized to debugger, debugger only needs the error reference string
- //
- [Serializable]
- internal class __RestrictedErrorObject
- {
- // Hold the error object instance but don't serialize/deserialize it
- [NonSerialized]
- private readonly object _realErrorObject;
-
- internal __RestrictedErrorObject(object errorObject)
- {
- _realErrorObject = errorObject;
- }
-
- public object RealErrorObject
- {
- get
- {
- return _realErrorObject;
- }
- }
- }
-
- internal void AddExceptionDataForRestrictedErrorInfo(
- string restrictedError,
- string restrictedErrorReference,
- string restrictedCapabilitySid,
- object? restrictedErrorObject,
- bool hasrestrictedLanguageErrorObject = false)
- {
- IDictionary dict = Data;
- if (dict != null)
- {
- dict.Add("RestrictedDescription", restrictedError);
- dict.Add("RestrictedErrorReference", restrictedErrorReference);
- dict.Add("RestrictedCapabilitySid", restrictedCapabilitySid);
-
- // Keep the error object alive so that user could retrieve error information
- // using Data["RestrictedErrorReference"]
- dict.Add("__RestrictedErrorObject", restrictedErrorObject == null ? null : new __RestrictedErrorObject(restrictedErrorObject));
- dict.Add("__HasRestrictedLanguageErrorObject", hasrestrictedLanguageErrorObject);
- }
- }
-
- internal bool TryGetRestrictedLanguageErrorObject(out object? restrictedErrorObject)
- {
- restrictedErrorObject = null;
- if (Data != null && Data.Contains("__HasRestrictedLanguageErrorObject"))
- {
- if (Data.Contains("__RestrictedErrorObject"))
- {
- if (Data["__RestrictedErrorObject"] is __RestrictedErrorObject restrictedObject)
- restrictedErrorObject = restrictedObject.RealErrorObject;
- }
- return (bool)Data["__HasRestrictedLanguageErrorObject"]!;
- }
-
- return false;
- }
-#endif // FEATURE_COMINTEROP
-
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern IRuntimeMethodInfo GetMethodFromStackTrace(object stackTrace);
diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs b/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs
index e9b8b3df601b54..f3454c368dd369 100644
--- a/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs
+++ b/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs
@@ -602,10 +602,6 @@ public static int FinalReleaseComObject(object o)
{
throw new ArgumentException(SR.Argument_ObjNotComObject, nameof(obj));
}
- if (obj.GetType().IsWindowsRuntimeObject)
- {
- throw new ArgumentException(SR.Argument_ObjIsWinRTObject, nameof(obj));
- }
// Retrieve the data from the __ComObject.
return co.GetData(key);
@@ -631,10 +627,6 @@ public static bool SetComObjectData(object obj, object key, object? data)
{
throw new ArgumentException(SR.Argument_ObjNotComObject, nameof(obj));
}
- if (obj.GetType().IsWindowsRuntimeObject)
- {
- throw new ArgumentException(SR.Argument_ObjIsWinRTObject, nameof(obj));
- }
// Retrieve the data from the __ComObject.
return co.SetData(key, data);
@@ -659,10 +651,6 @@ public static bool SetComObjectData(object obj, object key, object? data)
{
throw new ArgumentException(SR.Argument_NeedNonGenericType, nameof(t));
}
- if (t.IsWindowsRuntimeObject)
- {
- throw new ArgumentException(SR.Argument_TypeIsWinRTType, nameof(t));
- }
if (o is null)
{
@@ -673,10 +661,6 @@ public static bool SetComObjectData(object obj, object key, object? data)
{
throw new ArgumentException(SR.Argument_ObjNotComObject, nameof(o));
}
- if (o.GetType().IsWindowsRuntimeObject)
- {
- throw new ArgumentException(SR.Argument_ObjIsWinRTObject, nameof(o));
- }
// Check to see if we have nothing to do.
if (o.GetType() == t)
diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/BindableVectorToCollectionAdapter.cs b/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/BindableVectorToCollectionAdapter.cs
deleted file mode 100644
index f21bd539e985b3..00000000000000
--- a/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/BindableVectorToCollectionAdapter.cs
+++ /dev/null
@@ -1,92 +0,0 @@
-// 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 Internal.Runtime.CompilerServices;
-
-namespace System.Runtime.InteropServices.WindowsRuntime
-{
- // This is a set of stub methods implementing the support for the ICollection interface on WinRT
- // objects that support IBindableVector. Used by the interop mashaling infrastructure.
- //
- // The methods on this class must be written VERY carefully to avoid introducing security holes.
- // That's because they are invoked with special "this"! The "this" object
- // for all of these methods are not BindableVectorToCollectionAdapter objects. Rather, they are
- // of type IBindableVector. No actual BindableVectorToCollectionAdapter object is ever instantiated.
- // Thus, you will see a lot of expressions that cast "this" to "IBindableVector".
- internal sealed class BindableVectorToCollectionAdapter
- {
- private BindableVectorToCollectionAdapter()
- {
- Debug.Fail("This class is never instantiated");
- }
-
- // int Count { get }
- internal int Count()
- {
- IBindableVector _this = Unsafe.As(this);
- uint size = _this.Size;
- if (((uint)int.MaxValue) < size)
- {
- throw new InvalidOperationException(SR.InvalidOperation_CollectionBackingListTooLarge);
- }
-
- return (int)size;
- }
-
- // bool IsSynchronized { get }
- internal bool IsSynchronized()
- {
- return false;
- }
-
- // object SyncRoot { get }
- internal object SyncRoot()
- {
- return this;
- }
-
- // void CopyTo(Array array, int index)
- internal void CopyTo(Array array, int arrayIndex)
- {
- if (array == null)
- throw new ArgumentNullException(nameof(array));
-
- // ICollection expects the destination array to be single-dimensional.
- if (array.Rank != 1)
- throw new ArgumentException(SR.Arg_RankMultiDimNotSupported);
-
- int destLB = array.GetLowerBound(0);
-
- int srcLen = Count();
- int destLen = array.GetLength(0);
-
- if (arrayIndex < destLB)
- throw new ArgumentOutOfRangeException(nameof(arrayIndex));
-
- // Does the dimension in question have sufficient space to copy the expected number of entries?
- // We perform this check before valid index check to ensure the exception message is in sync with
- // the following snippet that uses regular framework code:
- //
- // ArrayList list = new ArrayList();
- // list.Add(1);
- // Array items = Array.CreateInstance(typeof(object), new int[] { 1 }, new int[] { -1 });
- // list.CopyTo(items, 0);
-
- if (srcLen > (destLen - (arrayIndex - destLB)))
- throw new ArgumentException(SR.Argument_InsufficientSpaceToCopyCollection);
-
- if (arrayIndex - destLB > destLen)
- throw new ArgumentException(SR.Argument_IndexOutOfArrayBounds);
-
- // We need to verify the index as we;
- IBindableVector _this = Unsafe.As(this);
-
- for (uint i = 0; i < srcLen; i++)
- {
- array.SetValue(_this.GetAt(i), i + arrayIndex);
- }
- }
- }
-}
diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/BindableVectorToListAdapter.cs b/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/BindableVectorToListAdapter.cs
deleted file mode 100644
index 737dd90ef3977d..00000000000000
--- a/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/BindableVectorToListAdapter.cs
+++ /dev/null
@@ -1,217 +0,0 @@
-// 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 Internal.Runtime.CompilerServices;
-
-namespace System.Runtime.InteropServices.WindowsRuntime
-{
- // This is a set of stub methods implementing the support for the IList interface on WinRT
- // objects that support IBindableVector. Used by the interop mashaling infrastructure.
- //
- // The methods on this class must be written VERY carefully to avoid introducing security holes.
- // That's because they are invoked with special "this"! The "this" object
- // for all of these methods are not BindableVectorToListAdapter objects. Rather, they are
- // of type IBindableVector. No actual BindableVectorToListAdapter object is ever instantiated.
- // Thus, you will see a lot of expressions that cast "this" to "IBindableVector".
- internal sealed class BindableVectorToListAdapter
- {
- private BindableVectorToListAdapter()
- {
- Debug.Fail("This class is never instantiated");
- }
-
- // object this[int index] { get }
- internal object? Indexer_Get(int index)
- {
- if (index < 0)
- throw new ArgumentOutOfRangeException(nameof(index));
-
- IBindableVector _this = Unsafe.As(this);
- return GetAt(_this, (uint)index);
- }
-
- // object this[int index] { set }
- internal void Indexer_Set(int index, object value)
- {
- if (index < 0)
- throw new ArgumentOutOfRangeException(nameof(index));
-
- IBindableVector _this = Unsafe.As(this);
- SetAt(_this, (uint)index, value);
- }
-
- // int Add(object value)
- internal int Add(object value)
- {
- IBindableVector _this = Unsafe.As(this);
- _this.Append(value);
-
- uint size = _this.Size;
- if (((uint)int.MaxValue) < size)
- {
- throw new InvalidOperationException(SR.InvalidOperation_CollectionBackingListTooLarge);
- }
-
- return (int)(size - 1);
- }
-
- // bool Contains(object item)
- internal bool Contains(object item)
- {
- IBindableVector _this = Unsafe.As(this);
-
- return _this.IndexOf(item, out _);
- }
-
- // void Clear()
- internal void Clear()
- {
- IBindableVector _this = Unsafe.As(this);
- _this.Clear();
- }
-
- // bool IsFixedSize { get }
- internal bool IsFixedSize()
- {
- return false;
- }
-
- // bool IsReadOnly { get }
- internal bool IsReadOnly()
- {
- return false;
- }
-
- // int IndexOf(object item)
- internal int IndexOf(object item)
- {
- IBindableVector _this = Unsafe.As(this);
-
- bool exists = _this.IndexOf(item, out uint index);
-
- if (!exists)
- return -1;
-
- if (((uint)int.MaxValue) < index)
- {
- throw new InvalidOperationException(SR.InvalidOperation_CollectionBackingListTooLarge);
- }
-
- return (int)index;
- }
-
- // void Insert(int index, object item)
- internal void Insert(int index, object item)
- {
- if (index < 0)
- throw new ArgumentOutOfRangeException(nameof(index));
-
- IBindableVector _this = Unsafe.As(this);
- InsertAtHelper(_this, (uint)index, item);
- }
-
- // bool Remove(object item)
- internal void Remove(object item)
- {
- IBindableVector _this = Unsafe.As(this);
-
- bool exists = _this.IndexOf(item, out uint index);
-
- if (exists)
- {
- if (((uint)int.MaxValue) < index)
- {
- throw new InvalidOperationException(SR.InvalidOperation_CollectionBackingListTooLarge);
- }
-
- RemoveAtHelper(_this, index);
- }
- }
-
- // void RemoveAt(int index)
- internal void RemoveAt(int index)
- {
- if (index < 0)
- throw new ArgumentOutOfRangeException(nameof(index));
-
- IBindableVector _this = Unsafe.As(this);
- RemoveAtHelper(_this, (uint)index);
- }
-
- // Helpers:
-
- private static object? GetAt(IBindableVector _this, uint index)
- {
- try
- {
- return _this.GetAt(index);
-
- // We delegate bounds checking to the underlying collection and if it detected a fault,
- // we translate it to the right exception:
- }
- catch (Exception ex)
- {
- if (HResults.E_BOUNDS == ex.HResult)
- throw new ArgumentOutOfRangeException(nameof(index));
-
- throw;
- }
- }
-
- private static void SetAt(IBindableVector _this, uint index, object value)
- {
- try
- {
- _this.SetAt(index, value);
-
- // We delegate bounds checking to the underlying collection and if it detected a fault,
- // we translate it to the right exception:
- }
- catch (Exception ex)
- {
- if (HResults.E_BOUNDS == ex.HResult)
- throw new ArgumentOutOfRangeException(nameof(index));
-
- throw;
- }
- }
-
- private static void InsertAtHelper(IBindableVector _this, uint index, object item)
- {
- try
- {
- _this.InsertAt(index, item);
-
- // We delegate bounds checking to the underlying collection and if it detected a fault,
- // we translate it to the right exception:
- }
- catch (Exception ex)
- {
- if (HResults.E_BOUNDS == ex.HResult)
- throw new ArgumentOutOfRangeException(nameof(index));
-
- throw;
- }
- }
-
- private static void RemoveAtHelper(IBindableVector _this, uint index)
- {
- try
- {
- _this.RemoveAt(index);
-
- // We delegate bounds checking to the underlying collection and if it detected a fault,
- // we translate it to the right exception:
- }
- catch (Exception ex)
- {
- if (HResults.E_BOUNDS == ex.HResult)
- throw new ArgumentOutOfRangeException(nameof(index));
-
- throw;
- }
- }
- }
-}
diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIKeyValuePairImpl.cs b/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIKeyValuePairImpl.cs
deleted file mode 100644
index dee36577c77ac5..00000000000000
--- a/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIKeyValuePairImpl.cs
+++ /dev/null
@@ -1,54 +0,0 @@
-// 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.Collections.Generic;
-using System.Diagnostics;
-
-namespace System.Runtime.InteropServices.WindowsRuntime
-{
- // Provides access to a System.Collections.Generic.KeyValuePair via the IKeyValuePair WinRT interface.
- internal sealed class CLRIKeyValuePairImpl : IKeyValuePair,
- IGetProxyTarget
- {
- private readonly KeyValuePair _pair;
-
- public CLRIKeyValuePairImpl([In] ref KeyValuePair pair)
- {
- _pair = pair;
- }
-
- // IKeyValuePair implementation
- public K Key => _pair.Key;
-
- public V Value => _pair.Value;
-
- // Called from the VM to wrap a boxed KeyValuePair with a CLRIKeyValuePairImpl.
- internal static object BoxHelper(object pair)
- {
- Debug.Assert(pair != null);
-
- KeyValuePair unboxedPair = (KeyValuePair)pair;
- return new CLRIKeyValuePairImpl(ref unboxedPair);
- }
-
- // Called from the VM to get a boxed KeyValuePair out of a CLRIKeyValuePairImpl.
- internal static object UnboxHelper(object wrapper)
- {
- Debug.Assert(wrapper != null);
-
- CLRIKeyValuePairImpl reference = (CLRIKeyValuePairImpl)wrapper;
- return reference._pair;
- }
-
- public override string ToString()
- {
- return _pair.ToString();
- }
-
- object IGetProxyTarget.GetTarget()
- {
- return _pair;
- }
- }
-}
diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIPropertyValueImpl.cs b/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIPropertyValueImpl.cs
deleted file mode 100644
index bec5ac79efe4bf..00000000000000
--- a/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIPropertyValueImpl.cs
+++ /dev/null
@@ -1,517 +0,0 @@
-// 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.Runtime.CompilerServices;
-
-using Internal.Runtime.CompilerServices;
-
-namespace System.Runtime.InteropServices.WindowsRuntime
-{
- internal class CLRIPropertyValueImpl : IPropertyValue
- {
- private readonly PropertyType _type;
- private readonly object _data;
-
- // Numeric scalar types which participate in coersion
- private static volatile Tuple[]? s_numericScalarTypes;
-
- internal CLRIPropertyValueImpl(PropertyType type, object data)
- {
- _type = type;
- _data = data;
- }
-
- private static Tuple[] NumericScalarTypes
- {
- get
- {
- if (s_numericScalarTypes == null)
- {
- Tuple[] numericScalarTypes = new Tuple[] {
- new Tuple(typeof(byte), PropertyType.UInt8),
- new Tuple(typeof(short), PropertyType.Int16),
- new Tuple(typeof(ushort), PropertyType.UInt16),
- new Tuple(typeof(int), PropertyType.Int32),
- new Tuple(typeof(uint), PropertyType.UInt32),
- new Tuple(typeof(long), PropertyType.Int64),
- new Tuple(typeof(ulong), PropertyType.UInt64),
- new Tuple(typeof(float), PropertyType.Single),
- new Tuple(typeof(double), PropertyType.Double)
- };
-
- s_numericScalarTypes = numericScalarTypes;
- }
-
- return s_numericScalarTypes;
- }
- }
-
- public PropertyType Type => _type;
-
- public bool IsNumericScalar => IsNumericScalarImpl(_type, _data);
-
- public override string? ToString()
- {
- if (_data != null)
- {
- return _data.ToString();
- }
- else
- {
- return base.ToString();
- }
- }
-
- public byte GetUInt8()
- {
- return CoerceScalarValue(PropertyType.UInt8);
- }
-
- public short GetInt16()
- {
- return CoerceScalarValue(PropertyType.Int16);
- }
-
- public ushort GetUInt16()
- {
- return CoerceScalarValue(PropertyType.UInt16);
- }
-
- public int GetInt32()
- {
- return CoerceScalarValue(PropertyType.Int32);
- }
-
- public uint GetUInt32()
- {
- return CoerceScalarValue(PropertyType.UInt32);
- }
-
- public long GetInt64()
- {
- return CoerceScalarValue(PropertyType.Int64);
- }
-
- public ulong GetUInt64()
- {
- return CoerceScalarValue(PropertyType.UInt64);
- }
-
- public float GetSingle()
- {
- return CoerceScalarValue(PropertyType.Single);
- }
-
- public double GetDouble()
- {
- return CoerceScalarValue(PropertyType.Double);
- }
-
- public char GetChar16()
- {
- if (this.Type != PropertyType.Char16)
- throw new InvalidCastException(SR.Format(SR.InvalidCast_WinRTIPropertyValueElement, this.Type, "Char16"), HResults.TYPE_E_TYPEMISMATCH);
- return (char)_data;
- }
-
- public bool GetBoolean()
- {
- if (this.Type != PropertyType.Boolean)
- throw new InvalidCastException(SR.Format(SR.InvalidCast_WinRTIPropertyValueElement, this.Type, "Boolean"), HResults.TYPE_E_TYPEMISMATCH);
- return (bool)_data;
- }
-
- public string GetString()
- {
- return CoerceScalarValue(PropertyType.String);
- }
-
-
- public Guid GetGuid()
- {
- return CoerceScalarValue(PropertyType.Guid);
- }
-
-
- public DateTimeOffset GetDateTime()
- {
- if (this.Type != PropertyType.DateTime)
- throw new InvalidCastException(SR.Format(SR.InvalidCast_WinRTIPropertyValueElement, this.Type, "DateTime"), HResults.TYPE_E_TYPEMISMATCH);
- return (DateTimeOffset)_data;
- }
-
- public TimeSpan GetTimeSpan()
- {
- if (this.Type != PropertyType.TimeSpan)
- throw new InvalidCastException(SR.Format(SR.InvalidCast_WinRTIPropertyValueElement, this.Type, "TimeSpan"), HResults.TYPE_E_TYPEMISMATCH);
- return (TimeSpan)_data;
- }
-
- public Point GetPoint()
- {
- if (this.Type != PropertyType.Point)
- throw new InvalidCastException(SR.Format(SR.InvalidCast_WinRTIPropertyValueElement, this.Type, "Point"), HResults.TYPE_E_TYPEMISMATCH);
-
- return Unbox(IReferenceFactory.s_pointType);
- }
-
- public Size GetSize()
- {
- if (this.Type != PropertyType.Size)
- throw new InvalidCastException(SR.Format(SR.InvalidCast_WinRTIPropertyValueElement, this.Type, "Size"), HResults.TYPE_E_TYPEMISMATCH);
-
- return Unbox(IReferenceFactory.s_sizeType);
- }
-
- public Rect GetRect()
- {
- if (this.Type != PropertyType.Rect)
- throw new InvalidCastException(SR.Format(SR.InvalidCast_WinRTIPropertyValueElement, this.Type, "Rect"), HResults.TYPE_E_TYPEMISMATCH);
-
- return Unbox(IReferenceFactory.s_rectType);
- }
-
- public byte[] GetUInt8Array()
- {
- return CoerceArrayValue(PropertyType.UInt8Array);
- }
-
- public short[] GetInt16Array()
- {
- return CoerceArrayValue(PropertyType.Int16Array);
- }
-
- public ushort[] GetUInt16Array()
- {
- return CoerceArrayValue(PropertyType.UInt16Array);
- }
-
- public int[] GetInt32Array()
- {
- return CoerceArrayValue(PropertyType.Int32Array);
- }
-
- public uint[] GetUInt32Array()
- {
- return CoerceArrayValue(PropertyType.UInt32Array);
- }
-
- public long[] GetInt64Array()
- {
- return CoerceArrayValue(PropertyType.Int64Array);
- }
-
- public ulong[] GetUInt64Array()
- {
- return CoerceArrayValue(PropertyType.UInt64Array);
- }
-
- public float[] GetSingleArray()
- {
- return CoerceArrayValue(PropertyType.SingleArray);
- }
-
- public double[] GetDoubleArray()
- {
- return CoerceArrayValue(PropertyType.DoubleArray);
- }
-
- public char[] GetChar16Array()
- {
- if (this.Type != PropertyType.Char16Array)
- throw new InvalidCastException(SR.Format(SR.InvalidCast_WinRTIPropertyValueElement, this.Type, "Char16[]"), HResults.TYPE_E_TYPEMISMATCH);
- return (char[])_data;
- }
-
- public bool[] GetBooleanArray()
- {
- if (this.Type != PropertyType.BooleanArray)
- throw new InvalidCastException(SR.Format(SR.InvalidCast_WinRTIPropertyValueElement, this.Type, "Boolean[]"), HResults.TYPE_E_TYPEMISMATCH);
- return (bool[])_data;
- }
-
- public string[] GetStringArray()
- {
- return CoerceArrayValue(PropertyType.StringArray);
- }
-
- public object[] GetInspectableArray()
- {
- if (this.Type != PropertyType.InspectableArray)
- throw new InvalidCastException(SR.Format(SR.InvalidCast_WinRTIPropertyValueElement, this.Type, "Inspectable[]"), HResults.TYPE_E_TYPEMISMATCH);
- return (object[])_data;
- }
-
- public Guid[] GetGuidArray()
- {
- return CoerceArrayValue(PropertyType.GuidArray);
- }
-
- public DateTimeOffset[] GetDateTimeArray()
- {
- if (this.Type != PropertyType.DateTimeArray)
- throw new InvalidCastException(SR.Format(SR.InvalidCast_WinRTIPropertyValueElement, this.Type, "DateTimeOffset[]"), HResults.TYPE_E_TYPEMISMATCH);
- return (DateTimeOffset[])_data;
- }
-
- public TimeSpan[] GetTimeSpanArray()
- {
- if (this.Type != PropertyType.TimeSpanArray)
- throw new InvalidCastException(SR.Format(SR.InvalidCast_WinRTIPropertyValueElement, this.Type, "TimeSpan[]"), HResults.TYPE_E_TYPEMISMATCH);
- return (TimeSpan[])_data;
- }
-
- public Point[] GetPointArray()
- {
- if (this.Type != PropertyType.PointArray)
- throw new InvalidCastException(SR.Format(SR.InvalidCast_WinRTIPropertyValueElement, this.Type, "Point[]"), HResults.TYPE_E_TYPEMISMATCH);
-
- return UnboxArray(IReferenceFactory.s_pointType);
- }
-
- public Size[] GetSizeArray()
- {
- if (this.Type != PropertyType.SizeArray)
- throw new InvalidCastException(SR.Format(SR.InvalidCast_WinRTIPropertyValueElement, this.Type, "Size[]"), HResults.TYPE_E_TYPEMISMATCH);
-
-
- return UnboxArray(IReferenceFactory.s_sizeType);
- }
-
- public Rect[] GetRectArray()
- {
- if (this.Type != PropertyType.RectArray)
- throw new InvalidCastException(SR.Format(SR.InvalidCast_WinRTIPropertyValueElement, this.Type, "Rect[]"), HResults.TYPE_E_TYPEMISMATCH);
-
- return UnboxArray(IReferenceFactory.s_rectType);
- }
-
- private T[] CoerceArrayValue(PropertyType unboxType)
- {
- // If we contain the type being looked for directly, then take the fast-path
- if (Type == unboxType)
- {
- return (T[])_data;
- }
-
- // Make sure we have an array to begin with
- if (!(_data is Array dataArray))
- {
- throw new InvalidCastException(SR.Format(SR.InvalidCast_WinRTIPropertyValueElement, this.Type, typeof(T).MakeArrayType().Name), HResults.TYPE_E_TYPEMISMATCH);
- }
-
- // Array types are 1024 larger than their equivilent scalar counterpart
- Debug.Assert((int)Type > 1024, "Unexpected array PropertyType value");
- PropertyType scalarType = Type - 1024;
-
- // If we do not have the correct array type, then we need to convert the array element-by-element
- // to a new array of the requested type
- T[] coercedArray = new T[dataArray.Length];
- for (int i = 0; i < dataArray.Length; ++i)
- {
- try
- {
- coercedArray[i] = CoerceScalarValue(scalarType, dataArray.GetValue(i)!);
- }
- catch (InvalidCastException elementCastException)
- {
- Exception e = new InvalidCastException(SR.Format(SR.InvalidCast_WinRTIPropertyValueArrayCoersion, this.Type, typeof(T).MakeArrayType().Name, i, elementCastException.Message), elementCastException);
- e.HResult = elementCastException.HResult;
- throw e;
- }
- }
-
- return coercedArray;
- }
-
- private T CoerceScalarValue(PropertyType unboxType)
- {
- // If we are just a boxed version of the requested type, then take the fast path out
- if (Type == unboxType)
- {
- return (T)_data;
- }
-
- return CoerceScalarValue(Type, _data);
- }
-
- private static T CoerceScalarValue(PropertyType type, object value)
- {
- // If the property type is neither one of the coercable numeric types nor IInspectable, we
- // should not attempt coersion, even if the underlying value is technically convertable
- if (!IsCoercable(type, value) && type != PropertyType.Inspectable)
- {
- throw new InvalidCastException(SR.Format(SR.InvalidCast_WinRTIPropertyValueElement, type, typeof(T).Name), HResults.TYPE_E_TYPEMISMATCH);
- }
-
- try
- {
- // Try to coerce:
- // * String <--> Guid
- // * Numeric scalars
- if (type == PropertyType.String && typeof(T) == typeof(Guid))
- {
- return (T)(object)Guid.Parse((string)value);
- }
- else if (type == PropertyType.Guid && typeof(T) == typeof(string))
- {
- return (T)(object)((Guid)value).ToString("D", System.Globalization.CultureInfo.InvariantCulture);
- }
- else
- {
- // Iterate over the numeric scalars, to see if we have a match for one of the known conversions
- foreach (Tuple numericScalar in NumericScalarTypes)
- {
- if (numericScalar.Item1 == typeof(T))
- {
- return (T)Convert.ChangeType(value, typeof(T), System.Globalization.CultureInfo.InvariantCulture)!;
- }
- }
- }
- }
- catch (FormatException)
- {
- throw new InvalidCastException(SR.Format(SR.InvalidCast_WinRTIPropertyValueElement, type, typeof(T).Name), HResults.TYPE_E_TYPEMISMATCH);
- }
- catch (InvalidCastException)
- {
- throw new InvalidCastException(SR.Format(SR.InvalidCast_WinRTIPropertyValueElement, type, typeof(T).Name), HResults.TYPE_E_TYPEMISMATCH);
- }
- catch (OverflowException)
- {
- throw new InvalidCastException(SR.Format(SR.InvalidCast_WinRTIPropertyValueCoersion, type, value, typeof(T).Name), HResults.DISP_E_OVERFLOW);
- }
-
- // If the property type is IInspectable, and we have a nested IPropertyValue, then we need
- // to pass along the request to coerce the value.
- if (type == PropertyType.Inspectable && value is IPropertyValue ipv)
- {
- if (typeof(T) == typeof(byte))
- {
- return (T)(object)ipv.GetUInt8();
- }
- else if (typeof(T) == typeof(short))
- {
- return (T)(object)ipv.GetInt16();
- }
- else if (typeof(T) == typeof(ushort))
- {
- return (T)(object)ipv.GetUInt16();
- }
- else if (typeof(T) == typeof(int))
- {
- return (T)(object)ipv.GetUInt32();
- }
- else if (typeof(T) == typeof(uint))
- {
- return (T)(object)ipv.GetUInt32();
- }
- else if (typeof(T) == typeof(long))
- {
- return (T)(object)ipv.GetInt64();
- }
- else if (typeof(T) == typeof(ulong))
- {
- return (T)(object)ipv.GetUInt64();
- }
- else if (typeof(T) == typeof(float))
- {
- return (T)(object)ipv.GetSingle();
- }
- else if (typeof(T) == typeof(double))
- {
- return (T)(object)ipv.GetDouble();
- }
- else
- {
- Debug.Fail("T in coersion function wasn't understood as a type that can be coerced - make sure that CoerceScalarValue and NumericScalarTypes are in sync");
- }
- }
-
- // Otherwise, this is an invalid coersion
- throw new InvalidCastException(SR.Format(SR.InvalidCast_WinRTIPropertyValueElement, type, typeof(T).Name), HResults.TYPE_E_TYPEMISMATCH);
- }
-
- private static bool IsCoercable(PropertyType type, object data)
- {
- // String <--> Guid is allowed
- if (type == PropertyType.Guid || type == PropertyType.String)
- {
- return true;
- }
-
- // All numeric scalars can also be coerced
- return IsNumericScalarImpl(type, data);
- }
-
- private static bool IsNumericScalarImpl(PropertyType type, object data)
- {
- if (data.GetType().IsEnum)
- {
- return true;
- }
-
- foreach (Tuple numericScalar in NumericScalarTypes)
- {
- if (numericScalar.Item2 == type)
- {
- return true;
- }
- }
-
- return false;
- }
-
- // Unbox the data stored in the property value to a structurally equivalent type
- private unsafe T Unbox(Type expectedBoxedType) where T : struct
- {
- Debug.Assert(expectedBoxedType != null);
- Debug.Assert(Marshal.SizeOf(expectedBoxedType) == Marshal.SizeOf(typeof(T)));
-
- if (_data.GetType() != expectedBoxedType)
- {
- throw new InvalidCastException(SR.Format(SR.InvalidCast_WinRTIPropertyValueElement, _data.GetType(), expectedBoxedType.Name), HResults.TYPE_E_TYPEMISMATCH);
- }
-
- T unboxed = default;
-
- fixed (byte* pData = &_data.GetRawData())
- {
- byte* pUnboxed = (byte*)Unsafe.AsPointer(ref unboxed);
- Buffer.Memcpy(pUnboxed, pData, Marshal.SizeOf(unboxed));
- }
-
- return unboxed;
- }
-
- // Convert the array stored in the property value to a structurally equivilent array type
- private unsafe T[] UnboxArray(Type expectedArrayElementType) where T : struct
- {
- Debug.Assert(expectedArrayElementType != null);
- Debug.Assert(Marshal.SizeOf(expectedArrayElementType) == Marshal.SizeOf(typeof(T)));
-
- if (!(_data is Array dataArray) || _data.GetType().GetElementType() != expectedArrayElementType)
- {
- throw new InvalidCastException(SR.Format(SR.InvalidCast_WinRTIPropertyValueElement, _data.GetType(), expectedArrayElementType.MakeArrayType().Name), HResults.TYPE_E_TYPEMISMATCH);
- }
-
- T[] converted = new T[dataArray.Length];
-
- if (converted.Length > 0)
- {
- fixed (byte* dataPin = &dataArray.GetRawData())
- fixed (byte* convertedPin = &converted.GetRawData())
- {
- byte* pData = (byte*)Marshal.UnsafeAddrOfPinnedArrayElement(dataArray, 0);
- byte* pConverted = (byte*)Marshal.UnsafeAddrOfPinnedArrayElement(converted, 0);
-
- Buffer.Memcpy(pConverted, pData, checked(Marshal.SizeOf(typeof(T)) * converted.Length));
- }
- }
-
- return converted;
- }
- }
-}
diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIReferenceImpl.cs b/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIReferenceImpl.cs
deleted file mode 100644
index 3a3741c48bc378..00000000000000
--- a/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIReferenceImpl.cs
+++ /dev/null
@@ -1,353 +0,0 @@
-// 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.Collections;
-using System.Diagnostics;
-
-namespace System.Runtime.InteropServices.WindowsRuntime
-{
- internal sealed class CLRIReferenceImpl : CLRIPropertyValueImpl, IReference, IGetProxyTarget
- {
- private readonly T _value;
-
- public CLRIReferenceImpl(PropertyType type, T obj)
- : base(type, obj!)
- {
- Debug.Assert(obj != null, "Must not be null");
- _value = obj;
- }
-
- public T Value => _value;
-
- public override string? ToString()
- {
- if (_value != null)
- {
- return _value.ToString();
- }
- else
- {
- return base.ToString();
- }
- }
-
- object IGetProxyTarget.GetTarget()
- {
- return _value!;
- }
-
- // We have T in an IReference. Need to QI for IReference with the appropriate GUID, call
- // the get_Value property, allocate an appropriately-sized managed object, marshal the native object
- // to the managed object, and free the native method. Also we want the return value boxed (aka normal value type boxing).
- //
- // This method is called by VM.
- internal static object UnboxHelper(object wrapper)
- {
- Debug.Assert(wrapper != null);
- IReference reference = (IReference)wrapper;
- Debug.Assert(reference != null, "CLRIReferenceImpl::UnboxHelper - QI'ed for IReference<" + typeof(T) + ">, but that failed.");
- return reference.Value!;
- }
- }
-
- // T can be any WinRT-compatible type
- internal sealed class CLRIReferenceArrayImpl : CLRIPropertyValueImpl,
- IGetProxyTarget,
- IReferenceArray,
- IList // Jupiter data binding needs IList/IEnumerable
- {
- private readonly T[] _value;
- private readonly IList _list;
-
- public CLRIReferenceArrayImpl(PropertyType type, T[] obj)
- : base(type, obj)
- {
- Debug.Assert(obj != null, "Must not be null");
-
- _value = obj;
-
- _list = (IList)_value;
- }
-
- public T[] Value => _value;
-
- public override string? ToString()
- {
- if (_value != null)
- {
- return _value.ToString();
- }
- else
- {
- return base.ToString();
- }
- }
-
- //
- // IEnumerable methods. Used by data-binding in Jupiter when you try to data bind
- // against a managed array
- //
- IEnumerator IEnumerable.GetEnumerator()
- {
- return ((IEnumerable)_value).GetEnumerator();
- }
-
- //
- // IList & ICollection methods.
- // This enables two-way data binding and index access in Jupiter
- //
- object? IList.this[int index]
- {
- get => _list[index];
- set => _list[index] = value;
- }
-
- int IList.Add(object? value)
- {
- return _list.Add(value);
- }
-
- bool IList.Contains(object? value)
- {
- return _list.Contains(value);
- }
-
- void IList.Clear()
- {
- _list.Clear();
- }
-
- bool IList.IsReadOnly => _list.IsReadOnly;
-
- bool IList.IsFixedSize => _list.IsFixedSize;
-
- int IList.IndexOf(object? value)
- {
- return _list.IndexOf(value);
- }
-
- void IList.Insert(int index, object? value)
- {
- _list.Insert(index, value);
- }
-
- void IList.Remove(object? value)
- {
- _list.Remove(value);
- }
-
- void IList.RemoveAt(int index)
- {
- _list.RemoveAt(index);
- }
-
- void ICollection.CopyTo(Array array, int index)
- {
- _list.CopyTo(array, index);
- }
-
- int ICollection.Count => _list.Count;
-
- object ICollection.SyncRoot => _list.SyncRoot;
-
- bool ICollection.IsSynchronized => _list.IsSynchronized;
-
- object IGetProxyTarget.GetTarget()
- {
- return (object)_value;
- }
-
- // We have T in an IReferenceArray. Need to QI for IReferenceArray with the appropriate GUID, call
- // the get_Value property, allocate an appropriately-sized managed object, marshal the native object
- // to the managed object, and free the native method.
- //
- // This method is called by VM.
- internal static object UnboxHelper(object wrapper)
- {
- Debug.Assert(wrapper != null);
- IReferenceArray reference = (IReferenceArray)wrapper;
- Debug.Assert(reference != null, "CLRIReferenceArrayImpl::UnboxHelper - QI'ed for IReferenceArray<" + typeof(T) + ">, but that failed.");
- T[] marshaled = reference.Value;
- return marshaled;
- }
- }
-
- // For creating instances of Windows Runtime's IReference and IReferenceArray.
- internal static class IReferenceFactory
- {
- internal static readonly Type s_pointType = Type.GetType("Windows.Foundation.Point, System.Runtime.WindowsRuntime")!;
- internal static readonly Type s_rectType = Type.GetType("Windows.Foundation.Rect, System.Runtime.WindowsRuntime")!;
- internal static readonly Type s_sizeType = Type.GetType("Windows.Foundation.Size, System.Runtime.WindowsRuntime")!;
-
- internal static object CreateIReference(object obj)
- {
- Debug.Assert(obj != null, "Null should not be boxed.");
-
- Type type = obj.GetType();
-
- if (type.IsArray)
- return CreateIReferenceArray((Array)obj);
-
- if (type == typeof(int))
- return new CLRIReferenceImpl(PropertyType.Int32, (int)obj);
- if (type == typeof(string))
- return new CLRIReferenceImpl(PropertyType.String, (string)obj);
- if (type == typeof(byte))
- return new CLRIReferenceImpl(PropertyType.UInt8, (byte)obj);
- if (type == typeof(short))
- return new CLRIReferenceImpl(PropertyType.Int16, (short)obj);
- if (type == typeof(ushort))
- return new CLRIReferenceImpl(PropertyType.UInt16, (ushort)obj);
- if (type == typeof(uint))
- return new CLRIReferenceImpl(PropertyType.UInt32, (uint)obj);
- if (type == typeof(long))
- return new CLRIReferenceImpl(PropertyType.Int64, (long)obj);
- if (type == typeof(ulong))
- return new CLRIReferenceImpl(PropertyType.UInt64, (ulong)obj);
- if (type == typeof(float))
- return new CLRIReferenceImpl(PropertyType.Single, (float)obj);
- if (type == typeof(double))
- return new CLRIReferenceImpl(PropertyType.Double, (double)obj);
- if (type == typeof(char))
- return new CLRIReferenceImpl(PropertyType.Char16, (char)obj);
- if (type == typeof(bool))
- return new CLRIReferenceImpl(PropertyType.Boolean, (bool)obj);
- if (type == typeof(Guid))
- return new CLRIReferenceImpl(PropertyType.Guid, (Guid)obj);
- if (type == typeof(DateTimeOffset))
- return new CLRIReferenceImpl(PropertyType.DateTime, (DateTimeOffset)obj);
- if (type == typeof(TimeSpan))
- return new CLRIReferenceImpl(PropertyType.TimeSpan, (TimeSpan)obj);
- if (type == typeof(object))
- return new CLRIReferenceImpl