Click here to Skip to main content
15,511,353 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.

 
GeneralRe: Another ancient oddity in .net Pin
Dave DD12-Sep-22 9:16
Dave DD12-Sep-22 9:16 
GeneralRe: Another ancient oddity in .net Pin
Thornik12-Sep-22 9:26
Thornik12-Sep-22 9:26 
GeneralRe: Another ancient oddity in .net Pin
Dave DD12-Sep-22 9:45
Dave DD12-Sep-22 9:45 
GeneralRe: Another ancient oddity in .net Pin
F Margueirat12-Sep-22 12:02
F Margueirat12-Sep-22 12:02 
GeneralRe: Another ancient oddity in .net Pin
obermd12-Sep-22 4:58
obermd12-Sep-22 4:58 
GeneralRe: Another ancient oddity in .net Pin
PIEBALDconsult12-Sep-22 5:35
professionalPIEBALDconsult12-Sep-22 5:35 
GeneralRe: Another ancient oddity in .net Pin
Gerry Schmitz12-Sep-22 8:35
mveGerry Schmitz12-Sep-22 8:35 
GeneralC# 6, you dirty dog! Pin
PIEBALDconsult27-Aug-22 10:57
professionalPIEBALDconsult27-Aug-22 10:57 
OK, so after my earlier post, I found that I was compiling with C# 6 turned on without realizing it.
I prefer to use new features of C# only if they offer me something useful. I use only a few features of C# 3, and no newer features than that, so I want my code to compile with C# 3 selected, but I hadn't been bothering to specify it, I had left it set to the default (my fault of course).
So yesterday I spent some time ensuring that my libraries and utilities will compile with C# 3.


And BOOM! one of my recent utilities complained:
error CS0840: '[REDACTED].CommonBase.ScriptXML.get' must declare a body because it is not marked abstract or extern. Automatically implemented properties must define both get and set accessors.
and
error CS8026: Feature 'readonly automatically implemented properties' is not available in C# 3. Please use language version 6 or greater.
(Messages from two versions of CSC.EXE . I'm not sure which is the more helpful.)

It turns out that a few months back, I had made a copy/paste error. I had intended to write:
public System.Xml.XmlNode ScriptXML { get ; private set ; }
but, because I had copied:
System.Xml.XmlNode ScriptXML { get ; }
from an Interface definition, I wound up with:
public System.Xml.XmlNode ScriptXML { get ; }
I had forgotten to add the private set ; (or do I want it protected?) and the compiler (set to C# 6) was fine with it! Elephant | [mastadon] !

Yeah, OK, so it's not actually a bug, but it's a coding error and I wish I had been alerted to it when I first wrote it.
Going forward, I am specifying /langversion:3 until I find a useful feature of some future version.


Bonus: My work laptop has these two versions of CSC.EXE:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe Supports up to C# 5
C:\Program Files (x86)\MSBuild\14.0\Bin\csc.exe Supports up to C# 6
and, of course, I had been using the newer version (as you do). I expect the newer version was installed in the past month.
But I found that utilities compiled with the newer version won't run on the servers, so I had to revert to using the older version when I compile on the command line, which is the norm for my utilities.
Yes, I do use Visual Studio (2015) on occasion, but not for making release builds of command-line utilities to deploy to the servers.
GeneralRe: C# 6, you dirty dog! Pin
Richard Deeming29-Aug-22 22:15
mveRichard Deeming29-Aug-22 22:15 
GeneralRe: C# 6, you dirty dog! Pin
PIEBALDconsult30-Aug-22 4:35
professionalPIEBALDconsult30-Aug-22 4:35 
GeneralRe: C# 6, you dirty dog! Pin
James Curran1-Sep-22 1:04
James Curran1-Sep-22 1:04 
GeneralRe: C# 6, you dirty dog! Pin
jochance1-Sep-22 6:47
jochance1-Sep-22 6:47 
GeneralRe: C# 6, you dirty dog! Pin
englebart1-Sep-22 7:55
professionalenglebart1-Sep-22 7:55 
GeneralRe: C# 6, you dirty dog! Pin
PIEBALDconsult1-Sep-22 8:00
professionalPIEBALDconsult1-Sep-22 8:00 
GeneralTwo of my most frequent issues with .net inconsistencies Pin
PIEBALDconsult24-Aug-22 11:28
professionalPIEBALDconsult24-Aug-22 11:28 
GeneralRe: Two of my most frequent issues with .net inconsistencies Pin
MarkTJohnson24-Aug-22 11:31
professionalMarkTJohnson24-Aug-22 11:31 
GeneralRe: Two of my most frequent issues with .net inconsistencies Pin
Greg Utas24-Aug-22 12:29
mveGreg Utas24-Aug-22 12:29 
GeneralRe: Two of my most frequent issues with .net inconsistencies Pin
PIEBALDconsult24-Aug-22 12:37
professionalPIEBALDconsult24-Aug-22 12:37 
GeneralRe: Two of my most frequent issues with .net inconsistencies Pin
Greg Utas24-Aug-22 14:35
mveGreg Utas24-Aug-22 14:35 
GeneralRe: Two of my most frequent issues with .net inconsistencies Pin
englebart1-Sep-22 7:59
professionalenglebart1-Sep-22 7:59 
GeneralRe: Two of my most frequent issues with .net inconsistencies Pin
Richard Deeming24-Aug-22 23:06
mveRichard Deeming24-Aug-22 23:06 
GeneralRe: Two of my most frequent issues with .net inconsistencies Pin
PIEBALDconsult25-Aug-22 4:21
professionalPIEBALDconsult25-Aug-22 4:21 
GeneralRe: Two of my most frequent issues with .net inconsistencies Pin
Richard Deeming25-Aug-22 6:05
mveRichard Deeming25-Aug-22 6:05 
GeneralRe: Two of my most frequent issues with .net inconsistencies Pin
PIEBALDconsult25-Aug-22 8:40
professionalPIEBALDconsult25-Aug-22 8:40 
GeneralRe: Two of my most frequent issues with .net inconsistencies Pin
Bernhard Hiller25-Aug-22 22:09
Bernhard Hiller25-Aug-22 22:09 

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.