Compatibility issue using ASP.Net 4.0, Extensions and ScriptManager

1,371 views
Skip to first unread message

ChrisH

unread,
Aug 23, 2010, 1:59:12 PM8/23/10
to WebSync
Hi guys,

A few days ago I came across a problem that seems to be a
compatibility issue when using ScriptManager and the 'Subscribers' and
'ReturnData' WebSync server extensions in the same ASP.Net 4.0 (C#)
project. The application fails with an exception like this:
Could not load file or assembly
'FM.WebSync.Extensions.ExtensionAttribute, Version=1.0.1.0,
Culture=neutral, PublicKeyToken=null' or one of its dependencies.

The problem is very easy to reproduce; just open the example project
'FM.WebSync.Examples.Extensions' (that is shipped with WebSync Server)
in Visual Studio 2010 and allow it to convert to ASP.Net 4.0. Then add
a regular ScriptManager tag to default.aspx.

The problem does not occur in .Net 3.5 projects. A workaround seems to
be referencing 'FM.WebSync.Extensions.ExtensionAttribute.dll' from the
Compatibility folder (which is there for .Net 2.0 projects, according
to the readme).

I have not had time yet to investigate the underlying cause. Please
let me know if you need any more information.

Cheers,
Chris

Jerod Venema

unread,
Aug 23, 2010, 2:01:59 PM8/23/10
to web...@googlegroups.com
Thanks for the heads up, Chris; seems odd indeed. The "ExtensionAttribute" stuff was added to make .NET 2.0 allow the extension methods used in, naturally, the extensions, but it should be native functionality in .NET 4.

We'll take a look into it as well; if you find anything interesting, let us know :)


--
You received this message because you are subscribed to the Google Groups "WebSync" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to websync+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/websync?hl=en.




--
Jerod Venema
Frozen Mountain Software
http://www.frozenmountain.com/
(w) 919-300-5141
(c) 919-368-5105

ChrisH

unread,
Aug 23, 2010, 3:27:48 PM8/23/10
to WebSync
Hi Jerod,

That was fast :-) Just in case, here is the stacktrace:

[FileNotFoundException: Could not load file or assembly
'FM.WebSync.Extensions.ExtensionAttribute, Version=1.0.1.0,
Culture=neutral, PublicKeyToken=null' or one of its dependencies. Het
systeem kan het opgegeven bestand niet vinden.]
System.ModuleHandle.ResolveType(RuntimeModule module, Int32
typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr*
methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type) +0
System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module,
Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext,
RuntimeTypeHandle[] methodInstantiationContext) +180
System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken,
Type[] genericTypeArguments, Type[] genericMethodArguments) +192

System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord
caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly,
RuntimeModule decoratedModule, MetadataToken decoratedToken,
RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[]
attributes, IList derivedAttributes, RuntimeType& attributeType,
IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean&
isVarArg) +115
System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule
decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount,
RuntimeType attributeFilterType, Boolean mustBeInheritable, IList
derivedAttributes, Boolean isDecoratedTargetSecurityTransparent) +426

System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeAssembly
assembly, RuntimeType caType) +103
System.Reflection.RuntimeAssembly.GetCustomAttributes(Boolean
inherit) +33

