How to validate an URI ?
-
EDI : Fixed by changing the pack with "mx-appx" as per documentation example. Is there a way to check or validate if an URI is valid ? The Assets folder is in my solution
System.Uri icon = new System.Uri("pack://application:,,,/Assets/icon.png");
This is part of this code which crashes at the instantiation of the ToastCollection.
public async void CreateToastCollection()
{
string displayName = "Is Potato";
string launchArg = "NavigateToPotato";
System.Uri icon = new System.Uri("pack://application:,,,/Assets/icon.png");// **CRASH here** ToastCollection licensingManagerToastCollection = new ToastCollection( "MyToastCollection", displayName, launchArg, icon); // Calls the platform to create the collection await ToastNotificationManager.GetDefault().GetToastCollectionManager().SaveToastCollectionAsync(licensingManagerToastCollection); }
Thanks.
CI/CD = Continuous Impediment/Continuous Despair
-
EDI : Fixed by changing the pack with "mx-appx" as per documentation example. Is there a way to check or validate if an URI is valid ? The Assets folder is in my solution
System.Uri icon = new System.Uri("pack://application:,,,/Assets/icon.png");
This is part of this code which crashes at the instantiation of the ToastCollection.
public async void CreateToastCollection()
{
string displayName = "Is Potato";
string launchArg = "NavigateToPotato";
System.Uri icon = new System.Uri("pack://application:,,,/Assets/icon.png");// **CRASH here** ToastCollection licensingManagerToastCollection = new ToastCollection( "MyToastCollection", displayName, launchArg, icon); // Calls the platform to create the collection await ToastNotificationManager.GetDefault().GetToastCollectionManager().SaveToastCollectionAsync(licensingManagerToastCollection); }
Thanks.
CI/CD = Continuous Impediment/Continuous Despair
Have you tried Uri.TryCreate Method (System) | Microsoft Docs[^] - I haven't either, but ...
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!
-
EDI : Fixed by changing the pack with "mx-appx" as per documentation example. Is there a way to check or validate if an URI is valid ? The Assets folder is in my solution
System.Uri icon = new System.Uri("pack://application:,,,/Assets/icon.png");
This is part of this code which crashes at the instantiation of the ToastCollection.
public async void CreateToastCollection()
{
string displayName = "Is Potato";
string launchArg = "NavigateToPotato";
System.Uri icon = new System.Uri("pack://application:,,,/Assets/icon.png");// **CRASH here** ToastCollection licensingManagerToastCollection = new ToastCollection( "MyToastCollection", displayName, launchArg, icon); // Calls the platform to create the collection await ToastNotificationManager.GetDefault().GetToastCollectionManager().SaveToastCollectionAsync(licensingManagerToastCollection); }
Thanks.
CI/CD = Continuous Impediment/Continuous Despair
If it's actually crashing on the
new ToastCollection
line, then the URI is valid - otherwise, thenew Uri
line would crash. TheToastCollection
probably doesn't supportpack:
URIs. But that's just a guess, since you haven't provided any details of the error.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Have you tried Uri.TryCreate Method (System) | Microsoft Docs[^] - I haven't either, but ...
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!
-
The docs say Uri.TryCreate is for .Net 7 and higher. You could try Uri.IsWellFormedUriString (Uri.IsWellFormedUriString(String, UriKind) Method (System) | Microsoft Docs[^]) which covers a wider range of .Net versions.
No it doesn't. The docs for Uri.TryCreate go all the way back to .NET Framework 1.1.
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave Kreskowiak -
If it's actually crashing on the
new ToastCollection
line, then the URI is valid - otherwise, thenew Uri
line would crash. TheToastCollection
probably doesn't supportpack:
URIs. But that's just a guess, since you haven't provided any details of the error.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
I think the error was at the URI statement, I checked the [documentation](https://docs.microsoft.com/en-us/windows/apps/design/shell/tiles-and-notifications/toast-collections) (well, :-O duh) and they use "ms-appx:" instead. Still having errors on related code. Will ask another question. Thanks
CI/CD = Continuous Impediment/Continuous Despair
-
I think the error was at the URI statement, I checked the [documentation](https://docs.microsoft.com/en-us/windows/apps/design/shell/tiles-and-notifications/toast-collections) (well, :-O duh) and they use "ms-appx:" instead. Still having errors on related code. Will ask another question. Thanks
CI/CD = Continuous Impediment/Continuous Despair
According to the documentation[^],
Toast
images only support the following URI schemas:http://
orhttps://
file:///
ms-appx:///
ms-appdata:///local/
WPF-style
pack:
URIs are not supported.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
According to the documentation[^],
Toast
images only support the following URI schemas:http://
orhttps://
file:///
ms-appx:///
ms-appdata:///local/
WPF-style
pack:
URIs are not supported.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
Thanks, I missed that one.:rose:
CI/CD = Continuous Impediment/Continuous Despair