Is calling System.Diagnostics.Process.Start() truly problematic? - c#

In the Validation Result that I get when readying my app for submission to the Microsoft Store (which my app "PASSED WITH WARNINGS"), I got this "Fail" under the "Package Sanity Test" section:
The code which contains such a call is:
private void myMapsHelpToolStripMenuItem_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("https://ramblingnotesofageezer.substack.com/p/map-o-matic-overview");
}
I am using that code due to the recommendation to do so here. How do I start a process from C#?
Is this truly a problem? If so, what should I use instead of the call to System.Diagnostics.Process.Start()?
I find it odd that it is classified as a failed part of the test, yet the overall results are that my app passed (albeit with warnings).
UPDATE
I checked out the link in the comment from Codexer, where it says, "Starting a utility can often provide a convenient way to obtain information from the operating system, access the registry, or access system capabilities. However, you can use UWP APIs to accomplish these sorts of tasks instead."
If this is the solution, do the UWP APIs have an equivalent to System.Diagnostics.Process.Start()?
UPDATE 2
I followed the steps in the answer, but the solution still doesn't compile, due to an error with this line of code:
await Windows.System.Launcher.LaunchUriAsync(uri);
In fact, even when I comment out the offending line, the project will no longer compile, but doesn't give me any information about how to solve the problem, just this:
I set the Package Management Format to PackageReference, and installed version 10.0.18362.2005 of Microsoft.Windows.SDK.Contracts, but it is complaining about needing a package reference...?!? I tried adding using Windows.System;
and using Microsoft.Windows.SDK.Contracts; but neither is recognized.
The package is installed for the project, as you can see here:
UPDATE 3
Regarding the "Must Use Package Reference" err msg, I have three questions revolving around what I see here:
The verbiage below Microsoft.Windows.SDK.Contracts says I can update versions of this package - should I?
I do not see a Reference to Microsoft.Windows.SDK.Contracts in my project's References, although it has been installed. Do I need to add one - if so, from where?
The context menu on my References affords me the ability to "Migrate packages.config to PackageReference..." should I do that?

If you were developing an uwp application, for opening open a web uri, it is recommended to use Launcher.LaunchUriAsync(Uri) method instead, this method starts the default browser to open the specified URI.
For example:
private async void button_Click(object sender, RoutedEventArgs e)
{
Uri uri = new Uri("http://www.google.com");
await Windows.System.Launcher.LaunchUriAsync(uri);
}
Update:
As Codexer mentioned, you could refer to this document to use uwp api in winform app.
I have created a winform project, its target framework is .Net Framework4.8. For earlier versions of .NET(.NET Core 3.x, .NET 5 Preview 7 (or earlier), or .NET Framework), you could refer to my steps.
1.Click Tools->NuGet Package Manager-> Package Manager Settings-> Change Default package management format to PackageReference. As follows:
2.Install the Microsoft.Windows.SDK.Contracts package, note that you need to install the appropriate version. Please check the corresponding version below. (Installation details: Right click Reference-> Manage NuGet Packages->Browse->Search Microsoft.Windows.SDK.Contracts->install)
10.0.19041.xxxx: Choose this for Windows 10, version 2004, version 20H2
10.0.18362.xxxx: Choose this for Windows 10, version 1903.
10.0.17763.xxxx: Choose this for Windows 10, version 1809.
10.0.17134.xxxx: Choose this for Windows 10, version 1803.
3.Run the project

Related

Unable to find an entry point named 'sk_color_get_bit_shift' in DLL 'libSkiaSharp'. when using SkiaSharp 15.9.1

I am attempting to build and use the MicoCharts project available here: https://github.com/dotnet-ad/Microcharts which is dependant on this SkiaSharp project available here: https://github.com/mono/SkiaSharp
The specific version I am attempting to use is 15.9.1 (the version that the nuget package downloads) which utilizes skia m59.
I need to build them myself and cannot use Nuget due to business restrictions, just use the package isn't an option for me.
I have built skia m59, SkiaSharp and MicroCharts but when I attempt to create a SKBitmap object I get an error when it attempts to initialize SkiaSharp.SKImageInfo. The error is as follows:
Unable to find an entry point named 'sk_color_get_bit_shift' in DLL 'libSkiaSharp'.
I had to make a few changes to the base BUILD.gn to point to the correct file locations, for the windows SDK and the VC install. I enabled skia_use_gdi in the BUILD.gn and ran the following commands.
python2 tools/git-sync-deps
gn gen out/Release --args="is_debug=false is_official_build=true skia_use_system_expat=false skia_use_system_libjpeg_turbo=false skia_use_system_libpng=false skia_use_system_libwebp=false skia_use_system_zlib=false skia_use_icu=false is_component_build=true"
ninja -C out/Release skia
This process outputs a DLL I assumed is the same as the libSkiaSharp that the SkiaSharp project relies on. I add all my references and run, the project runs successfully until I attempt to create the SkBitmap object then it fails.
Either this DLL is not the correct DLL and I am misunderstanding something here or something in my process is wrong. I would love any help I can get as I am completely new to building these sorts of projects, I am a C# developer by trade.
This is not the same thing. SkiaSharp has a few other bits that it adds to the core skia. The output that you would have got is a skia.dll, which only part. Not sure how you got a libSkiaSharp from the skia target...
If you can't use SkiaSharp from NuGet.org (which is the supported case) you can follow this to build your own: https://github.com/mono/SkiaSharp/wiki/Building-SkiaSharp
You can also check out the Azure DevOps yaml: https://github.com/mono/SkiaSharp/blob/master/scripts/azure-pipelines.yml
Just set up your own DevOps job to use that and all the work will be done for you.

