Run C# WPF application with uiAccess = true in manifest at startup - c#

The application needs to stay on top of metro, hence the need for the uiAccess flag. This is a recent change in the application. In the previous version, where the uiAccess flag was not set, we could set the application to run on user access using this scheduled task:
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2014-04-23T11:31:11.9188616</Date>
<Author>MU15\Utente</Author>
</RegistrationInfo>
<Triggers>
<LogonTrigger>
<Enabled>true</Enabled>
</LogonTrigger>
</Triggers>
<Principals>
<Principal id="Author">
<UserId>MU15\Utente</UserId>
<LogonType>InteractiveToken</LogonType>
<RunLevel>HighestAvailable</RunLevel>
</Principal>
</Principals>
<Settings>
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
<DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>
<AllowHardTerminate>false</AllowHardTerminate>
<StartWhenAvailable>true</StartWhenAvailable>
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
<IdleSettings>
<StopOnIdleEnd>false</StopOnIdleEnd>
<RestartOnIdle>false</RestartOnIdle>
</IdleSettings>
<AllowStartOnDemand>true</AllowStartOnDemand>
<Enabled>true</Enabled>
<Hidden>false</Hidden>
<RunOnlyIfIdle>false</RunOnlyIfIdle>
<WakeToRun>false</WakeToRun>
<ExecutionTimeLimit>PT0S</ExecutionTimeLimit>
<Priority>7</Priority>
<RestartOnFailure>
<Interval>PT1M</Interval>
<Count>3</Count>
</RestartOnFailure>
</Settings>
<Actions Context="Author">
<Exec>
<Command>"C:\Program Files (x86)\path\to\application.exe"</Command>
</Exec>
</Actions>
</Task>
We recently added the following application manifest:
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app" />
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="requireAdministrator" uiAccess="true" />
</requestedPrivileges>
<applicationRequestMinimum>
<defaultAssemblyRequest permissionSetReference="Custom" />
<PermissionSet ID="Custom" SameSite="site" Unrestricted="true" />
</applicationRequestMinimum>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
</application>
</compatibility>
</assembly>
The scheduled task now fails with error 0x800702e4: the requested operation requires elevation.
We tried putting a shortcut in %APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup, with no success.
Is there a way to run an application with the uiAccess flag set?

The problem is that the Task Scheduler uses by default CreateProcess, which won't work for running processes with a manifest that requires elevation: you'd need to use ShellExecuteEx for that.
There are probably other ways to do this, but at least one of them, with the task scheduler, is configure the task to stop other existing instances if the task is already running.
Via the GUI: Settings -> "If task is already running (etc.)", set to "Stop the existing instance", or in the XML:
<MultipleInstancesPolicy>StopExisting</MultipleInstancesPolicy>

Related

Unable to get autocomplete to work after installing vsix

I am working on a completionprovider project, which will be published as a visual studio extension. The completionprovider code is taken from https://github.com/PacktPublishing/Roslyn-Cookbook/blob/master/Chapter03/CodeSamples/Recipe%205%20-%20CompletionProvider/CompletionProvider.zip.
When I was debugging the vsix, I can get it to work properly. Installation also worked using the vsix file generated in the bin folder after building the project. However, I can't get it to work by testing the extension in the project I used during debugging. I have tried all possible ways to change the vsixmanifest but simply could not get it to work after installation. Below is a sample of the manifest file.
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="MyCompletionProviderVsix.2f4985a4-6bc6-46fc-9082-2c45d3d8ac3f" Version="1.0" Language="en-US" Publisher="ABC" />
<DisplayName>MyCompletionProviderVsix</DisplayName>
<Description>Auto complete test.</Description>
</Metadata>
<Installation AllUsers="true">
<InstallationTarget Id="Microsoft.VisualStudio.Community" Version="[16.0, 17.0)" />
</Installation>
<Dependencies>
<Dependency Id="Microsoft.Framework.NDP" DisplayName="Microsoft .NET Framework" d:Source="Manual" Version="[4.5,)" />
</Dependencies>
<Prerequisites>
<Prerequisite Id="Microsoft.VisualStudio.Component.CoreEditor" Version="[15.0,17.0)" DisplayName="Visual Studio core editor" />
<Prerequisite Id="Microsoft.VisualStudio.Component.Roslyn.LanguageServices" Version="[16.0,17.0)" DisplayName="Roslyn Language Services" />
</Prerequisites>
<Assets>
<Asset Type="Microsoft.VisualStudio.MefComponent" d:Source="Project" d:ProjectName="MyCompletionProvider" Path="|MyCompletionProvider|" />
<Asset Type="Microsoft.VisualStudio.Analyzer" d:Source="Project" d:ProjectName="MyCompletionProvider" Path="|MyCompletionProvider|" />
</Assets>
</PackageManifest>

