views:

1295

answers:

29

What .NET issue have you run into that wasted hours and hours of your time, was nearly impossible to debug, and could have been easily avoided if you had known just one quirk of the framework?

+4  A: 

Not really specific to .NET: threading.

jop
How does knowing one simple quirk let you overcome the difficulties of threading? Please tell me the quirk, so I don't have to deal with debugging threads anymore.
Kibbee
+5  A: 

I've spent many nights wondering why System.Xml.Xslt.XsltLoadException is an internal class, when XsltCompiledTransform.Load() throws it in the event that the XSLT you supply it is malformed or contains a syntax error.

Chris
+3  A: 

For ASP.net, if you ever happen to override the Render event for a page, but the page uses Response.Write in the HTML itself... well, get ready to spend some hours trying to figure out why it never shows up in the right place...

Hugoware
+9  A: 

Returning a DataTable over a WCF service without naming the DataTable. The default constructor, DataTable dt = new DataTable(); will leave the DataTable unnamed and unnamed DataTables are not serializable. Instead of receiving a serialization error, testing my service gave only a "Connection forcibly closed by host" exception.

foson
It's not a serialization error. The host receiving the serialize DatTable closed the connection before WCF could transmit it.
Chris
Try this:using (MemoryStream ms = new MemoryStream()){ XmlSerializer xs = new XmlSerializer(typeof(DataTable)); DataTable dt = new DataTable(); xs.Serialize(ms, dt);} then try DataTable dt = new DataTable("t1");WCF may not use XmlSerializer, but the principle is the same.
foson
I'm just saying... the serialization and IOException or SocketException you're referring to (I know, I've gotten them too) have nothing to do with the serialization. :)
Chris
Is this a problem with web services, too? I've always had to return datasets because (I thought) datatables weren't serializable. Was the problem actually that I wasn't naming them?
MusiGenesis
I actually posted a question on this topic: http://stackoverflow.com/questions/12702/net-returning-datatables-in-wcfTook me forever to realize what was going on, too.
theprise
@MusiGenesis: Given that DataSets use DataTables to actually store data, if DataTables weren't serializable, neither would DataSets be.
technophile
+1  A: 

It was a while ago but I wasted a lot of time trying to properly bind nested objects to a web form.

I think I eventually found a way to get it working using the CslaDataSource, but that required using the CSLA.NET framework.

Mike Henry
+7  A: 

Took me several hours to figure out this exception: "A generic error occurred in GDI+" when saving a bitmap - turns out that if you load a bitmap from a stream, then dispose of the stream, then you'll get this error when you call bitmap.Save(). Dispose of the stream after saving, if you can.

Erik Forbes
indeed. This error can actually refer to many things. I have had similar situation, except in my case it was running out of memory.
mattlant
Yeah, the Interop.ExternalException (which is the message you cite) can result anyway. We have a program generating thumbnails 24/7 and out of about 50,000 items, a couple to few will throw this error.
Chris
+3  A: 

The XmlDocument class in System.Xml.

If there is a DOCTYPE declaration on the first line of an HTML document, the XmlDocument tries to get the definition. This is an undocumented "feature" if I remember correctly which is useless for HTML. It doesn't seem to do the same for XML namespace URLs however.

This caused problems for me when generating several HTML reports that had to parse an existing HTML document. On my company's slow network, the DOCTYPE lookup was painfully slow. It was so slow I added a loading dialog just so that the user would know how long they had left.

When the app. was run without an internet connection, the DOCTYPE lookup would throw an exception which was not documented in the MSDN documentation.

The final solution was to read the file in as test, check if there was a doctype and remove it, then load the file as XML. This made the app. so fast that the loading dialog I wrote became useless. It would flash on the screen for 1-2 seconds at most then the process was finished.

This was one of the biggest time sinkholes I ever experienced because it was also one of my first enterprise programming projects so the solutions I developed to get around the slow DOCTYPE lookup took time to learn and write, then I ultimately found out that my solution was totally pointless...

Dan Herbert
Couldn't you have used an XmlReader, passing in XmlReaderSettings that Prohibit the processing of the Dtd? (http://msdn.microsoft.com/en-us/library/system.xml.xmlreadersettings_members.aspx)
Richard Nienaber
Until I read your comment, I had no idea that feature existed. I did some searching when I encountered the problem but I didn't find anything like that online at the time explaining the "problem." I was also pressed for time and I was a much more novice programmer, so I didn't know any better.
Dan Herbert
+3  A: 

Rolling my own HTMLEncoder :P Really sucked when I found out it was available out-of-the-box in System.Web.

Jon Limjap
That happens more than it should. I'll spend a few hours writing something before I realize that there is already a tool in .NET the does exactly what I need it to do...
Hugoware
+2  A: 

FtpWebClient has a known issue with allegedly "non-standard" secure FTP server responses (you know, the kind used by a lot of huge banks). And by known, I mean 'complained about and reported as a bug over 2 years ago and never fixed'. As best I remember, it seems that if the secure FTP server replies with anything other than "\" after authentication (to indicate the current directory), like, for example, replying with "\userdefaultdirectoryname" instead, then FtpWebClient closes the connection and throws an exception - and there is nothing the programmer can do to change this behavior.

The lesson learned here was: now, any time I start to use a new (to me) class or capability of .NET (or any other language), I first google about it along with the keywords "bug OR issue OR problem OR exception OR failure OR hang..." to see if there are any lurking gotchas!

Steven A. Lowe
And this is still the case in .NET 4.0? MS has now opened its ears to a few of the developer complaints/reports - let's just hope this one is included.
Noldorin
@[Noldorin]: I'm not holding my breath ;-)
Steven A. Lowe
+5  A: 

In C# 2.0, the All member of the FlagsAttribute-style DragDropEffects enum, contrary to what the name of the member implies, does not include the DragDropEffects.Link member.

At the time, I had assumed that DragDropEffects.All was equal to:

Copy | Link | Move | Scroll

But it is actually defined as:

Copy | Move | Scroll

(despite the existance of the Link member.)

It does look like this has been addressed in C# 3.5. But in C# 2.0, the fact that the All member did not contain the Link bit was not at all clear from the documentation (quite possibly a bug).

I blogged about this issue at the time that I had originally encountered it (late 2006).

Jon Schneider
+13  A: 

Ternary Operator in C# doesn't know how to handle Nullable types. For example following won't work:

int? myIntValue = 
    dataReader.IsDBNull("ColumnName") ? null :  
    dataReader.GetInt32("ColumnName");

Even though following is legal and works:

int? myIntValue;

if(dataReader.IsDBNull("ColumnName"))
{
    myIntValue = null;
}
else
{
    myIntValue = dataReader.GetInt32("ColumnName");
}

The correct way is to cast the result, i.e :

int? myIntValue = 
    dataReader.IsDBNull("ColumnName") ? (int?)null : 
    (int?)dataReader.GetInt32("ColumnName");

(Note: This annoyance existed in C# 2.0. For more of Nullable Type annoyances see: http://sab39.netreach.com/Blog/Blog/12/vobId__172/pm__18/)

Vivek
Weird - I haven't had this problem in C# 3.
Erik Forbes
You only need to cast the first expression, as null don't carry any type: int? myIntValue = dataReader.IsDBNull("ColumnName") ? (int?)null : dataReader.GetInt32("ColumnName");
dalle
This is a problem of the nullable type, not of the ternary operator
BeowulfOF
+4  A: 

In .NET 1.0, web service objects (client-side) had a timeout property that didn't work as you would expect (the timeout covered the length of time the object would wait between receiving packets, not the length of time it would wait for the call to return), so you had to roll your own grisly, timer-based hack to abort a web service call manually after a set period of time if you didn't want your app to lock up for 2 minutes when the server was unavailable.

This problem was fixed in .NET 2.0, but I didn't realize it, and I kept migrating the grisly hack from project to project for a couple years, long after it was no longer necessary. Bonus: it didn't even work anymore with .NET 2.0.

MusiGenesis
"Bonus: it didn't even work anymore with .NET 2.0." LOL
Jeff Atwood
+2  A: 

Cookies in ASP.NET 1.1

I wasted days.

Vulcan Eager
A: 

I had to spend more time than I wanted implementing my own inplace tooltip for use in lists because the .NET one doesn't support having the font changed (and pre-2.0, didn't support being inherited either, or the transparent extended window style).

Jeff Yates
+2  A: 
var adEntry = new DirectoryEntry("LDAP://...");
adEntry.DoSomething(); // Throws meaningless COMException! Sometimes a different one!

adEntry = new DirectoryEntry("ldap://...");
adEntry.DoSomething(); // Works.
Sander
+1  A: 

This is not a quirk of the framework, but:

Cross-thread operations in C# 1.0. There are so many weird bugs because I didn't know better :)

The C# 2.0 compiler saved my day by finding these at compile-time.

VVS
+2  A: 

Configuration files, particularly with shared class library projects, seem more difficult to get implemented than they should be.

marc
A: 

I just discovered the asp:Menu control after trying all sorts of more complicated ways to do it.

Greg
+2  A: 

One issue that was a great time sink for me was DateTime with regard to daylight savings time. For example, if I create a date:

DateTime someDateTime = new DateTime(2008, 1, 1);

If I am in EST it will be the equivalent of whether I was in day light savings time or not for that moment in time rather than what my current day light savings time is. In other words, if I'm in day light savings time now and the date time I'm representing with the object is not within that time frame it will respect the timezone of that period in time.

This is particularly an issue when you are trying to do date time math (such as converting to UTC, etc) and find the time spans between two points in time -- it may very well be off by an hour.

Russell Myers
A: 

I've just wasted two days getting some WPF templating to work as I wanted. See my question over there. In the end I worked around this by modifying the parent and buying two WPF books to burn off my frustration.

David Schmitt
A: 

I had to design a series of ASP.NET pages which displayed a varying number of DataGrid controls created dynamically at run-time (back in .NET 1.1). When designing my app, I assumed I could allow the programmer to drop a single DataGrid control on the page to use as a template on which he could set the appearance, colors and CSS properties. I planned to reuse this grid as a template at run-time when creating other grids dynamically and delete the template at the end of my request.

My assumption was that I could do this:

for i = 1 to nGrids
    grids[i] = new Grid(templateGrid)    // assuming copy constructor semantics
delete templateGrid

or

for i = 1 to nGrids
    grids[i] = templateGrid.Clone()
delete templateGrid

Copying one variable to another is an elementary operation. After all it was one of the very first things I learned in programming.

No such luck!! Not in ASP.NET 1.1 at least. As luck would have it, I had emailed my grand design document to my team of eager freshmen without checking first!

Vulcan Eager
A: 

It sounds stupid and simple, but a lot of string operations like String.Split, String.Concat, etc. I was writing an EDI parser and was manually creating all of these basic string functions that already all existed. Now, I tend to google a lot more. It's saves a ton of time.

Micah
I did the same thing with a lot of methods in System.IO.File and System.IO.Path that I'd brought over from my VB6 days.
Michael Itzoe
I can't tell you how many times I've seen people reinvent the stuff in System.IO.Path. Mostly in a horrible way, too.
Chris
@Chris, have you maintained some of my code?
Mike C.
+1  A: 

Starting in .Net 2, when an application was compiled with the debug configuration, it would hold on to a small piece of memory every time you instantiated a class which had an event defined in it. Even if you didn't raise the event. It would hold onto this memory, and never release it. After running the ASP.Net application for a couple hours it would throw a OutOfMemoryException, restart the web service, and continue chewing through memory again. took many many hours of debugging, and a memory profiling to figure out where the problem was.

Kibbee
+1  A: 

Building dynamically generated UIs in ASP.NET. I kept banging my head against the wall until I learned to fully grok the page lifecycle.

Daniel Auger
+1  A: 

Running "Build Solution" on a solution with dozens of projects...

Waiting for the WinForms visual designer to respond...

... both have, when combined, taken up days of my life...

ObiWanKenobi
+1  A: 

ASP.NET:
Automatic ID generation + JQuery

Outputting clientside to cater for ASP.NET's automatic ID generation with form elements for use with JQuery, when all that was really required was to subclass the form controls (TextBox, Button etc.) and force the IDs.

Unless you have a really heavily nested setup or lots of spaghetti from drag and dropped created webforms, forcing your own IDs is the solution.

Chris S
Can you give a sample?
Mike C.
4.0 to the rescue!
ScottE
+3  A: 
  • Configuring MSBuild and/or TFSBuild script for a complex solution
  • Creating robust installer with WiX
  • Managing database change scripts
zvolkov
+1 for Managing database change scripts. All hail Redgate!
Mike C.
+1  A: 

Messing around with ASP.NET validators/ValidatorCalloutExtender with dynamic content. Yes, there is a ValidatorEnable() javascript property, but when you use the ValidatorCalloutExtenders you run into some issues. The correct solution is...

...

...

Anyone?

Bueller?

Mike C.
A: 

System.IO.Pipes

280Z28