Stores and C# assembly dll files not being loaded

I have recently tried adding In App Purchase into my Unity project. Unfortunately, it didn't show in the Components drop down menu. I could use the option to create IAP Button and perform code-less IAP configuration but it wasn't there in the menu. So I decided to configure IAP through script. But the script too throws some errors. The error goes like this:
"Assembly 'Library/ScriptAssemblies/Assembly-CSharp-firstpass.dll' will not be loaded due to errors: Reference has errors 'Stores'."
Four errors just like the above one shows up for Assembly-CSharp.dll, Editor.dll and Assembly-CSharp-firstpass.dll
And then this one:
"Assembly 'Assets/Plugins/UnityPurchasing/Bin/Stores.dll' will not be loaded due to errors:
Unable to resolve reference 'UnityEngine.UI'. Is the assembly missing or incompatible with the current platform?
Reference validation can be disabled in the Plugin Inspector."
I have tried re-installing In App Purchase package.
I have tried changing the API from .NET Standard 2.0 to .NET 4.x (and did the vice versa and still did not work)
Downgrading unity project isn't really a good idea but anyways I gave it a try but it just added to the already existing errors.
Upgrading to newer Unity version (alpha version) didn't help.
The error occurs whenever I initialize the ConfigurationBuilder referring StandardPurchasingModule.
public void InitializePurchasing()
{
// If we have already connected to Purchasing ...
if (IsInitialized())
{
// ... we are done here.
return;
}
var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
builder.AddProduct(TWO_BOLTS, ProductType.Consumable);
builder.AddProduct(FIVE_BOLTS, ProductType.NonConsumable);
UnityPurchasing.Initialize(this, builder);
}
The worst part is that I am unable to use my scripts after writing the ConfigurationBuilder initialization code. Unity asks me to fix any compiler errors and assign a valid script. I have searched for the answer for so long. I am really stuck in here. Please help.
Your issue seems to be related to verison of Unity you using. You can follow progress of this issue on official Unity issue tracker.
If this issue is showstopper for you than cosider downgrading as you using beta verions of Unity and as official site states:
As with any beta program, you’ll have early access to new features and
will be able to assist in the final steps of their development. That
means you’re likely to experience Unity as less stable than a final
version.

SQLite removing reference on rebuild

SQL Lite states that its added support for Xamrian Forms and .net standard and yet when I rebuild my project all references disappear what it the correct library I need to get SQL lite working in .net standard 2.0 I am using it to sync between a mobile app and the server.
public async Task SyncAllDeliverys()
{
Task<string> callTask = Task.Run(() => GetDeliverysFromAPi());
// Wait for it to finish
callTask.Wait();
// Get the result
string content = callTask.Result;
//Sends a GET request to the specified Uri and returns the response body as a string in an asynchronous operation
deliverysItems = JsonConvert.DeserializeObject<List<DeliverysItems>>(content); //Deserializes or converts JSON String into a collection of Post
SQLiteAsyncConnection conn = new SQLiteAsyncConnection(dbPath);
await conn.InsertAllAsync(deliverysItems);
}
As you see here my project is .net standard 2.0
Edit 2
To show the correct version that I have installed instead of the incorrect one I showed in the first graphic.
Edit 2
It would appear that this is a known bug and xamrian has submitted it as such in 2019 visual studio.
https://github.com/xamarin/Xamarin.Forms/issues/5983
You are looking at the wrong description of dependencies. The dependencies in the first screenshot(you circled in the right bottom) belongs to sqlite-net-pcl instead of SQLite.Net-PCL.
Package 'SQLite.Net-PCL 3.1.1' was restored using
'.NETFramework,Version=v4.6.1'.
You can try uninstall and install sqlite-net-pcl nuget, clean and rebuild your project.
what it the correct library I need to get SQL lite working in .net
standard 2.0
Use sqlite-net-pcl is the right way. (The fourth library in your screenshot).
There are a number of NuGet packages with similar names, the correct package has these attributes:
Created by: Frank A. Krueger
Id: sqlite-net-pcl
NuGet link: sqlite-net-pcl
Refer: databases

