2006.04.24 02:06 PM
AppDomain.RelativeSearchPath Returns Null
Due to an unfortunate failure today, I discovered that the .NET v1.1 AppDomain type's string-based RelativeSearchPath property does not return an empty string if not set. Instead, it returns null. This runs counter to Microsoft's own .NET design guidelines, which state that methods and properties typed as strings and arrays should return empty strings and empty arrays instead of nulls. (I can't find the exact guideline at the moment, but here's Wesner Moise's explanation from a couple of years ago.)
In case you're interested, the RelativeSearchPath is null for AppDomains created for most Windows applications, but is "bin" for most AppDomains created by ASP.NET.
Anyhow, forewarned is forearmed, as they say. Time to doublecheck my code. Maybe FxCop should report any usage of string typed variables set by methods or properties that aren't first checked for null?
By the way, .NET 2.0 makes this doublecheck a little easier with the addition of the String.IsNullOrEmpty method.
what about the "??" operator.
you could do "var z = a ?? "unknown";" in c# 3 :)
its wierd to comment in the past:) but just for the heck of it:D
zproxy | 2006.08.14 05:12 AM
As infrequently as I post this one isn't so past. ;) Thanks for the comment.
ewbi.develops | 2006.08.14 10:13 AM
TrackBack URL: http://www.typepad.com/services/trackback/6a00d8341c7bd453ef00d834dd1dd869e2
Listed below are links to weblogs that reference AppDomain.RelativeSearchPath Returns Null: