Custom Attribute Load Failure in GetAjaxFrameworkAssemblyAttribute - by Jerod Venema

Status : 

  Fixed<br /><br />
		This item has been fixed in the current or upcoming version of this product.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.


7
0
Sign in
to vote
ID 588777 Comments
Status Closed Workarounds
Type Bug Repros 4
Opened 8/24/2010 12:05:48 PM
Access Restriction Public

Description

Hey folks!

There's a minor bug in .NET 4 that causes problems when loading pages with a ScriptManager on the page. Within the System.Web.Extensions dll, in the System.Web.UI.AssemblyCache class, the method "GetAjaxFrameworkAssemblyAttribute" enumerates all the custom attributes in a given assembly. If, for some reason, one of those attributes is unavailable, this method fails and the application crashes.

See this search for a number of people running into the same problem:

http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=GetAjaxFrameworkAssemblyAttribute

The solution would be to simply wrap the call to GetCustomAttributes() in a try...catch block; if there's a problem getting an attribute for an unrelated DLL, it should not cause the application to crash.

Also, see this thread: http://groups.google.com/group/websync/browse_thread/thread/83c1f88abbb00b80?pli=1
Sign in to post a comment.
Posted by Microsoft on 4/29/2014 at 12:17 PM
Thank you for reporting this issue. This issue has been fixed in Visual Studio 2013. You can install a trial version of Visual Studio 2013 with the fix from: http://go.microsoft.com/?linkid=9832436
Posted by Marian Zaki on 1/31/2012 at 4:14 AM
Where should we put the code below?
Where to add the try and catch

public static AjaxFrameworkAssemblyAttribute GetAjaxFrameworkAssemblyAttribute(Assembly assembly)
{
    AjaxFrameworkAssemblyAttribute attribute = null;
    if (!_ajaxAssemblyAttributeCache.TryGetValue(assembly, out attribute))
    {
        foreach (Attribute attribute2 in assembly.GetCustomAttributes(false)) // <=== HERE
        {
            if (attribute2 is AjaxFrameworkAssemblyAttribute)
            {
                attribute = (AjaxFrameworkAssemblyAttribute) attribute2;
                break;
            }
        }
        _ajaxAssemblyAttributeCache.TryAdd(assembly, attribute);
    }
    return attribute;
Posted by Iulian Ionescu on 5/6/2011 at 6:54 AM
This bug still exists as of today!!
Here is where the error lies: In the ScriptManager constructor you are trying to find the DefaultAjaxAssembly and you call a procedure that scans all loaded assemblies looking for a certain attribute. The problem is that if the code that retrieves the attribute fails the entire code in the constructors fails and exists with the specific exception. This is where the problem is:

In System.Web.UI.AssemblyCache:


public static AjaxFrameworkAssemblyAttribute GetAjaxFrameworkAssemblyAttribute(Assembly assembly)
{
    AjaxFrameworkAssemblyAttribute attribute = null;
    if (!_ajaxAssemblyAttributeCache.TryGetValue(assembly, out attribute))
    {
        foreach (Attribute attribute2 in assembly.GetCustomAttributes(false)) // <=== HERE
        {
            if (attribute2 is AjaxFrameworkAssemblyAttribute)
            {
                attribute = (AjaxFrameworkAssemblyAttribute) attribute2;
                break;
            }
        }
        _ajaxAssemblyAttributeCache.TryAdd(assembly, attribute);
    }
    return attribute;
}

You must wrap that in a try{}catch{} block to prevent the entire code from crashing when the GetCustomAttributes fails on a certain library. In my case this was failing on a library called AxAcroPDFLib.dll because it had the following attribute:


[assembly: TypeLibraryTimeStamp("16.05.2006 21:31:20")]

Because of my locale that cannot be converted to a Date and so the whole code was crashing with a invalid string for Date kind of exception...

Iulian
Posted by Microsoft on 8/24/2010 at 5:05 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)