Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to validate an URI ?

How to validate an URI ?

Scheduled Pinned Locked Moved C#
tutorialdevopsquestion
8 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Maximilien
    wrote on last edited by
    #1

    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

    OriginalGriffO Richard DeemingR 2 Replies Last reply
    0
    • M Maximilien

      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

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      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!

      "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

      J 1 Reply Last reply
      0
      • M Maximilien

        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

        Richard DeemingR Offline
        Richard DeemingR Offline
        Richard Deeming
        wrote on last edited by
        #3

        If it's actually crashing on the new ToastCollection line, then the URI is valid - otherwise, the new Uri line would crash. The ToastCollection probably doesn't support pack: 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

        "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

        M 1 Reply Last reply
        0
        • OriginalGriffO OriginalGriff

          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!

          J Offline
          J Offline
          jsc42
          wrote on last edited by
          #4

          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.

          D 1 Reply Last reply
          0
          • J jsc42

            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.

            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            • Richard DeemingR Richard Deeming

              If it's actually crashing on the new ToastCollection line, then the URI is valid - otherwise, the new Uri line would crash. The ToastCollection probably doesn't support pack: 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

              M Offline
              M Offline
              Maximilien
              wrote on last edited by
              #6

              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

              Richard DeemingR 1 Reply Last reply
              0
              • M Maximilien

                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

                Richard DeemingR Offline
                Richard DeemingR Offline
                Richard Deeming
                wrote on last edited by
                #7

                According to the documentation[^], Toast images only support the following URI schemas:

                • http:// or https://
                • 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

                "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                M 1 Reply Last reply
                0
                • Richard DeemingR Richard Deeming

                  According to the documentation[^], Toast images only support the following URI schemas:

                  • http:// or https://
                  • 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

                  M Offline
                  M Offline
                  Maximilien
                  wrote on last edited by
                  #8

                  Thanks, I missed that one.:rose:

                  CI/CD = Continuous Impediment/Continuous Despair

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups