Explore: .NET Gotchas

by Venkat Subramaniam

Xlarge_9781449362706

Like most complex tasks, .NET programming is fraught with potential costly, and time-consuming hazards. The millions of Microsoft developers worldwide who create applications for the .NET platform can attest to that. Thankfully there's now a book that shows you how to avoid such costly and time-consuming mistakes. It's called .NET Gotchas.

The ultimate guide for efficient, pain-free coding, .NET Gotchas from O'Reilly contains 75 common .NET programming pitfalls--and advice on how to work around them. It will help you steer away from those mistakes that cause application performance problems, or so taint code that it just doesn't work right.

The book is organized into nine chapters, each focusing on those features and constructs of the .NET platform that...

More >>

Like most complex tasks, .NET programming is fraught with potential costly, and time-consuming hazards. The millions of Microsoft developers worldwide who create applications for the .NET platform can attest to that. Thankfully there's now a book that shows you how to avoid such costly and time-consuming mistakes. It's called .NET Gotchas.

The ultimate guide for efficient, pain-free coding, .NET Gotchas from O'Reilly contains 75 common .NET programming pitfalls--and advice on how to work around them. It will help you steer away from those mistakes that cause application performance problems, or so taint code that it just doesn't work right.

The book is organized into nine chapters, each focusing on those features and constructs of the .NET platform that consistently baffle developers. Within each chapter are several "gotchas," with detailed examples, discussions, and guidelines for avoiding them. No doubt about it, when applied, these concise presentations of best practices will help you lead a more productive, stress-free existence.

What's more, because code examples are written in both VB.NET and C#, .NET Gotchas is of interest to more than 75 percent of the growing numbers of .NET programmers. So if you're a .NET developer who's mired in the trenches and yearning for a better way, this book is most definitely for you.

Less

Read Now


ISBN 9781449362706

Published 2012-11-29

Publisher O'Reilly Media