Differences between versions of Microsoft.TeamFoundation.Client libraries - ComboTree.SetSelectedText(System.String) is missing

I have an issue with my code that connect to TFS/VSTS and writes work items from it.
public FormSearchWorkItems(WorkItemStore workItemStore, string projectName)
{
InitializeComponent();
WorkingItem = new WorkingItem();
pickWorkItemsControl = new PickWorkItemsControl(workItemStore, false);
}
It worked well with TFS using old version of Microsoft.TeamFoundation.Client (12.0.0.0), but after an update to the newest Microsoft.TeamFoundation.Client (15.0.0.0), there is an expection for PickWorkItemsControl throwed:
An unhandled exception of type 'System.MissingMethodException' occurred in Microsoft.TeamFoundation.WorkItemTracking.Controls.dll
Additional information: Method not found: Void Microsoft.TeamFoundation.Client.ComboTree.SetSelectedText(System.String).
So the problem is that there is missing SetSelectedText(System.string) method in the newest version of Microsoft.TeamFoundation.Client.dll
Does anyone know the workaround of this problem please?
The method Microsoft.TeamFoundation.Client.ComboTree.SetSelectedText is not exist in the 15.0.0 version.
You can install latest version of Microsoft.TeamFoundationServer.ExtendedClient package, and then build again. This package contains all the reference you used. And you can develop the similar method by yourself.
Integrate with Microsoft Team Foundation Server and Visual Studio Team
Services from desktop-based Windows applications. Work with and manage
version control, work items, and build, and other resources from your
client application.

Is it possible to use Wi-Fi Direct from a non Universal application?

I've been trying to code a simple command-line based application (using C# and .NET from Visual Studio 2015 and Windows 10) to start a Wi-Fi Direct advertiser following Microsoft's Universal Samples, but manually adding references to the necessary *.dll and *.winmd assemblies instead of creating a UniversalWindowsPlatform project. (System.Runtime.WindowsRuntime from Refference Assemblies and Windows from Windows Kits\10\Union Metadata\Windows.winmd)
This is the relevant code:
public void StartAdvertisement(WiFiDirectAdvertisementListenStateDiscoverability discoverability,
bool listenToConnections)
{
if (mPublisher == null)
mPublisher = new WiFiDirectAdvertisementPublisher();
if (listenToConnections)
{
mListener = new WiFiDirectConnectionListener();
mListener.ConnectionRequested += OnConnectionRequested;
}
mPublisher.StatusChanged += OnStatusChanged;
mPublisher.Advertisement.IsAutonomousGroupOwnerEnabled = true;
mPublisher.Advertisement.ListenStateDiscoverability = discoverability;
mPublisher.Start();
}
async void OnConnectionRequested(WiFiDirectConnectionListener sender,
WiFiDirectConnectionRequestedEventArgs connectionEventArgs)
{
// Connection code
}
The advertiser starts OK (it can be found from other devices, and it creates the necessary network interface), but the OnConnectionRequested method doesn't get called when other devices attempt to connect. I've seen that for using Wi-Fi Direct, an Universal Windows Application must add to its manifest the proximity capability, but for a generic application, there is no manifest.
Can I use the Windows 10 WiFi Direct API from a non-universal Windows application only by referencing the necessary assemblies?
So, I finally could use the WinRT APIs (including the Wi-Fi Direct ones even without a manifest declaring the proximity capability use) from a non-Universal Windows application, but in Windows 10 is a little bit trickier than in 8 or 8.1.
Once you edit the *.csproj of your project to add the following line inside the group...
<TargetPlatformVersion>10.0.10240.0</TargetPlatformVersion>
you'll see a new section inside the Reference Manager called Windows, with winmd libraries. None of them will be useful, all you probably need is inside two libraries that you'll have to add browsing:
C:\Program Files (x86)\Windows Kits\10\Union Metadata\Windows.winmd
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5\System.Runtime.WindowsRuntime.dll
With those two references you'll avoid problems like
'The type XXXX is defined in an assembly that is not referenced'
or
'The namespace XXXX is defined in two different assemblies'.
But we're not done yet! Particularly in Wi-Fi Direct, once the advertiser is, you know, advertising, and some other computer attempts to connect, if you have an instance of WiFiDirectConnectionListener, the following method should be called
async void OnConnectionRequested(WiFiDirectConnectionListener sender, WiFiDirectConnectionRequestedEventArgs connectionEventArgs)
but instead you get a System.BadImageFormatException. That's because the System.Runtime.WindowsRuntime.dll actual version differs somehow from the one declared in its manifest, so it can't be loaded.
Open the properties tool in Visual Studio, select the System.Runtime.WindowsRuntime reference and change the following properties: Copy Local to false and Specific Version to true.
Now it should work!

Categories