Service Fabric Application doesn't register and run the Actor

I am developing APIs with Service Fabric into a big solution. After I created the services I needed (an Actor, a stateful and a stateless with .NET Framework) and I made a walking skeleton of the APIs.
I started to test and service fabric always threw the error "Service does not exist" (I'm 100% sure that the uri was right) when was the time to call the Actor (same error with both ActorProxyFactory and ActorProxy). I wathced on Cluster Explorer and under my SF App there was only the other two service. But the ActorServiceType was registered.
So I decide to create two simple SF app with an actor and I got the same error and also I don't see them on Cluster explorer.
In no projects I touched the ServiceManifest, ApplicationManifest or whatelse.
Here the versions of the tools I use:
Windows 11 Enterprise
Visual Studio Enterprise v16.11.9 with .Net Framework 4.7.1
Service Fabric Runtime 8.1.321.9590
Serive Fabric SDK 5.1.321.9590
Nuget Microsoft.SerivceFabric 8.1.321
Nuget Microsoft.ServiceFabric.Actors 5.1.321 (For the nuget packages I tried everything)
Microsoft.VisualStudio.Azure.Fabric.MSBuild 1.7.6 (also this I tried
every version)
My auto-generated setting.xml:
<?xml version="1.0" encoding="utf-8"?>
<Settings xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/2011/01/fabric">
<Section Name="MyActorServiceReplicatorConfig">
<Parameter Name="ReplicatorEndpoint" Value="MyActorServiceReplicatorEndpoint" />
<Parameter Name="BatchAcknowledgementInterval" Value="0.005" />
</Section>
<Section Name="MyActorServiceReplicatorSecurityConfig">
<Parameter Name="CredentialType" Value="None" />
</Section>
<!-- The content will be generated during build -->
</Settings>
My auto-generated service-manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<ServiceManifest xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="MyActorPkg" Version="1.0.0" xmlns="http://schemas.microsoft.com/2011/01/fabric">
<ServiceTypes>
<StatefulServiceType ServiceTypeName="MyActorServiceType" HasPersistedState="true">
<Extensions>
<Extension Name="__GeneratedServiceType__" GeneratedId="5f4d2e71-68d5-43f4-b8a3-60990017b54d|Persisted">
<GeneratedNames xmlns="http://schemas.microsoft.com/2015/03/fabact-no-schema">
<DefaultService Name="MyActorService" />
<ReplicatorEndpoint Name="MyActorServiceReplicatorEndpoint" />
<ReplicatorConfigSection Name="MyActorServiceReplicatorConfig" />
<ReplicatorSecurityConfigSection Name="MyActorServiceReplicatorSecurityConfig" />
<StoreConfigSection Name="MyActorServiceLocalStoreConfig" />
<ServiceEndpointV2_1 Name="MyActorServiceEndpointV2_1" />
</GeneratedNames>
</Extension>
</Extensions>
</StatefulServiceType>
</ServiceTypes>
<CodePackage Name="Code" Version="1.0.0">
<EntryPoint>
<ExeHost>
<Program>MyActor.exe</Program>
</ExeHost>
</EntryPoint>
</CodePackage>
<ConfigPackage Name="Config" Version="1.0.0" />
<Resources>
<Endpoints>
<Endpoint Name="MyActorServiceEndpointV2_1" />
<Endpoint Name="MyActorServiceReplicatorEndpoint" />
</Endpoints>
</Resources>
<!-- The content will be generated during build -->
</ServiceManifest>
my auto-generated application-manifest:
<?xml version="1.0" encoding="utf-8"?>
<ServiceManifest xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="MyActorPkg" Version="1.0.0" xmlns="http://schemas.microsoft.com/2011/01/fabric">
<ServiceTypes>
<StatefulServiceType ServiceTypeName="MyActorServiceType" HasPersistedState="true">
<Extensions>
<Extension Name="__GeneratedServiceType__" GeneratedId="5f4d2e71-68d5-43f4-b8a3-60990017b54d|Persisted">
<GeneratedNames xmlns="http://schemas.microsoft.com/2015/03/fabact-no-schema">
<DefaultService Name="MyActorService" />
<ReplicatorEndpoint Name="MyActorServiceReplicatorEndpoint" />
<ReplicatorConfigSection Name="MyActorServiceReplicatorConfig" />
<ReplicatorSecurityConfigSection Name="MyActorServiceReplicatorSecurityConfig" />
<StoreConfigSection Name="MyActorServiceLocalStoreConfig" />
<ServiceEndpointV2_1 Name="MyActorServiceEndpointV2_1" />
</GeneratedNames>
</Extension>
</Extensions>
</StatefulServiceType>
</ServiceTypes>
<CodePackage Name="Code" Version="1.0.0">
<EntryPoint>
<ExeHost>
<Program>MyActor.exe</Program>
</ExeHost>
</EntryPoint>
</CodePackage>
<ConfigPackage Name="Config" Version="1.0.0" />
<Resources>
<Endpoints>
<Endpoint Name="MyActorServiceEndpointV2_1" />
<Endpoint Name="MyActorServiceReplicatorEndpoint" />
</Endpoints>
</Resources>
<!-- The content will be generated during build -->
</ServiceManifest>
my local1node.xml file:
<?xml version="1.0" encoding="utf-8"?>
<Application xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="fabric:/TEST2.MYACTOR.SF" xmlns="http://schemas.microsoft.com/2011/01/fabric">
<Parameters />
</Application>
screens cluster explorer:
screen cluster explorer
screen cluster explorer service type
The solution of this problem found on this github issue with a step-by-step guide.
In few words if you have more than installation of Visual Studio (2019 and 2022) a service fabric package cache go in conflict.

Tizen.NET NfcCardEmulation throws UnsupportedException (with added privileges)

I had a issue with a Tizen.NET Api v4. Generally i need cardemulation in the watch, but while executing static method
NfcManager.GetCardEmulationAdapter()
i am gettings logs
tizen-manifest.xml looks like (and he was generating by vs2019 with Tizen ext)
<?xml version="1.0" encoding="utf-8"?>
<manifest package="tizenapp" version="1.0.1" api-version="4" xmlns="http://tizen.org/ns/packages">
<profile name="wearable" />
<ui-application appid="tizenapp" exec="tizenapp.dll" multiple="false" nodisplay="false" taskmanage="true" type="dotnet" launch_mode="single">
<label>tizenapp</label>
<icon>tizenapp.png</icon>
<metadata key="http://tizen.org/metadata/prefer_dotnet_aot" value="true" />
<splash-screens />
</ui-application>
<shortcut-list />
<privileges>
<privilege>http://tizen.org/privilege/secureelement</privilege>
<privilege>http://tizen.org/privilege/nfc</privilege>
<privilege>http://tizen.org/privilege/nfc.cardemulation</privilege>
<privilege>http://tizen.org/feature/network.nfc.card_emulation</privilege>
<privilege>http://tizen.org/feature/network.nfc</privilege>
</privileges>
<dependencies />
<provides-appdefined-privileges />
<feature name="http://tizen.org/feature/network.nfc">true</feature>
<feature name="http://tizen.org/feature/network.nfc.card_emulation">true</feature>
<feature name="http://tizen.org/feature/network.secure_element">true</feature>
<feature name="http://tizen.org/feature/network.secure_element.ese">true</feature>
<feature name="http://tizen.org/feature/network.secure_element.uicc">true</feature>
</manifest>
I dont know what i need to fix this problems.
It looks like a simple typo in the implementation. It's fixed in API5 and later.
https://github.com/Samsung/TizenFX/pull/578/files
I'm not sure if there's any workaround for this when targetting for API4, because it's not about a privilege but a feature.

Version number in manifest file's dependentAssembly/assemblyIdentity element

I'm working with an application that includes an un-managed client DLL and a managed COM server DLL (which was a challenge in itself: Managed Reg-Free COM Server Won't Activate), and now I'm wondering what is the best way to keep the version numbers in sync. Since we are building both the client and the server, and we try to keep the version numbers of all our files in sync for every build, it looks like I need to have a process that edits all my manifest files on both the client and server ends of all my isolated COM references before a full build happens. Is there an easier way?
Example (client manifest):
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity type="win32" name="globals" version="1.0.0.0" />
<dependency>
<dependentAssembly>
<assemblyIdentity type="win32" name="SoftBrands.FourthShift.FSCulture" version="8.0.0.999" publicKeyToken="541b4aff0f04b60a" />
</dependentAssembly>
</dependency>
</assembly>
Server Manifest:
<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<assemblyIdentity type="win32" name="SoftBrands.FourthShift.FSCulture" version="8.0.0.999" publicKeyToken="541b4aff0f04b60a" />
<clrClass clsid="{23D4FF3D-EEDF-4F68-AD65-749958EE3B2A}"
name="SoftBrands.FourthShift.FSCulture.FSCulture"
tlbid="{8D480B22-D603-309F-9A26-EA9E9B020207}">
</clrClass>
</asmv1:assembly>
I could just do a global search and replace on version="8.0.0.999" with the current version for every build, but I suspect there might be a better way.
Your best bet is to leverage a custom MSBuild task to manipulate the project artifacts prior to compilation.
The task should accept three properties. One property for the client manifest, another property for the server manifest and the third property for the version.
Here is what the targets file might look like in MSBuild.
Manifests.targets
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<!-- Import Tasks -->
<!-- Be sure to sue the full namespace of the task to import -->
<UsingTask TaskName="Full.Namespace.To.UpdateManifestsTask" AssemblyFile="$(MSBuildThisFileDirectory)\MyCustomTasks.dll" />
<!-- Define the location of the client and server manifest files -->
<PropertyGroup>
<ClientManifest><!-- Location of the client manifest --></ClientManifest>
<ServerManifest><!-- Location of the server manifest --></ServerManifest>
</PropertyGroup>
<!-- Define Generate App Config Target -->
<Target Name="UpdateManifests">
<UpdateManifests ClientManifest="$(ClientManifest)" ServerManifest="$(ServerManifest)" Version="$(Version)" />
</Target>
<!-- Define Before Build Target -->
<!-- This will ensure the above target gets executed prior to compilation -->
<Target Name="BeforeBuild">
<CallTarget Targets="UpdateManifests;" />
</Target>
</Project>
Here is what the custom task might look like -
UpdateManifestsTask.cs
public class UpdateManifestsTask : Task
{
public ITaskItem ClientManifest { get; set; }
public ITaskItem ServerManifest { get; set; }
public ITaskItem Version { get; set; }
public override bool Execute()
{
var newVersion = string.Format("name=\"SoftBrands.FourthShift.FSCulture\" version=\"{0}\"", this.Version.ItemSpec);
var clientFile = File.ReadAllText(this.ClientManifest.ItemSpec);
clientFile = Regex.Replace(clientFile, "name=\"SoftBrands.FourthShift.FSCulture\" version=\"\\d*\\.\\d*\\.\\d*\\.\\d*\"", newVersion);
File.WriteAllText(this.ClientManifest.ItemSpec, clientFile);
var serverFile = File.ReadAllText(this.ClientManifest.ItemSpec);
serverFile = Regex.Replace(clientFile, "name=\"SoftBrands.FourthShift.FSCulture\" version=\"\\d*\\.\\d*\\.\\d*\\.\\d*\"", newVersion);
File.WriteAllText(this.ServerManifest.ItemSpec, serverFile);
return true;
}
}
The RegEx is a little sloppy as this was a quick and dirty example but this is effectively how you would go about doing this kind of thing.
Be sure to add references to the MSBuild libraries.
http://blogs.msdn.com/b/msbuild/archive/2006/01/21/515834.aspx
If you don't want to build a custom task you can write a small console app that does the same thing but in my opinion a custom task is cleaner.
Should you decide to go the console app route, you can leverage the BeforeBuild and AfterBuild events in your project file.
<Target Name="BeforeBuild">
<!-- Invoke console app -->
</Target>
<Target Name="AfterBuild">
</Target>

