Click here to Skip to main content
15,890,690 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralC# interpolated string, JavaScript template literal Pin
raddevus29-Oct-18 2:58
mvaraddevus29-Oct-18 2:58 
GeneralRe: C# interpolated string, JavaScript template literal Pin
  Forogar  29-Oct-18 3:08
professional  Forogar  29-Oct-18 3:08 
GeneralRe: C# interpolated string, JavaScript template literal Pin
raddevus29-Oct-18 3:21
mvaraddevus29-Oct-18 3:21 
GeneralRe: C# interpolated string, JavaScript template literal Pin
Marc Clifton29-Oct-18 4:22
mvaMarc Clifton29-Oct-18 4:22 
GeneralRe: C# interpolated string, JavaScript template literal Pin
raddevus29-Oct-18 4:52
mvaraddevus29-Oct-18 4:52 
GeneralRe: C# interpolated string, JavaScript template literal Pin
Richard Deeming29-Oct-18 8:52
mveRichard Deeming29-Oct-18 8:52 
GeneralRe: C# interpolated string, JavaScript template literal Pin
raddevus29-Oct-18 10:00
mvaraddevus29-Oct-18 10:00 
GeneralVisual Studio and XML command line parameters Pin
PIEBALDconsult25-Oct-18 19:20
mvePIEBALDconsult25-Oct-18 19:20 
(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:
XML
"<ArgTest><Parameter>Value</Parameter></ArgTest>"


In ArgTest.csproj.user, it looks good:
XML
<StartArguments>"<ArgTest><Parameter>Value</Parameter></ArgTest>"</StartArguments>


And on first run, the output is good:
XML
<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:
XML
"<ArgTest xmlns="http://schemas.microsoft.com/developer/msbuild/2003"><Parameter>Value</Parameter></ArgTest>"

<ArgTest xmlns=http://schemas.microsoft.com/developer/msbuild/2003><Parameter>Value</Parameter></ArgTest>
'http' is an unexpected token. The expected token is '"' or '''. Line 1, position 16.
"c:\Project\ArgTest\bin\Debug\ArgTest.exe" "<ArgTest xmlns="http://schemas.microsoft.com/developer/msbuild/2003"><Parameter>Value</Parameter></ArgTest>"
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.

C#
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 ) ;
        }
      }
      catch ( System.Exception err )
      {
        System.Console.WriteLine ( err.Message ) ;
      }

      try
      {
        System.Console.WriteLine ( System.Environment.CommandLine ) ;

        int s = System.Environment.CommandLine.IndexOf ( "\"<" ) + 1 ;
        int e = System.Environment.CommandLine.IndexOf ( ">\"" ) + 1;

        doc.LoadXml ( System.Environment.CommandLine.Substring ( s , e - s ) ) ;

        System.Xml.XmlNode val = doc.DocumentElement.SelectSingleNode ( "Parameter" ) ;

        if ( val == null )
        {
          System.Console.WriteLine ( "Not found" ) ;
        }
        else
        {
          System.Console.WriteLine ( val.InnerText ) ;
        }
      }
      catch ( System.Exception err )
      {
        System.Console.WriteLine ( err.Message ) ;
      }

      return ( result ) ;
    }
  }
}

GeneralRe: Visual Studio and XML command line parameters Pin
Richard Deeming26-Oct-18 1:05
mveRichard Deeming26-Oct-18 1:05 
GeneralRe: Visual Studio and XML command line parameters Pin
PIEBALDconsult26-Oct-18 4:58
mvePIEBALDconsult26-Oct-18 4:58 
GeneralCodePen: Adventure Game only CSS & HTML (no JS) Pin
raddevus23-Oct-18 5:18
mvaraddevus23-Oct-18 5:18 
GeneralRe: CodePen: Adventure Game only CSS & HTML (no JS) Pin
Richard Deeming23-Oct-18 7:38
mveRichard Deeming23-Oct-18 7:38 
GeneralRe: CodePen: Adventure Game only CSS & HTML (no JS) Pin
raddevus23-Oct-18 9:00
mvaraddevus23-Oct-18 9:00 
GeneralRe: CodePen: Adventure Game only CSS & HTML (no JS) Pin
Richard Deeming23-Oct-18 11:40
mveRichard Deeming23-Oct-18 11:40 
GeneralRe: CodePen: Adventure Game only CSS & HTML (no JS) Pin
Richard Deeming25-Oct-18 4:16
mveRichard Deeming25-Oct-18 4:16 
GeneralRe: CodePen: Adventure Game only CSS & HTML (no JS) Pin
raddevus25-Oct-18 7:40
mvaraddevus25-Oct-18 7:40 
AnswerRe: CodePen: Adventure Game only CSS & HTML (no JS) Pin
ZurdoDev25-Oct-18 8:26
professionalZurdoDev25-Oct-18 8:26 
GeneralRe: CodePen: Adventure Game only CSS & HTML (no JS) Pin
Richard Deeming25-Oct-18 8:31
mveRichard Deeming25-Oct-18 8:31 
GeneralLet's REALLY make sure "4" isn't "5" PinPopular
Marc Clifton17-Oct-18 2:39
mvaMarc Clifton17-Oct-18 2:39 
GeneralRe: Let's REALLY make sure "4" isn't "5" Pin
gardnerp17-Oct-18 3:10
gardnerp17-Oct-18 3:10 
GeneralRe: Let's REALLY make sure "4" isn't "5" Pin
Marc Clifton17-Oct-18 5:50
mvaMarc Clifton17-Oct-18 5:50 
GeneralRe: Let's REALLY make sure "4" isn't "5" Pin
kalberts18-Oct-18 1:35
kalberts18-Oct-18 1:35 
GeneralRe: Let's REALLY make sure "4" isn't "5" Pin
CHill6019-Oct-18 6:17
mveCHill6019-Oct-18 6:17 
GeneralRe: Let's REALLY make sure "4" isn't "5" Pin
ZurdoDev25-Oct-18 8:28
professionalZurdoDev25-Oct-18 8:28 
GeneralRe: Let's REALLY make sure "4" isn't "5" Pin
Dr.Walt Fair, PE1-Nov-18 5:14
professionalDr.Walt Fair, PE1-Nov-18 5:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.