I would like to use Microsoft.Web.Administration.dll from within the SQL Server CLR in order to get the physical path of a specific web application at runtime, but the DLL is not available or tested in SQL Server, and adding it would require adding a chain of dependent DLLs (also untested), so basically NEVERMIND all of the above.

On to the issue, but first a short background. The architecture of my database application is pretty fancy... a "Database.Values" namespace (in database.dll) contains a host of C# classes, each of which subclass "RegexConstrainedString" or "ConstrainedNumber" (both custom classes) which represent regular expression and numeric value constraints for various fields in the database. Each class is marked with attributes specifying various table+fieldname combinations indicating which table and field names each rule applies to in the database.

A deployment application takes that database.dll, uses reflection to find classes with the aforementioned attributes and dynamically generates (in IL op codes) a function for each class (classname appended with "Check"), whose purpose is simply to attempt to instantiate a given string or number with the associated class and returns true or false depending on whether the instantiation was successful. Instantiation fails when the string or number doesn't match the class's defined constraints. The deployment app then uses ILMerge.exe to merge its dynamically generated functions with the original database.dll to produce a new database.dll which is deployed to SQL Server. It then opens a GUI that allows for one-click creation, enabling, and checking of all the associated SQL check constraint functions, which call the underlying CLR class-based "\*Check" functions that were generated.

Anyway... one of those classes in particular called "Text" enforces ASCII encoding on a field by mapping Unicode strings to ASCII strings, and for completeness, it will map all 65536 possible two-byte (16-bit) UCS2 code point values to a specific ASCII character using a character map that is created and edited by a web application. Sure, I could have just mapped everything outside the range (32-126) to a question mark character, but I wanted greater control to the point where I mapped out every possible Unicode character to an ASCII character that it closely resembles, so it's probably one of the most complete (although subjective) visual maps in existence.

The problem is, the static constructor of the Text class that resides in database.dll in the SQL CLR needs to load that ASCII map file, which resides in the root of a particular web application. How am I supposed to get that path without hard coding it and without the ability to use the Microsoft.Web.Administration.dll's call to `(new ServerManager()).Sites["Default Web Site"].Applications["/utilities"].VirtualDirectories["/"].PhysicalPath`?