Free .NET Gotchas 2 >
Free Dedication 3 >
Free SPECIAL OFFER: Upgrade this ebook with O’Reilly 4 >
Free A Note Regarding Supplemental Files 5 >
Free Preface 6 >
Free Who This Book Is For 7 >
Free What You Need to Use This Book 10 >
Free Measure of Performance 11 >
Free Conventions Used in This Book 11 >
Free Using Code Examples 12 >
Free Comments and Questions 13 >
Free Safari® Enabled 13 >
Free Acknowledgments 14 >
Free 1. CLR/Framework Gotchas 16 >
Free GOTCHA #1 Type alias size doesn’t match what you’re familiar with 16 >
Free GOTCHA #2 struct and class differ in behavior 20 >
Free GOTCHA #3 Returning value types from a method/property is risky 25 >
Free GOTCHA #4 You can’t force calls to your value-type constructors 28 >
Free GOTCHA #5 String concatenation is expensive 31 >
Free GOTCHA #6 Exceptions may go unhandled 35 >
Free GOTCHA #7 Uninitialized event handlers aren’t treated gracefully 42 >
Free GOTCHA #8 Division operation isn’t consistent between types 46 >
Free GOTCHA #9 Typeless ArrayList isn’t type-safe 50 >
Free GOTCHA #10 Type.GetType() may not locate all types 56 >
GOTCHA #11 Public key reported by sn.exe is inconsistent 61 >
2. Visual Studio and Compiler Gotchas 64 >
GOTCHA #12 Compiler warnings may not be benign 64 >
GOTCHA #13 Ordering of catch processing isn’t consist across languages 73 >
GOTCHA #14 Type.GetType() might fail at run-time 77 >
GOTCHA #15 rethrow isn’t consistent 79 >
GOTCHA #16 Default of Option Strict (off) isn’t good 83 >
GOTCHA #17 Versioning may lead to Serialization headaches 88 >
GOTCHA #18 Creating Web apps can be painful 97 >
GOTCHA #19 Naming XML documentation for IntelliSense support isn’t intuitive 102 >
3. Language and API Gotchas 104 >
GOTCHA #20 Singleton isn’t guaranteed process-wide 104 >
GOTCHA #21 Default performance of Data.ReadXMLData.ReadXML 108 >
GOTCHA #22 enum lacks type-safety 112 >
GOTCHA #23 Copy Constructor hampers exensibility 117 >
GOTCHA #24 Clone() has limitations 124 >
GOTCHA #25 Access to static/Shared members isn’t enforced consistently 135 >
GOTCHA #26 Details of exception may be hidden 138 >
GOTCHA #27 Object initialization sequence isn’t consistent 143 >
GOTCHA #28 Polymorphism kicks in prematurely 147 >
GOTCHA #29 Unit testing private methodstesting private methods 151 >
4. Language Interoperability Gotchas 157 >
GOTCHA #30 Common Language Specification Compliance isn’t the default 158 >
GOTCHA #31 Optional parameters break interoperability 160 >
GOTCHA #32 Mixing case between class members breaks interoperability 163 >
GOTCHA #33 Name collision with keywords breaks interoperability 165 >
GOTCHA #34 Defining an array isn’t consistent 168 >
5. Garbage Collection Gotchas 172 >
GOTCHA #35 Writing Finalize() is rarely a good idea 172 >
GOTCHA #36 Releasing managed resources in Finalize() can wreak havoc 175 >
GOTCHA #37 Rules to invoke base.Finalize() aren’t consistent 181 >
GOTCHA #38 Depending on Finalize() can tie up critical resources 183 >
GOTCHA #39 Using Finalize() on disposed objects is costly 187 >
GOTCHA #40 Implementing IDisposable isn’t enough 190 >
GOTCHA #41 Using the Dispose Design Pattern doesn’t guarantee cleanup 198 >
6. Inheritance and Polymorphism Gotchas 201 >
GOTCHA #42 Runtime Type Identification can hurt extensibility 201 >
GOTCHA #43 Using new/shadows causes “hideous hiding” 210 >
GOTCHA #44 Compilers are lenient toward forgotten override/overrides 213 >
GOTCHA #45 Compilers lean toward hiding virtual methods 216 >
GOTCHA #46 Exception handling can break polymorphism 219 >
GOTCHA #47 Signature mismatches can lead to method hiding 226 >
7. Multithreading Gotchas 231 >
GOTCHA #48 The Thread classThread class 231 >
GOTCHA #49 Foreground threads may prevent a program from terminating 232 >
GOTCHA #50 Background threads don’t terminate gracefully 235 >
GOTCHA #51 Interrupt () kicks in only when a thread is blocked 237 >
GOTCHA #52 ThreadAbortException—a hot potato 240 >
GOTCHA #53 Environment.Exit() brings down the CLR 243 >
GOTCHA #54 ResetAbort() may lead to surprises 245 >
GOTCHA #55 Abort() takes time to clean up 247 >
GOTCHA #56 Calling Type.GetType() may not return what you expect 250 >
GOTCHA #57 Locking on globally visible objects is too sweeping 257 >
GOTCHA #58 Threads from the thread pool are scarce 262 >
GOTCHA #59 Threads invoked using delegates behave like background threads 267 >
GOTCHA #60 Passing parameters to threads is tricky 270 >
GOTCHA #61 Exceptions thrown from threads in the pool are lost 281 >
GOTCHA #62 Accessing WinForm controls from arbitrary threads is dangerous 291 >
GOTCHA #63 Web-service proxy may fail when used for multiple asynchronous calls 298 >
GOTCHA #64 Raising events lacks thread-safety 304 >
8. COM-Interop and Enterprise Services Gotchas 312 >
GOTCHA #65 Release of COM object is confusing 312 >
GOTCHA #66 Using interface pointers after calling ReleaseComObject() will fail 316 >
GOTCHA #67 Cross-apartment calls are expensive 319 >
GOTCHA #68 Default apartment of main thread is inconsistent across languages 324 >
GOTCHA #69 STAThread attribute may have no effect on your methods 327 >
GOTCHA #70 Spattering access to COM components makes code hard to maintain 331 >
GOTCHA #71 Auto-generating GUID for your classes leads to versioning woes 334 >
GOTCHA #72 All but one of the ClassInterface options are ineffective 339 >
GOTCHA #73 Simply tur ning the switch for COM interop is dangerous 344 >
GOTCHA #74 ServicedComponents implemented inconsistently on XP and 2003 347 >
GOTCHA #75 AutoComplete comes with undesirable side effects 353 >
A. Resources 358 >
Bibliography 363 >
On the Web 358 >
Index 365 >
About the Author 409 >
Colophon 410 >
SPECIAL OFFER: Upgrade this ebook with O’Reilly 411 >
Copyright 412 >