I was updating some code today in ASP.NET 2.0. The code had originally been written in ASP.NET 1.1 and I'm in the process of migrating the application 2.0 in piecemeal fashion. I'm doing it thus, in part, to experiment. In doing so, I encountered an interesting situation that I thought to pass along to my faithful reader.
First of all, allow me to back up a bit to address a few of the issues that have some bearing on the discussion. I have a web service that I built for user authentication. I call it my Devstone Authentication Engine. This web service has a custom SDK that provides functions that call the services, effectively isolating the dependent application from the nuances of setting up web references and associations. The calling app simply establishes a reference to the SDK dll and we're good to go.
Alright, well, that SDK dll uses Reflection on the calling assembly to discover information about the system to which the user is authenticating. I like this approach. I have a custom Attribute-based type that I apply to the client application in question. When the client application attempts to use the SDK dll, it reflects back on the caller to determine the desired target.
To be honest, this was all well and good in .NET 1.x. You could build a Web Application, compile the entire site into a single assembly (MySite.dll) and call it good.
ASIDE
The rules changed with .NET 2.0, however. The compilation model is substantially more complex; heck, the programming model is (IMHO) a bit more complex because it is much less structured. (I know I'm not the only one who doesn't really care for the App_Code, no-namespace programming model. I'll discuss that more in depth another time.)
To address these and many other concerns expressed by developers moving to the 2.0 Framework who were comfortable with the 1.1 programming model Microsoft has created what are called Web Development Projects. If you're comfortable in the .NET 1.x programming model but want the power and flexibility of the 2.0 Framework, I highly encourage you to download the Beta V2 and experiment with it - it's pretty sweet!
In 2.0, however, when each page/folder/whatever gets compiled into its own dll, the attributes applied in the AssemblyInfo.cs don't get incorporated into each dynamic, on-the-fly assembly. Therefore, calls to the web service SDK fail because it can't find an instance of the attribute within the calling assembly via Reflection. If you set a breakpoint and inspect the assembly name you get the name of a dynamically created assembly (e.g. App_Web_y7sgdlhd.dll).
The trick with 2.0 is simply to move the [assembly: myattribute()] from the AssemblyInfo.cs into the same page as the ASPX page that needs to call the web service. Then, when the runtime compiler grabs the file and compiles it, the [assembly:...] attributes get applied to the dynamic assembly as well.