I have a solution in visual studio containing a Windows Application Packaging Project, a UWP project, and a Console Application project. The UWP app contains a single button that when pressed is supposed to launch the console application as a fulltrust process. Solution Explorer looks like this:
The Windows Application Packaging project is set as the startup project. It's entry point is set to the UWP app. Both the UWP app and the console app are added to the packaging project as references.
Configuration manager looks like this:
The console app is set as a dependency for the UWP app. The dependencies for the UWP app looks like this:
The build order look like this:
Code
Here is the code for the console app:
using System;
using System.Diagnostics;
namespace ShellHost
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
}
}
As I mentioned the UWP app only has one page (MainPage.xaml) and it's code behind looks like this:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.ApplicationModel;
namespace OnScreenDeviceManager
{
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
private async void button_Click(object sender, RoutedEventArgs e)
{
await FullTrustProcessLauncher.LaunchFullTrustProcessForAppAsync("Default");
}
}
}
The manifest for the UWP app is unmodified. The manifest for the Package has been modified to include fulltrust capability, and it contains the necessary extension for the fulltrust process. The xml file looks like this:
<?xml version="1.0" encoding="utf-8"?>
<Package
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10"
IgnorableNamespaces="uap rescap desktop">
<Identity
Name="d3e964dc-9265-4243-b97c-2dacb7c11dac"
Publisher="CN=Dell"
Version="1.0.0.0" />
<Properties>
<DisplayName>Package</DisplayName>
<PublisherDisplayName>Dell</PublisherDisplayName>
<Logo>Images\StoreLogo.png</Logo>
</Properties>
<Dependencies>
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" />
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.14393.0" MaxVersionTested="10.0.14393.0" />
</Dependencies>
<Resources>
<Resource Language="x-generate"/>
</Resources>
<Applications>
<Application Id="App"
Executable="$targetnametoken$.exe"
EntryPoint="$targetentrypoint$">
<uap:VisualElements
DisplayName="Package"
Description="Package"
BackgroundColor="transparent"
Square150x150Logo="Images\Square150x150Logo.png"
Square44x44Logo="Images\Square44x44Logo.png">
<uap:DefaultTile Wide310x150Logo="Images\Wide310x150Logo.png" />
<uap:SplashScreen Image="Images\SplashScreen.png" />
</uap:VisualElements>
<Extensions>
<desktop:Extension Category="windows.fullTrustProcess" Executable="ShellHost\ShellHost.exe">
<desktop:FullTrustProcess>
<desktop:ParameterGroup GroupId="SyncGroup" Parameters="/Sync"/>
<desktop:ParameterGroup GroupId="OtherGroup" Parameters="/Other"/>
<desktop:ParameterGroup GroupId="Default" Parameters=""/>
</desktop:FullTrustProcess>
</desktop:Extension>
</Extensions>
</Application>
</Applications>
<Capabilities>
<Capability Name="internetClient"/>
<rescap:Capability Name="runFullTrust" />
</Capabilities>
</Package>
The package/debug/bin folder where the solution exe resides looks like this:
You can clearly see the console app exe (ShellHost.exe) in the ShellHost folder.
The console app has been tested and works just fine. The UWP app works just fine except when I click the button I get an 'Element not found' exception.
Exception message says:
System.Exception: 'Element not found. (Exception from HRESULT: 0x80070490)'
This exception was originally thrown at this call stack:
[External Code]
OnScreenDeviceManager.MainPage.button_Click(object, Windows.UI.Xaml.RoutedEventArgs) in MainPage.xaml.cs
Can anyone help me solve this? What am I missing?
LaunchFullTrustProcessForAppAsync API means you need to launch the full-trust process with the specified application ID.
I suggest you try to use LaunchFullTrustProcessForCurrentAppAsync(String) API to replace your code.
private async void button_Click(object sender, RoutedEventArgs e)
{
await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync("Default");
}
Related
I am trying to use MSBuild to compile WPF user controls into a library. In a test project I get the results I expected to, however in my active project I have run into nothing but problems.
This being the first time I have used MSBuild I created a test project to figure out how to use it. I added references to Microsoft.Build and Microsoft.Build.Engine, using the code below my program did exactly what I wanted. The library compiled and I was able to load and use the usercontrol as intended.
MSBuild C#
using Microsoft.Build.Evaluation;
using Microsoft.Build.Execution;
namespace MSBuildTest
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void RunButton_Click(object sender, RoutedEventArgs e)
{
string fileName = #"C:\...\MSBuildTest.proj";
ProjectCollection buildEngin = new ProjectCollection();
Dictionary<string, string> GlobalProperty = new Dictionary<string, string>();
GlobalProperty.Add("Configuration", "Release");
GlobalProperty.Add("Platform", "x86");
BuildRequestData BuildRequest = new BuildRequestData(fileName, GlobalProperty, null, new string[] { "Build" }, null);
var buildParameters = new BuildParameters(buildEngin);
BuildResult buildResult = BuildManager.DefaultBuildManager.Build(buildParameters, BuildRequest);
}
}
}
.proj file
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<PropertyGroup>
<OutputType>Library</OutputType>
<OutputPath>someoutputpath</OutputPath>
<Assembly>MSBuildTest.dll</Assembly>
<TargetFramework>net7.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
</PropertyGroup>
<ItemGroup>
<Page Include="C:\...\UserControl1.xaml" />
<Compile Include="C:\...\UserControl1.xaml.cs" >
<DependentUpon>UserControl1.xaml</DependentUpon>
</Compile>
<Reference Include="System" />
<Reference Include="WindowsBase" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System.Xaml" />
</ItemGroup>
<Import Project="$(MsbuildBinPath)\Microsoft.CSharp.targets" />
</Project>
UserControl .xaml
<UserControl x:Class="UserControlTest.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:UserControlTest"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Button Content="Button" Click="Button_Click" />
<TextBlock Grid.Row="1" x:Name="TextBlock1" Background="White" Text="{Binding ElementName=TextBlock2, Path=Text}"/>
<TextBlock Grid.Row="1" Grid.Column="1" Text="Test" Background="White" />
</Grid>
</UserControl>
UserControl .cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace UserControlTest
{
/// <summary>
/// Interaction logic for UserControl1.xaml
/// </summary>
public partial class UserControl1 : System.Windows.Controls.UserControl
{
public UserControl1()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("This worked");
}
}
}
I switched over to my main program to start implementing my new toy. I followed the same steps I did in my test project. I ran the program expecting it to work exactly as the test program had, but I got this exception:
"System.BadImageFormatException: 'Could not load file or assembly
'Microsoft.Build, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a'. Reference assemblies cannot be
loaded for execution. (0x80131058)'" I compared the projects and
found that the test project I started was targeting .NET Framework
4.7.2 while my main project targeted .NET 7.0.
After research I found that with .Net 7.0 I should be using the MSBuild NuGet Package instead of referencing the MSBuild dlls.
So, I made the appropriate changes to my projects and tried running it again. The build fails and I get this exception:
The SDK 'Microsoft.NET.Sdk' specified could not be found.
More digging and I find that setting the "MSBuildSDKsPath" environment variable allows MSBuild to find the SDK. But the build fails again
with this exception:
“The imported project
"…MainProgram\bin\x64\Debug\net7.0-windows\Current\Microsoft.Common.props"
was not found. Confirm that the expression in the Import declaration
"…MainProgram\bin\x64\Debug\net7.0-windows\Current\Microsoft.Common.props"
is correct, and that the file exists on disk. C:\Program
Files\dotnet\sdk\7.0.101\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.props”
Setting the "AlternateCommonProps" environment variable appropriately
solved that problem, but:
“The SDK 'Microsoft.NET.SDK.WorkloadAutoImportPropsLocator' specified
could not be found. C:\Program
Files\dotnet\sdk\7.0.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.ImportWorkloads.props”
Given that I wasn’t making much progress this way I decided to try out
the Microsoft.Build.Locator. I made the appropriate changes to my
program. Using the locator, the program correctly finds the SDK
without having to set environments variables, which is nice. However,
my builds still fail and now all the exceptions are blank. I added a
logger to see if I can figure out what is going on. Below are some of
the warnings and errors I received and through changes to the .proj
file was able to get past with varying degrees of success.
Project "MSBuiltTest.proj" (Build target(s)): Warning C:\Program
Files\dotnet\sdk\7.0.101\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.targets(37,3):
"C:\Program Files\dotnet\sdk\7.0.101\Microsoft.Common.targets" cannot
be imported again. It was already imported at "C:\Program
Files\dotnet\sdk\7.0.101\Microsoft.CSharp.CurrentVersion.targets
(327,5)". This is most likely a build authoring error. This subsequent
import will be ignored. […\MSBuiltTest.proj] Done building project
"MSBuiltTest.proj" -- FAILED.
Project "MSBuiltTest.proj" (Build target(s)):
GetReferenceAssemblyPaths: : ERROR C:\Program
Files\dotnet\sdk\7.0.101\Microsoft.Common.CurrentVersion.targets(1229,5):
The reference assemblies for .NETFramework,Version=v4.0 were not
found. To resolve this, install the Developer Pack (SDK/Targeting
Pack) for this framework version or retarget your application. You can
download .NET Framework Developer Packs at
https://aka.ms/msbuild/developerpacks Project "MSBuiltTest.proj"
(Build target(s)): ResolveAssemblyReference: : Warning C:\Program
Files\dotnet\sdk\7.0.101\Microsoft.Common.CurrentVersion.targets(2352,5):
Could not resolve this reference. Could not locate the assembly
"System". Check to make sure the assembly exists on disk. If this
reference is required by your code, you may get compilation errors.
ResolveAssemblyReference: : …"WindowsBase"…
ResolveAssemblyReference: : …" PresentationCore "…
ResolveAssemblyReference: : …" PresentationFramework "…
ResolveAssemblyReference: : …" PresentationFramework "…
ResolveAssemblyReference: : …" System.Xaml "…
ResolveAssemblyReference: : Warning C:\Program
Files\dotnet\sdk\7.0.101\Microsoft.Common.CurrentVersion.targets(2352,5):
No way to resolve conflict between "System, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089" and "System".
Choosing "System, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089" arbitrarily.
ResolveAssemblyReference: : …"WindowsBase, …
ResolveAssemblyReference: : …" PresentationCore "…
ResolveAssemblyReference: : …" PresentationFramework "…
ResolveAssemblyReference: : …" PresentationFramework "…
ResolveAssemblyReference: : …" System.Xaml "… Done building project
"MSBuiltTest.proj" -- FAILED.
Project "MSBuiltTest.proj" (Build target(s)): ERROR C:\Program
Files\dotnet\sdk\7.0.101\Sdks\Microsoft.NET.Sdk.WindowsDesktop\targets\Microsoft.WinFX.targets(211,9):
The "MarkupCompilePass1" task was not given a value for the required
parameter "Language". Done building project "MSBuiltTest.proj" --
FAILED.
The test project I built worked exactly as I had hoped it would, but my main program is continuously giving me grief. It’s my hope that I am missing some simple solution to my problems. But I have read everything I can find on how to use MSBuild, I have followed the endless rabbit trails of .common and .prop files and have even spent time digging through the MSBuild source code. The conclusion I have come to is that it’s turtles all the way down. Can someone tell me what I am missing or point me in the direction of some documentation that can help?
I am desiring addition to my Universal Windows Platform software the ability for it to shut-down its host machine after invocation of it by 1 button-click, however, 0 methods that I have tried thus far have operated:
I have attempted to instruct Windows to shut-down, but shutdown /s /t 120 is not able to operate, specifically after invocation by my application.
Therefore, I attempted uage of native C# code. However, usage of this has informed me that it has not been permitted to invoke shutdown:
ShutdownManager.BeginShutdown(Windows.System.ShutdownKind.Shutdown, TimeSpan.FromSeconds(120));
I have used many methods, but I am not able to remediate this problem.
Relevant files
MainPage.xaml.cs
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using System;
using Windows.System;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409.
// Delete the extra namespaces when the application is complete.
namespace Shutdown_Roulette
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
private void Button_click(object sender, RoutedEventArgs e)
{
ShutdownManager.BeginShutdown(Windows.System.ShutdownKind.Shutdown, TimeSpan.FromSeconds(120));
}
}
}
Package.appxmanifest
<?xml version="1.0" encoding="utf-8"?>
<Package
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
xmlns:iot="http://schemas.microsoft.com/appx/manifest/iot/windows10"
IgnorableNamespaces="uap mp iot">
<Identity
Name="7eb73f1e-b159-4fd0-aab9-4158e57ba08a"
Publisher="CN=rokeb"
Version="1.0.0.0" />
<mp:PhoneIdentity PhoneProductId="7eb73f1e-b159-4fd0-aab9-4158e57ba08a" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
<Properties>
<DisplayName>Shutdown Roulette</DisplayName>
<PublisherDisplayName>Master Roke Julian Lockhart Beedell</PublisherDisplayName>
<Logo>Assets\StoreLogo.png</Logo>
</Properties>
<Dependencies>
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" />
</Dependencies>
<Resources>
<Resource Language="x-generate"/>
</Resources>
<Applications>
<Application Id="App"
Executable="$targetnametoken$.exe"
EntryPoint="Shutdown_Roulette.App">
<uap:VisualElements
DisplayName="Shutdown Roulette"
Square150x150Logo="Assets\Square150x150Logo.png"
Square44x44Logo="Assets\Square44x44Logo.png"
Description="Shutdown Roulette"
BackgroundColor="transparent">
<uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png" ShortName="Shutdown Roulette">
</uap:DefaultTile >
<uap:SplashScreen Image="Assets\SplashScreen.png" />
</uap:VisualElements>
</Application>
</Applications>
<Capabilities>
<iot:Capability Name="systemManagement"/></Capabilities>
</Package>
Please do note that I am wanting to use this command on Windows 10, rather than Windows 10 IoT; I merely am attempting to use those commands because they are the only other way I have been able to conceive of invocation of this without reliance upon either PowerShell, Python or the Windows Command Processor.
According to the description of ShowdownManager, it needs the support of IOT SDK, which means it is a platform-limited API (only valid on IOT devices).
In Windows 10 desktop devices, UWP does not have the permission to turn off the device.
I am attempting to use this plugin to open an android image picker, however it errors when launched.
The calling script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using LukeWaffel.AndroidGallery;
public class LoadImageWithMagic : MonoBehaviour {
public Image image;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public void OpenGallery() {
Debug.Log ("It clicked");
AndroidGallery.Instance.OpenGallery (GalleryCallback);
}
public void GalleryCallback() {
image.material.mainTexture = AndroidGallery.Instance.GetTexture ();
AndroidGallery.Instance.ResetOutput ();
}
}
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.unity3d.player"
xmlns:tools="http://schemas.android.com/tools"
android:installLocation="preferExternal"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true"/>
<application
android:theme="#style/UnityThemeSelector"
android:icon="#drawable/app_icon"
android:label="#string/app_name"
android:debuggable="true">
<activity android:name="com.unity3d.player.UnityPlayerActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="unityplayer.UnityActivity" android:value="true" />
</activity>
<activity android:name= "com.lukewaffel.androidgallery.Gallery"></activity>
</application>
</manifest>
Error from logcat:
08-25 09:53:09.029 3458-3474/com.TNOAB.FindMyPet I/Unity: It clicked
(Filename: ./artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)
08-25 09:53:09.036 3458-3474/com.TNOAB.FindMyPet I/Unity: [Singleton] An instance of LukeWaffel.AndroidGallery.AndroidGallery is needed in the scene, so '(singleton) LukeWaffel.AndroidGallery.AndroidGallery (UnityEngine.GameObject)' was created with DontDestroyOnLoad.
(Filename: ./artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)
08-25 09:53:09.060 1485-1737/system_process I/ActivityManager: START u0 {cmp=com.TNOAB.FindMyPet/com.lukewaffel.androidgallery.Gallery} from uid 10061 on display 0
08-25 09:53:09.082 3458-3474/com.TNOAB.FindMyPet I/Unity: AndroidJavaException: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.TNOAB.FindMyPet/com.lukewaffel.androidgallery.Gallery}; have you declared this activity in your AndroidManifest.xml?
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.TNOAB.FindMyPet/com.lukewaffel.androidgallery.Gallery}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1777)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1501)
at android.app.Activity.startActivityForResult(Activity.java:3745)
at android.app.Activity.startActivityForResult(Activity.java:3706)
at android.app.Activity.startActivity(Activity.java:4016)
at android.app.Activity.startActivity(Activity.java:3984)
at com.lukewaffel.androidgallery.UnityBinder.OpenGallery(UnityBinder.java:12)
at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
at com.unity3d.player.UnityPlayer.c
It appears that the issue is Unity is prepending my package to the package of the plugin, causing it to not be found. I have attempted to change my package to the package of the plugin and it still had the same error.
I have tried reinstalling the app and still cannot get the gallery to open.
I have discovered that the issue was all of the plugin files were placed into a subdirectory, so unity could not find the AndroidManifest.xml. After moving all of the items out of the subdirectory, the Gallery opened.
As a note to anyone copying the above code, I then discovered an unrelated error, image.material.mainTexture = AndroidGallery.Instance.GetTexture (); should be image.sprite = AndroidGallery.Instance.GetSprite ();
I'm developing a Windows 10 Universal Application to communicate with an embedded system via a HM-10 chip.
What I did try and other circumstances
The chip is set up, there is no problem connecting to it. From an iPhone application for these devices, I can due two-way messaging via Arduino Serial window, and the iPhone application.
My computer can also see it, and can connect to it from a sample application provided by Microsoft.
Before running, it is paired and connected in Bluetooth Settings. I also tried without pairing and connecting, but it was not discovered by DeviceInformation then.
The MainPage.xaml.cs
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.Devices.Enumeration;
using Windows.Devices.Bluetooth;
using Windows.Devices.Bluetooth.GenericAttributeProfile;
using System.Threading.Tasks;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
namespace App1
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
///
public sealed partial class MainPage : Page
{
public List<string> deviceList = new List<string>();
public MainPage()
{
this.InitializeComponent();
Debug.WriteLine("A");
var taskDevices = getDevices();
Task.WaitAll(taskDevices);
Debug.WriteLine("B");
}
public async Task<List<string>> getDevices()
{
Debug.WriteLine("C");
foreach (DeviceInformation di in await DeviceInformation.FindAllAsync(GattDeviceService.GetDeviceSelectorFromUuid(GattServiceUuids.GenericAccess), null))
{
Debug.WriteLine("D");
Debug.WriteLine(di.Name);
Debug.WriteLine(di.Id);
Debug.WriteLine(di.IsEnabled);
var bleDevice = await GattDeviceService.FromIdAsync(di.Id);
Debug.WriteLine("E");
// Add the dvice name into the list.
// deviceList.Add(bleDevice.Name);
}
return deviceList;
}
private void button_Click(object sender, RoutedEventArgs e)
{
}
private void textBox_TextChanged(object sender, TextChangedEventArgs e)
{
}
I did my search and I realised the manifest needs an addition to have Bluetooth capability.
Package.appxmanifest
<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" xmlns:m2="http://schemas.microsoft.com/appx/manifest/foundation/windows10" IgnorableNamespaces="uap mp">
<Identity Name="acbf6f03-e62b-4d1e-8c25-9f649ca5af4c" Publisher="CN=Boomkin" Version="1.0.0.0" />
<mp:PhoneIdentity PhoneProductId="acbf6f03-e62b-4d1e-8c25-9f649ca5af4c" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
<Properties>
<DisplayName>App1</DisplayName>
<PublisherDisplayName>Boomkin</PublisherDisplayName>
<Logo>Assets\StoreLogo.png</Logo>
</Properties>
<Dependencies>
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" />
</Dependencies>
<Resources>
<Resource Language="x-generate" />
</Resources>
<Applications>
<Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="App1.App">
<uap:VisualElements DisplayName="Histamine Control Panel" Square150x150Logo="Assets\Square150x150Logo.png" Square44x44Logo="Assets\Square44x44Logo.png" Description="App1" BackgroundColor="transparent">
<uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png">
</uap:DefaultTile>
<uap:SplashScreen Image="Assets\SplashScreen.png" />
</uap:VisualElements>
</Application>
</Applications>
<Capabilities>
<m2:DeviceCapability Name="bluetooth.genericAttributeProfile">
<m2:Device Id="any">
<m2:Function Type="serviceId:00001800-0000-1000-8000-00805f9b34fb"/>
</m2:Device>
</m2:DeviceCapability>
</Capabilities>
</Package>
I have tried many other versions, added and deleted internetclient and bluetooth capabilities, without any success. My current guess that the problem is around here.
The problem
As the question states the FromIdAsync part doesn't return anything. Not even null (as I saw in many other questions here), it just does not finish and the thread exists eventually.
Log
A
C
D
HIST
\\?\BTHLEDevice#{00001800-0000-1000-8000-00805f9b34fb}_f45eabaaf694#8&2782425b&13&0006#{6e3bb679-4372-40c8-9eaa-4509df260cd8}
True
Then after waiting for a while
The thread 0x3c6c has exited with code 0 (0x0).
Thank you and I really appreciate any help.
Your problem is here:
Task.WaitAll(taskDevices);
Blocking on asynchronous code causes a deadlock. The proper resolution is to use async all the way.
In your specific case, you need to (synchronously, immediately) create your view in a "loading" state - however you want that to look. Then, when the asynchronous code completes, update your view to a "loaded" state. See my MSDN article on async data binding for more information.
I am trying to create a service using VS2012 express that will be installed with WiX. This is done without the templates provided in the full version of VS. I had my class derive from ServiceBase. I assumed (perhaps incorrectly) that if the program was installed using WiX that a class derived from ServiceInstaller was not necessary. When I run the MSI that is created by WiX, no errors are flagged, but no new service shows up.
I have Google searched for an answer, but didn't find an example of the miniumum C# code needed to create a service. Links to a good tutorial or pointing out the area where either the C# or WiX code is lacking would be appreciated.
The code for the template service is:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceProcess;
namespace WixInstalledServiceTeamplate
{
class BasicService : ServiceBase
{
static void Main(string[] args)
{
}
public BasicService()
{
this.AutoLog = true;
this.ServiceName = "MY Service Template";
}
protected override void OnStart(string[] args)
{
base.OnStart(args);
//TODO: place your start code here
}
protected override void OnStop()
{
base.OnStop();
//TODO: clean up any variables and stop any threads
}
}
}
Wix Code:
<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="786F7069-9C7F-4E15-A721-6B3B4D300FD9" Name="WixEditText" Language="1033" Version="0.0.0.1" Manufacturer="3M Automated Inpsection and Measurement" UpgradeCode="31956530-98A2-4C83-B3A9-5FB6B7A7AE07">
<Package Description="Test file in a Product" Comments="Simple test" InstallerVersion="200" Compressed="yes" />
<Media Id="1" Cabinet="simple.cab" EmbedCab="yes" />
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder" Name="PFiles">
<Directory Id="RELEASE" Name="Release">
<Component Id="WIXINSTALLEDSERVICETEAMPLATE.EXE" DiskId="1" Guid="B0AEF920-4EF0-478C-9B5A-0B13F23F7E73">
<File Id="WIXINSTALLEDSERVICETEAMPLATE.EXE" Name="WixInstalledServiceTeamplate.exe" Source="bin\Release\WixInstalledServiceTeamplate.exe" />
</Component>
</Directory>
</Directory>
</Directory>
<Feature Id="Complete" Title="Install Everything" Level="1" Display="expand" ConfigurableDirectory="TARGETDIR">
<Component Id="MYServiceTemplate" Guid="1BD8DA93-86A6-4DC4-8CE9-B59525DDFB89" Directory="TARGETDIR">
<ServiceInstall Name="myservicetemplate" Type="ownProcess" Start="demand" ErrorControl="normal" Account="LOCAL SYSTEM" Description="test service install with wix" DisplayName="MY Service Template" Id="serviceInstall">
</ServiceInstall>
</Component>
<ComponentRef Id="WIXINSTALLEDSERVICETEAMPLATE.EXE" />
</Feature>
<UI />
<UIRef Id="WixUI_Minimal" />
</Product>
</Wix>
Your assumption that only ServiceBase is needed is correct. However you only need 1 component not 2 components in WiX. The ServiceInstall doesn't reference a file, it implicitly applies to the keyfile of the parent component.
If you need the ability to install the EXE and a console app and/or a service (variation point) that gets more complicated. The easiest is to factor into a DLL and create 2 EXE's with a total of 3 components.