Azure Diagnostics won't create WADLogsTable

I wanted to add logging to an existing azure cloud service using NLog and Azure Diagnostics, i went through all the steps described here: http://msdn.microsoft.com/en-us/library/azure/dn482131.aspx
But, unfortunately when testing the cloud service the WADLogsTable table storage does not created, and no information gets stored here. Not on local development storage, nor on azure.
diagnostics.wadcfg:
<?xml version="1.0" encoding="utf-8"?>
<DiagnosticMonitorConfiguration configurationChangePollInterval="PT1M" overallQuotaInMB="4096" xmlns="http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration">
<DiagnosticInfrastructureLogs />
<Directories>
<IISLogs container="wad-iis-logfiles" directoryQuotaInMB="1024" />
<CrashDumps container="wad-crash-dumps" />
</Directories>
<Logs bufferQuotaInMB="1024" scheduledTransferPeriod="PT1M" scheduledTransferLogLevelFilter="Verbose" />
<PerformanceCounters bufferQuotaInMB="512">
<PerformanceCounterConfiguration counterSpecifier="\Memory\Available MBytes" sampleRate="PT3M" />
</PerformanceCounters>
<WindowsEventLog bufferQuotaInMB="1024" scheduledTransferPeriod="PT1M" scheduledTransferLogLevelFilter="Verbose">
<DataSource name="Application!*" />
</WindowsEventLog>
</DiagnosticMonitorConfiguration>
ServiceConfiguration.Local.csfg (the same at Cloud, just with the correct table storage account)
<?xml version="1.0" encoding="utf-8"?>
<ServiceConfiguration serviceName="AAService" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="4" osVersion="*" schemaVersion="2014-01.2.3">
<Role name="Web.Services.AAService">
<Instances count="1" />
<ConfigurationSettings>
<Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="UseDevelopmentStorage=true" />
</ConfigurationSettings>
</Role>
</ServiceConfiguration>
ServiceDefinition.csdef
<?xml version="1.0" encoding="utf-8"?>
<ServiceDefinition name="AAService" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition" schemaVersion="2014-01.2.3">
<WebRole name="Web.Services.AAService" vmsize="ExtraSmall">
<Sites>
<Site name="Web">
<Bindings>
<Binding name="Endpoint1" endpointName="Endpoint1" />
</Bindings>
</Site>
</Sites>
<Endpoints>
<InputEndpoint name="Endpoint1" protocol="http" port="80" />
</Endpoints>
<Imports>
<Import moduleName="Diagnostics" />
</Imports>
<LocalResources>
<LocalStorage name="Web.Services.AAService.svclog" sizeInMB="1000" cleanOnRoleRecycle="false" />
</LocalResources>
</WebRole>
</ServiceDefinition>
WebRole entrypoint
public override bool OnStart()
{
// To enable the AzureLocalStorageTraceListner, uncomment relevent section in the web.config
DiagnosticMonitorConfiguration diagnosticConfig = DiagnosticMonitor.GetDefaultInitialConfiguration();
diagnosticConfig.Directories.ScheduledTransferPeriod = TimeSpan.FromMinutes(1);
diagnosticConfig.Directories.DataSources.Add(AzureLocalStorageTraceListener.GetLogDirectory());
DiagnosticMonitor.Start("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString", diagnosticConfig);
// For information on handling configuration changes
// see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.
return base.OnStart();
}
cloud service web.config also has:
<system.diagnostics>
<trace>
<listeners>
<add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=2.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics">
<filter type="" />
</add>
</listeners>
</trace>
</system.diagnostics>
Does anyone have any ide why is this doesnt make any trace logs? I called Trace.WriteLine() many places where the application goes through for sure, but still no WADLogsTable.
Thanks for the help
Get rid of all the Diagnostic* code in OnStart. The <Import moduleName="Diagnostics" /> in your csdef will automatically start the diagnostics agent, and the diagnostics agent will read the settings from the .wadcfg. Your code in OnStart is unnecessary and is overriding the wadcfg settings due to the order of precedence of loading WAD configuration.
Also note that if you are trying to update an existing cloud service then you will need to first delete the XML file in blob storage. If a file already exists in blob storage then the diagnostics agent will ignore the .wadcfg settings. The file you are looking for is in wad-control-container and will be named with the deployment ID and role name.

Categories