OrchardCMS / Orchard

Orchard is a free, open source, community-focused Content Management System built on the ASP.NET MVC platform.
https://orchardproject.net
BSD 3-Clause "New" or "Revised" License
2.38k stars 1.12k forks source link

Shapes not initialized (?) when JIT compilation takes place #4600

Open orchardbot opened 10 years ago

orchardbot commented 10 years ago

@Piedone created: https://orchard.codeplex.com/workitem/20771

Try to access any page on an Orchard site that you haven't yet (i.e. where you haven't used the code yet, thus, I suppose, JIT compilation should take place) since you started the site with the debugger attached. There will be loads of exceptions coming from places where dynamic methods or properties are accessed on shapes (or on the shape factory), e.g. exceptions from the following places with the following messages: CoreShapes ln 58 and below

A first chance exception of type 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' occurred in Microsoft.CSharp.dll

Additional information: 'Orchard.DisplayManagement.Implementation.DefaultShapeFactory' does not contain a definition for 'DocumentZone'

DefaultShapeFactory ln 113

A first chance exception of type 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' occurred in Microsoft.CSharp.dll

Additional information: Cannot apply indexing with [] to an expression of type 'Orchard.DisplayManagement.Shapes.Shape'

ResourceFilter ln 23 and below

A first chance exception of type 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' occurred in Microsoft.CSharp.dll

Additional information: 'Orchard.UI.Zones.ZoneHolding' does not contain a definition for 'Head'

LayoutAwareViewEngine ln 63

A first chance exception of type 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' occurred in Microsoft.CSharp.dll

Additional information: Cannot invoke a non-delegate type

src\Orchard.Web\Themes\SafeMode\Views\Layout.cshtml ln 17

A first chance exception of type 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' occurred in Microsoft.CSharp.dll

Additional information: 'Orchard.UI.Zones.ZoneHolding' does not contain a definition for 'Navigation'

CoreShapes ln 267

A first chance exception of type 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' occurred in Microsoft.CSharp.dll

Additional information: Cannot invoke a non-delegate type

This is new to Orchard 1.8.x I think, it definitely wasn't there in 1.7 and I can't remember to see it with 1.8.

orchardbot commented 10 years ago

@BenedekFarkas commented:

We experience this issue with all our 1.8+ instances, these exceptions are thrown all the time.

orchardbot commented 9 years ago

@Piedone commented:

Duplicate, focusing on the performance impact: https://orchard.codeplex.com/workitem/21063

orchardbot commented 9 years ago

MattGC0 commented:

Can I just bump this as a more of a major issue. I am seeing a lot of exceptions across a wide range of different usage of "dynamic". Code expects a number of different properties on various types and in some places is expecting the type to be an array. What are the plans for resolving this and when? Has anyone diagnosed this further at all and has any input? I can go through and put conditionals in checking that dynamic is not this or not that but that seems horrible to me when something rather significant in the object model is at fault.

Matt

orchardbot commented 9 years ago

@Piedone commented:

If you see other exceptions that are related to improper use of dynamic types than that's a different bug. I personally don't see such issues, and if you have them then it's by no means by design.

orchardbot commented 9 years ago

MattGC0 commented:

I'm not so sure. It really does seem the same as this work item. The errors above are identical to what I am seeing - you even have the "Cannot apply indexing with [] to an expression of type 'Orchard.DisplayManagement.Shapes.Shape". That particular issue happens around line 115 of DefaultShapeFactory. I am seeing these errors across all sorts of types for various core types.

createdContext.Shape[kv.Key] = kv.Value;

Would be interested to know if you are multitenant and in Azure? Some further info...

DefaultContentDisplay Line 52

itemShape.ContentItem = content.ContentItem;

Error is...

'Orchard.UI.Zones.ZoneHolding' does not contain a definition for 'ContentItem'

CoreShapes Line ~59,60 & 61:

layout.Head = created.New.DocumentZone(ZoneName: "Head"); etc
'Orchard.DisplayManagement.Implementation.DefaultShapeFactory' does not contain a definition for 'DocumentZone'

Then for the next line it repeats the above followed by...

'Orchard.UI.Zones.ZoneHolding' does not contain a definition for 'Body'

And it goes on for maybe 20 to 30 exceptions. Seems predominantly shape and zone related. Why would DefaultShapeFactory be passed as dynamic? Is that a symptom of this i.e. should that happen at all?

orchardbot commented 9 years ago

@Piedone commented:

I see, then this is indeed the same issue.

The problem with these exceptions are that they are false: shapes should correctly handle all these property accesses for example, because they have the necessary behaviour. It just seems that somehow the behaviour is not yet loaded the first time these calls happen...

DefaultShapeFactory being passed as dynamic is OK, this is the same as the New object used to construct shapes.

BTW the sites in question indeed run on Azure in a multi-tenant setup however we only see these exceptions locally, with the debugger attached. The site seemingly works perfectly fine, no YSOD, log entry or anything else.

orchardbot commented 9 years ago

MattGC0 commented:

Ok that is good to know. This is not as major as I had thought in that case.

Thanks

orchardbot commented 9 years ago

MattGC0 commented:

Ok that is good to know. This is not as major as I had thought in that case.

Thanks

orchardbot commented 9 years ago

MattGC0 commented:

I can't test the import of media when running in the Azure emulator. That is a pain!

orchardbot commented 9 years ago

@Piedone commented:

Again, you can, because you should only see these exceptions when you run a request for the first time and you have the debugger attached. If either of these two criteria are not met these exceptions shouldn't bother you.

orchardbot commented 9 years ago

MattGC0 commented:

What you describe is not what I see. I get the RuntimeBinderException constantly on every request when the debugger is attached.

mylemans commented 7 years ago

Any progress on this issue? I just noticed it today and sad to see that in 2 years no progress was made to fix this issue :/

While 'debugging' our live site (we're having some strange issues..) I got hundreds of RuntimeBinderException exceptions being thrown..

sebastienros commented 7 years ago

Does anyone know how we can fix it?

marknuzz commented 7 years ago

First-chance exceptions like this DO cause a lot of performance overhead. If debugging is slow, development is also slow. This should be looked at IMO (And yes, I am also experiencing this)

Piedone commented 7 years ago

I don't know if we can fix this at all (apart from not using dynamic shapes), seems to be done by design by the framework... See for some context: https://stackoverflow.com/questions/19936397/runtimebinderexception-when-accessing-dynamic-anonymous-type-in-view