C# ProjectionManager.StartProjectingAsync-引发访问被拒绝异常

C# ProjectionManager.StartProjectingAsync-引发访问被拒绝异常,c#,casting,uwp,projection,C#,Casting,Uwp,Projection,ProjectionManager.StartProjectingAsync api正在引发异常。 我需要什么? 我有一个uwp应用程序。单击按钮,我需要选择miracast设备并连接到该设备,然后向其投影新视图(或页面)。 操作系统:Windows 10,版本1709(操作系统版本16299.492) 因此,只有miracast设备才可见 var outputDevices = await DeviceInformation.FindAllAsync(projectorSelectorQuer

ProjectionManager.StartProjectingAsync api正在引发异常。 我需要什么? 我有一个uwp应用程序。单击按钮,我需要选择miracast设备并连接到该设备,然后向其投影新视图(或页面)。 操作系统:Windows 10,版本1709(操作系统版本16299.492)

因此,只有miracast设备才可见

var outputDevices = await DeviceInformation.FindAllAsync(projectorSelectorQuery);
我选择了一个miracast设备并开始投射到它

if (ProjectionViewPageControl == null)
        {
            // First, create a new, blank view
            var thisDispatcher = Window.Current.Dispatcher;
            await CoreApplication.CreateNewView().Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                // ViewLifetimeControl is a wrapper to make sure the view is closed only
                // when the app is done with it
                ProjectionViewPageControl = ViewLifetimeControl.CreateForCurrentView();

                // Assemble some data necessary for the new page
                var initData = new ProjectionViewPageInitializationData();
                initData.MainDispatcher = thisDispatcher;
                initData.ProjectionViewPageControl = ProjectionViewPageControl;
                initData.MainViewId = thisViewId;

                // Display the page in the view. Note that the view will not become visible
                // until "StartProjectingAsync" is called
                var rootFrame = new Frame();

                rootFrame.Navigate(typeof(BlankPage1), initData);
                Window.Current.Content = rootFrame;

                // The call to Window.Current.Activate is required starting in Windos 10.
                // Without it, the view will never appear.
                Window.Current.Activate();
            });
        }

        try
        {
            // Start/StopViewInUse are used to signal that the app is interacting with the
            // view, so it shouldn't be closed yet, even if the user loses access to it
            ProjectionViewPageControl.StartViewInUse();

            // Show the view on a second display that was selected by the user

            await ProjectionManager.StartProjectingAsync(ProjectionViewPageControl.Id, thisViewId, selectedDisplay);
            ProjectionViewPageControl.StopViewInUse();
        }
        //catch(InvalidOperationException)
        catch (Exception exception)
        {

            var msg = new MessageDialog(exception.Message + " Stack: " + exception.StackTrace + " Source: " + exception.Source);
           await msg.ShowAsync();
        }
事实上,它会连接到miracast设备,这意味着我的屏幕会镜像到它,但我的页面不会投影


我注意到您的代码来自官方。如果您直接测试官方代码示例以查看是否仍然得到异常?是的,我得到异常。@Xavier Xie-MSFTIf官方代码示例在您这边不起作用。您的环境可能有一些问题。请尝试使用其他投影应用程序(非UWP应用程序)查看它是否有效。
if (ProjectionViewPageControl == null)
        {
            // First, create a new, blank view
            var thisDispatcher = Window.Current.Dispatcher;
            await CoreApplication.CreateNewView().Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                // ViewLifetimeControl is a wrapper to make sure the view is closed only
                // when the app is done with it
                ProjectionViewPageControl = ViewLifetimeControl.CreateForCurrentView();

                // Assemble some data necessary for the new page
                var initData = new ProjectionViewPageInitializationData();
                initData.MainDispatcher = thisDispatcher;
                initData.ProjectionViewPageControl = ProjectionViewPageControl;
                initData.MainViewId = thisViewId;

                // Display the page in the view. Note that the view will not become visible
                // until "StartProjectingAsync" is called
                var rootFrame = new Frame();

                rootFrame.Navigate(typeof(BlankPage1), initData);
                Window.Current.Content = rootFrame;

                // The call to Window.Current.Activate is required starting in Windos 10.
                // Without it, the view will never appear.
                Window.Current.Activate();
            });
        }

        try
        {
            // Start/StopViewInUse are used to signal that the app is interacting with the
            // view, so it shouldn't be closed yet, even if the user loses access to it
            ProjectionViewPageControl.StartViewInUse();

            // Show the view on a second display that was selected by the user

            await ProjectionManager.StartProjectingAsync(ProjectionViewPageControl.Id, thisViewId, selectedDisplay);
            ProjectionViewPageControl.StopViewInUse();
        }
        //catch(InvalidOperationException)
        catch (Exception exception)
        {

            var msg = new MessageDialog(exception.Message + " Stack: " + exception.StackTrace + " Source: " + exception.Source);
           await msg.ShowAsync();
        }