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. Other Discussions
  3. The Weird and The Wonderful
  4. Visual Studio and XML command line parameters

Visual Studio and XML command line parameters

Scheduled Pinned Locked Moved The Weird and The Wonderful
visual-studiotutorialcsharpdebuggingxml
3 Posts 2 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.
  • P Offline
    P Offline
    PIEBALDconsult
    wrote on last edited by
    #1

    (Yes, I meant to put this here, no real reason.) I discovered this this week. Unsure anyone else has noticed it or has any idea of how to avoid it. I'm working on a command-line program which will require XML in a parameter. I stored an example XML parameter in VS (2010 and 2015) for debugging. It seemed OK the first day, but things went awry when I ran it the following day. This evening I whipped up a little demonstration. I set the debug parameter such:

    "<ArgTest><Parameter>Value</Parameter></ArgTest>"

    In ArgTest.csproj.user, it looks good:

    <StartArguments>"<ArgTest><Parameter>Value</Parameter></ArgTest>"</StartArguments>

    And on first run, the output is good:

    <ArgTest><Parameter>Value</Parameter></ArgTest>
    Value
    "c:\Project\ArgTest\bin\Debug\ArgTest.exe" "<ArgTest><Parameter>Value</Parameter></ArgTest>"
    Value

    But, save, close, and re-open the solution, and the parameter somehow gains a default namespace which then gets mangled by the system:

    "Value"

    Value
    'http' is an unexpected token. The expected token is '"' or '''. Line 1, position 16.
    "c:\Project\ArgTest\bin\Debug\ArgTest.exe" "Value"
    Not found

    Some of you will be surprised by the "Not found", but I'm not, I expected it once I saw the problem. Obviously, Visual Studio saves the .user file inappropriately, but that doesn't explain the addition of the namespace. Very weird.

    namespace CP
    {
    public static partial class ArgTest
    {
    static int
    Main
    (
    string[] args
    )
    {
    int result = 0 ;

      System.Xml.XmlDocument doc = new System.Xml.XmlDocument() ;
    
      try
      {
        System.Console.WriteLine ( args \[ 0 \] ) ;
      
        doc.LoadXml ( args \[ 0 \] ) ;
    
        System.Xml.XmlNode val = doc.DocumentElement.SelectSingleNode ( "Parameter" ) ;
    
        if ( val == null )
        {
          System.Console.WriteLine ( "Not found" ) ;
        }
        else
        {
          System.Console.WriteLine ( val.InnerText ) ;
        }
      }
    
    Richard DeemingR 1 Reply Last reply
    0
    • P PIEBALDconsult

      (Yes, I meant to put this here, no real reason.) I discovered this this week. Unsure anyone else has noticed it or has any idea of how to avoid it. I'm working on a command-line program which will require XML in a parameter. I stored an example XML parameter in VS (2010 and 2015) for debugging. It seemed OK the first day, but things went awry when I ran it the following day. This evening I whipped up a little demonstration. I set the debug parameter such:

      "<ArgTest><Parameter>Value</Parameter></ArgTest>"

      In ArgTest.csproj.user, it looks good:

      <StartArguments>"<ArgTest><Parameter>Value</Parameter></ArgTest>"</StartArguments>

      And on first run, the output is good:

      <ArgTest><Parameter>Value</Parameter></ArgTest>
      Value
      "c:\Project\ArgTest\bin\Debug\ArgTest.exe" "<ArgTest><Parameter>Value</Parameter></ArgTest>"
      Value

      But, save, close, and re-open the solution, and the parameter somehow gains a default namespace which then gets mangled by the system:

      "Value"

      Value
      'http' is an unexpected token. The expected token is '"' or '''. Line 1, position 16.
      "c:\Project\ArgTest\bin\Debug\ArgTest.exe" "Value"
      Not found

      Some of you will be surprised by the "Not found", but I'm not, I expected it once I saw the problem. Obviously, Visual Studio saves the .user file inappropriately, but that doesn't explain the addition of the namespace. Very weird.

      namespace CP
      {
      public static partial class ArgTest
      {
      static int
      Main
      (
      string[] args
      )
      {
      int result = 0 ;

        System.Xml.XmlDocument doc = new System.Xml.XmlDocument() ;
      
        try
        {
          System.Console.WriteLine ( args \[ 0 \] ) ;
        
          doc.LoadXml ( args \[ 0 \] ) ;
      
          System.Xml.XmlNode val = doc.DocumentElement.SelectSingleNode ( "Parameter" ) ;
      
          if ( val == null )
          {
            System.Console.WriteLine ( "Not found" ) ;
          }
          else
          {
            System.Console.WriteLine ( val.InnerText ) ;
          }
        }
      
      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      Seems like you need to manually edit the .csproj.user file to wrap the arguments in a CDATA section: Visual Studio changes debug xml Command line arguments - Stack Overflow[^] Unfortunately, you'll have to repeat that every time you change a project setting.


      "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

      P 1 Reply Last reply
      0
      • Richard DeemingR Richard Deeming

        Seems like you need to manually edit the .csproj.user file to wrap the arguments in a CDATA section: Visual Studio changes debug xml Command line arguments - Stack Overflow[^] Unfortunately, you'll have to repeat that every time you change a project setting.


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

        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #3

        This program doesn't warrant that amount of effort. :D I'll have to ensure that my command line parser can remove the namespace when present, but this program doesn't use that anyway.

        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