CommunityToolkit / Microsoft.Toolkit.Win32

ARCHIVE - This repository contained XAML Islands wrapper controls and tooling for XAML Islands with WinUI 2, see readme for more info about XAML Islands with WinUI 3 and the WindowsAppSDK.
https://aka.ms/windowsappsdk
Other
383 stars 89 forks source link

Cannot load Microsoft.Toolkit.Win32.UI.XamlHost.XamlApplication if Control Flow Guard is enforced #263

Closed sylveon closed 4 years ago

sylveon commented 4 years ago

Steps to Reproduce

Steps to reproduce the behavior:

  1. Create an application enabling Control Flow Guard enforcement by adding the following in the entry point:
    PROCESS_MITIGATION_CONTROL_FLOW_GUARD_POLICY cfg_policy;
    GetProcessMitigationPolicy(GetCurrentProcess(), ProcessControlFlowGuardPolicy, &cfg_policy, sizeof(cfg_policy));
    cfg_policy.StrictMode = true;
    SetProcessMitigationPolicy(ProcessControlFlowGuardPolicy, &cfg_policy, sizeof(cfg_policy));
  2. Try to create an instance of Microsoft.Toolkit.Win32.UI.XamlHost.XamlApplication (or have it implicitly happen by creating an instance of a type which derives from it)
  3. Add the required activatableClass and maxversiontested entries to your app manifest.
  4. Enable Control Flow Guard in Visual Studio project settings
  5. Build and run a release configuration.
  6. See exception get thrown, with the message The specified image file was blocked from loading because it does not enable a feature required by the process: Control Flow Guard.

Expected behavior

An exception doesn't get thrown, and the type gets created correctly.

Environment

NuGet Package(s):
 - Microsoft.Toolkit.Win32.UI.XamlApplication (v6.0.1)
 - Microsoft.VCRTForwarders.140 (v1.0.6)
 - Microsoft.Windows.CppWinRT (v2.0.200508.4)

Windows 10 Build Number:
- [ ] Fall Creators Update (16299)
- [ ] April 2018 Update (17134)
- [ ] October 2018 Update (17763)
- [ ] May 2019 Update (18362)
- [x] Insider Build (build number: 19041)

App min and target version:
- [ ] Fall Creators Update (16299)
- [ ] April 2018 Update (17134)
- [ ] October 2018 Update (17763)
- [x] May 2019 Update (18362)
- [ ] Insider Build (xxxxx)

Device form factor:
- [x] Desktop
- [ ] Xbox
- [ ] Surface Hub
- [ ] IoT

Visual Studio 
- [ ] 2017 (version: )
- [ ] 2019 (version: ) 
- [x] 2019 Preview (version: 16.6.0 Preview 6.0)

Additional context

This code, with the instructions above, suffices to reproduce it.

#include <iostream>
#include <winrt/base.h>
#include <winrt/Microsoft.Toolkit.Win32.UI.XamlHost.h>
#include <winrt/Windows.Foundation.Collections.h>
#include <Windows.h>

int main() try
{
    PROCESS_MITIGATION_CONTROL_FLOW_GUARD_POLICY cfg_policy;
    GetProcessMitigationPolicy(GetCurrentProcess(), ProcessControlFlowGuardPolicy, &cfg_policy, sizeof(cfg_policy));
    cfg_policy.StrictMode = true;
    SetProcessMitigationPolicy(ProcessControlFlowGuardPolicy, &cfg_policy, sizeof(cfg_policy));

    winrt::init_apartment(winrt::apartment_type::single_threaded);
    winrt::Microsoft::Toolkit::Win32::UI::XamlHost::XamlApplication app(winrt::param::vector<winrt::Windows::UI::Xaml::Markup::IXamlMetadataProvider>{});
}
catch (const winrt::hresult_error &err)
{
    std::wcout << err.message().c_str();
}
ghost commented 4 years ago

Hello sylveon, thank you for opening an issue with us!

I have automatically added a "needs triage" label to help get things started. Our team will analyze and investigate the issue, and escalate it to the relevant team if possible. Other community members may also look into the issue and provide feedback 🙌

ghost commented 4 years ago

This issue has been marked as "needs attention 👋" due to no activity for 15 days. Please triage the issue so the fix can be established.

ghost commented 4 years ago

This issue has been marked as "needs attention 👋" due to no activity for 15 days. Please triage the issue so the fix can be established.

ghost commented 4 years ago

This issue has been marked as "needs attention 👋" due to no activity for 15 days. Please triage the issue so the fix can be established.

sylveon commented 4 years ago

Third time's the charm...

ghost commented 4 years ago

This issue has been marked as "needs attention 👋" due to no activity for 15 days. Please triage the issue so the fix can be established.

hansmbakker commented 4 years ago

I have not encountered this issue myself, but would expect that if there is a pull request, at least a moderator would look at it? I see @ocalvo is assigned to the PR, but did not see any other activity? @azchohfi? @marb2000? @michael-hawker?

ghost commented 4 years ago

This issue has been marked as "needs attention 👋" due to no activity for 15 days. Please triage the issue so the fix can be established.

sylveon commented 4 years ago

This repo is clearly not having any attention whatsoever and I managed to remove my dependency on XamlApplication anyways.