System.Web.UI.AssemblyCache.GetAjaxFrameworkAssemblyAttribute(Assembly
assembly) +76
System.Web.UI.ScriptManager.get_DefaultAjaxFrameworkAssembly() +388
System.Web.UI.ScriptManager..ctor() +26
ASP.default_aspx.__BuildControlJustAScriptManager() in c:\Program
Files (x86)\Frozen Mountain Software\WebSync Server\Examples\Extensions
\Default.aspx:79
ASP.default_aspx.__BuildControlForm1() in c:\Program Files
(x86)\Frozen Mountain Software\WebSync Server\Examples\Extensions
\Default.aspx:78
ASP.default_aspx.__BuildControlTree(default_aspx __ctrl) in c:
\Program Files (x86)\Frozen Mountain Software\WebSync Server\Examples
\Extensions\Default.aspx:1
ASP.default_aspx.FrameworkInitialize() in c:\Windows\Microsoft.NET
\Framework\v4.0.30319\Temporary ASP.NET Files\root
\b31aa089\e506f4b4\App_Web_ctanqkby.0.cs:0
System.Web.UI.Page.ProcessRequest(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+54
System.Web.UI.Page.ProcessRequest() +78
System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
+21
System.Web.UI.Page.ProcessRequest(HttpContext context) +49
ASP.default_aspx.ProcessRequest(HttpContext context) in c:\Windows
\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root
\b31aa089\e506f4b4\App_Web_ctanqkby.0.cs:0

System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
+100
System.Web.HttpApplication.ExecuteStep(IExecutionStep step,
Boolean& completedSynchronously) +75


Googling a bit reveals a few seemingly similar issues with some
assemblies and the combination of ScriptManager and .Net 4.0, like
this one:
http://forums.asp.net/p/1560230/3851169.aspx

Same as in the last post of that thread, after reloading the page the
error stops occurring. That seems to imply it is some kind of problem
related to assembly loading order?




On 23 aug, 20:01, Jerod Venema <jerod.ven...@frozenmountain.com>
wrote:
> > websync+u...@googlegroups.com<websync%2Bunsu...@googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/websync?hl=en.
>
> --
> Jerod Venema
> Frozen Mountain Softwarehttp://www.frozenmountain.com/
> (w) 919-300-5141
> (c) 919-368-5105

Jerod Venema

unread,
Aug 23, 2010, 3:51:06 PM8/23/10
to web...@googlegroups.com
Huh, that is weird; it almost seems to me like it's related to caching of the ASPNet_Tempfiles stuff; when it recompiles, it thinks it needs dependencies that it really doesn't, so when it refreshes,  everything works...

To unsubscribe from this group, send email to websync+u...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/websync?hl=en.

ChrisH

unread,
Aug 23, 2010, 6:19:10 PM8/23/10
to WebSync
Sounds plausible to me! Would it be possible to create a version of
FM.WebSync.Extensions.Subscribers.Core.dll that does not reference
FM.WebSync.Extensions.ExtensionAttribute.dll in any way?



On 23 aug, 21:51, Jerod Venema <jerod.ven...@frozenmountain.com>
wrote:
> > <websync%2Bunsu...@googlegroups.com<websync%252Buns...@googlegroups.com>

Jerod Venema

unread,
Aug 23, 2010, 9:20:56 PM8/23/10
to web...@googlegroups.com
Yes and no?

We have the ExtensionAttribute in place to provide compatibility with .NET 2.0, which is the version of the framework under which the Core dll is compiled (so the client can use a lower .NET framework version). All the attribute does is provide the capability for extension methods, which is built into .NET 3.0+, so technically, it should never be required in .NET 3.0+. I'm not sure exactly why it's still holding the reference - as you noted, it doesn't require the reference for 3.0 or 3.5, and runs just fine. Actually, when we tested it, if you *included* the ExtensionAttribute dll in your project, you'd get compiler errors (or warnings, I can't remember which) because the Extension attribute was defined more than once (once in our code, once in the System.* namespace).

After reading up on it a bit more, it seems like the ScriptManager is doing some dynamic reflection stuff, finding linked assemblies on the fly, even if they're not explicitly required for the project to compile and run successfully. It could be that there's a way to tell it to ignore certain attributes or something; I guess we'll see!

We'll take a look into it regardless :)

To unsubscribe from this group, send email to websync+u...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/websync?hl=en.

ChrisH

unread,
Aug 24, 2010, 6:29:30 AM8/24/10
to WebSync
This is where my knowledge of assembly binding falls short. I just saw
the reference to the ExtensionAttribute dll when I took a look with
ildasm.
It does look like ScriptManager has a lot of underwater spookiness
going on. Unfortunately we need to use it in the app we're working on
right now :-|

Thanks for looking into this!


On 24 aug, 03:20, Jerod Venema <jerod.ven...@frozenmountain.com>
wrote:
> > > > <websync%2Bunsu...@googlegroups.com<websync%252Buns...@googlegroups.com>
> > <websync%252Buns...@googlegroups.com<websync%25252Bun...@googlegroups.com>

Jerod Venema

unread,
Aug 24, 2010, 5:13:25 PM8/24/10
to web...@googlegroups.com
The gory details...

This error is thrown from within .NET itself. Inside the System.Web.UI.AssemblyCache, we find this code:

foreach (Attribute attribute2 in assembly.GetCustomAttributes(false))

This basically grabs all the custom attributes in an assembly, which in turn looks at WebSync and attempts to load the FM.WebSync.Extensions.Extension dll, which, despite not actually being used, is (as you correctly noted) still referenced at the assembly level. Hence, making it available to the website fixes the problem, even though it's not actually USED by the site.

The interesting thing is that this all gets cached at the application level, so after the page is loaded once, even though it fails to load properly, from then on the application will run anyway.

Anyway, it's basically a bug (imho) in the .NET framework. They shouldn't be loading unnecessary assemblies, and even if they do, it shouldn't cause the app to collapse. I've opened a case with Microsoft about it.

In the meantime, you can use this little hack to avoid the problem if you don't want to include the extra DLL. Basically, it just tells the assembly cache to ignore the WebSync extension dlls when it's analyzing the custom attributes:

private void FixScriptManager()
{
    Type t = Type.GetType("System.Web.UI.AssemblyCache, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"falsetrue);
    ConcurrentDictionary<System.Reflection.Assembly, System.Web.Script.AjaxFrameworkAssemblyAttribute> cache = (ConcurrentDictionary<System.Reflection.Assembly, System.Web.Script.AjaxFrameworkAssemblyAttribute>)t.GetField("_ajaxAssemblyAttributeCache", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static).GetValue(null);
    Type[] toFix = new Type[]{
        typeof(FM.WebSync.Extensions.ReturnData.Server.WebSyncEvents), 
        typeof(FM.WebSync.Extensions.Subscribers.Server.WebSyncEvents),
        typeof(FM.WebSync.Extensions.ReturnData.Core.Base),
        typeof(FM.WebSync.Extensions.Subscribers.Core.Base)
    };
    foreach (Type type in toFix)
    {
        cache.TryAdd(System.Reflection.Assembly.GetAssembly(type), null);
    }
}
You can test it by just running it from the constructor of your default page, but move it to your Application_Start of your global.asax (or some other application-level initialization call) for production use.
To unsubscribe from this group, send email to websync+u...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/websync?hl=en.

ChrisH

unread,
Aug 25, 2010, 6:10:55 AM8/25/10
to WebSync
Thanks Jerod! The temporary fix works great. Knowing the Microsoft bug
submission process, it can take a while to get an update from their
side.

I have purchased a support contract in the meantime, mostly to show my
appreciation. But also to be able to perhaps pick your brain a bit
during the development of our new project, which will largely be a
showcase for WebSync :)

Cheers,
Chris


On 24 aug, 23:13, Jerod Venema <jerod.ven...@frozenmountain.com>
wrote:
> The gory details...
>
> This error is thrown from within .NET itself. Inside the
> System.Web.UI.AssemblyCache, we find this code:
>
> foreach (Attribute<http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorli...>
> *attribute2* in
> assembly.GetCustomAttributes<http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorli...>
> (false))
> ...
>
> meer lezen »

Jerod Venema

unread,
Aug 25, 2010, 8:21:29 AM8/25/10
to web...@googlegroups.com
Awesome, glad to hear it on all counts, and can't wait to hear from you about your project!


--
You received this message because you are subscribed to the Google Groups "WebSync" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to websync+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/websync?hl=en.

Jerod Venema

unread,
Sep 6, 2010, 2:48:26 PM9/6/10
to WebSync
For those viewing this thread in the future, to clarify, WebSync
doesn't have any issues running on .NET 4; this is a bug within
the .NET framework itself, that only applies when using the ASP.NET
"ScriptManager" tag. It can be avoided by either of the two methods
specified above (adding a reference to the ExtensionAttribute DLL or
including the workaround code mentioned above in your startup code).

On Aug 25, 8:21 am, Jerod Venema <jerod.ven...@frozenmountain.com>
wrote:
> > System.Web.Script.AjaxFrameworkAssemblyAttribute>)t.GetField("_ajaxAssembly AttributeCache",
> ...
>
> read more »

W.R. Matthiesen

unread,
Aug 29, 2012, 8:59:18 AM8/29/12
to web...@googlegroups.com
I'm using WebSync 4 and getting the same thing.  The reference to the DLL fix doesn't seem to apply, since that DLL is not in the 4 package.  And, the code fix doesn't seem to apply either because if says the ReturnData and Subscribers don't exist in FM.WebSync.Extensions.  Is there an updated version to these workarounds?
 
Thanks

Anton Venema

unread,
Aug 29, 2012, 11:46:50 AM8/29/12
to web...@googlegroups.com
The ExtensionAttribute doesn't exist at all on the server-side for WebSync 4. What is the error message you are seeing?

Anton Venema
Frozen Mountain Software
604-227-2458 (Canada)
919-300-5520 (United States)
888-379-6686 (
888-FRZN-MTN)
www.frozenmountain.com




On Wed, Aug 29, 2012 at 5:59 AM, W.R. Matthiesen <wrmatt...@gmail.com> wrote:
I'm using WebSync 4 and getting the same thing.  The reference to the DLL fix doesn't seem to apply, since that DLL is not in the 4 package.  And, the code fix doesn't seem to apply either because if says the ReturnData and Subscribers don't exist in FM.WebSync.Extensions.  Is there an updated version to these workarounds?
 
Thanks

--
You received this message because you are subscribed to the Google Groups "WebSync" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to websync+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/websync/-/Skz7m6107gsJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Jerod Venema

unread,
Aug 29, 2012, 11:46:41 AM8/29/12
to web...@googlegroups.com
Can you tell us exactly the error you're seeing?

On Wed, Aug 29, 2012 at 8:59 AM, W.R. Matthiesen <wrmatt...@gmail.com> wrote:
I'm using WebSync 4 and getting the same thing.  The reference to the DLL fix doesn't seem to apply, since that DLL is not in the 4 package.  And, the code fix doesn't seem to apply either because if says the ReturnData and Subscribers don't exist in FM.WebSync.Extensions.  Is there an updated version to these workarounds?
 
Thanks

--
You received this message because you are subscribed to the Google Groups "WebSync" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to websync+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/websync/-/Skz7m6107gsJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

W.R. Matthiesen

unread,
Aug 29, 2012, 12:11:05 PM8/29/12
to web...@googlegroups.com
I am getting:
 
Could not load type 'System.Runtime.CompilerServices.ExtensionAttribute' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
 
Line 22:
Line 23:     <form id="form1" runat="server" style="height:100%;" >
Line 24: <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" > Line 25:         <Services>
Line 26:           <asp:ServiceReference Path="~/WebService/SmartSearchWS.asmx" />
 
It throws it whenever it load after a rebuild. A refresh in the browser, and all is fine.  I have a stack trace I can include too.  But, it is all windows assemblies.  It is always possible that it is not Websync causing it, but I saw this thread and it sounded very similar.
 
The asmx in the ScriptManager is mine, and it isn't doing much.

Anton Venema

unread,
Aug 29, 2012, 12:24:48 PM8/29/12
to web...@googlegroups.com
I don't think this is a WebSync issue.

It looks like Microsoft moved the ExtensionAttribute around in .NET 4.5. This looks like a relevant StackOverflow thread:



Anton Venema
Frozen Mountain Software
604-227-2458 (Canada)
919-300-5520 (United States)
888-379-6686 (
888-FRZN-MTN)
www.frozenmountain.com




--
You received this message because you are subscribed to the Google Groups "WebSync" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to websync+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/websync/-/icGAyALVs5EJ.

W.R. Matthiesen

unread,
Aug 29, 2012, 12:34:32 PM8/29/12
to web...@googlegroups.com
OK, thanks. I will look elsewhere.

Anton Venema

unread,
Sep 27, 2012, 1:21:41 PM9/27/12
to web...@googlegroups.com
As a follow-up, just in case there are compatibility issues running .NET 3.5 assemblies in a .NET 4.0 or 4.5 environment, releases of WebSync 4 now include server assemblies specifically targeting .NET 3.5, 4.0, and 4.5. If you are running in a .NET 4.5 environment, you can use the .NET 4.5 WebSync server assemblies.


Anton Venema
Frozen Mountain Software
604-227-2458 (Canada)
919-300-5520 (United States)
888-379-6686 (
888-FRZN-MTN)
www.frozenmountain.com




On Wed, Aug 29, 2012 at 9:34 AM, W.R. Matthiesen <wrmatt...@gmail.com> wrote:
OK, thanks. I will look elsewhere.

--
You received this message because you are subscribed to the Google Groups "WebSync" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to websync+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/websync/-/kEbfaKV9buoJ.
Reply all
Reply to author
Forward
0 new messages