I had the following code as per this question&answer How do I get the MIME type of a file being requested in ASP.NET C#?
and it was working perfectly fine:
static MimeMappingWrapper()
{
// dirty trick - Assembly.LoadWIthPartialName has been deprecated
//Assembly ass = Assembly.LoadWithPartialName("System.Web");
Assembly ass = Assembly.GetAssembly(typeof (HttpApplication));
Type mimeMappingType = ass.GetType("System.Web.MimeMapping");
GetMimeMappingMethod = mimeMappingType.GetMethod("GetMimeMapping", BindingFlags.Static | BindingFlags.NonPublic);
}
Now suddenly the mimeMappingType.GetMethod("GetMimeMapping", BindingFlags.Static | BindingFlags.NonPublic) returns null.
What could be the reason? Nothing special was changed in the application and even if it was, how could it influence this constructor for the wrapper class?
My guess would be that the .NET Framework installed on the server got upgraded, and the private constructor is no longer present under the new version.
Assembly developers (in this case, Microsoft) are allowed to change any private (or internal) types or members at their whim, without it being considered to have been a breaking change.
Edit: I checked on my PC under .NET 4.0, and the method is still present. This is its signature:
At this point, my two suggestions would be to check your actual .NET version at runtime…
…and to enumerate the methods of the
MimeMappingclass to check whether they correspond to what you expect:Update: The good news is that the
MimeMappingclass and itsGetMimeMappingmethod seem like they might be made public in .NET 4.5.However, this means that your code would definitely break, since you’re only searching for
NonPublicmethods. Try performing an all-inclusive search instead and see whetherGetMimeMappingshows up: