June 5, 2007

LoadWithPartialName, I miss you…

When you make a call to LoadWithPartialName in .NET 2.0, you get the standard compiler error that you’re using an obsolete function:

foo.cs(5,24): warning CS0618:
'System.Reflection.Assembly.LoadWithPartialName(string)' is obsolete:
'This method has been deprecated. Please use Assembly.Load() instead.
http://go.microsoft.com/fwlink/?linkid=14202 '

The problem is, unlike more obsolete function warnings, there’s no good way I know of to reform the arguments from the obsolete function to the recommended replacement, i.e. Assembly.Load doesn’t work if you give it a partial assembly name. Because of this, instead of code filled with Assembly.Load calls, I see this all over the place in production .NET 2.0 code:

#pragma warning disable 618
Assembly.LoadWithPartialName("foo");
#pragma warning restore 618

Maybe in .NET 3.5, we can get a helper function that wraps the #pragmas for us… : )