aspnet / Razor

[Archived] Parser and code generator for CSHTML files used in view pages for MVC web apps. Project moved to https://github.com/aspnet/AspNetCore
Apache License 2.0
882 stars 225 forks source link

Dynamic view compilation fails because of RazorPage<dynamic> under linux>dotnet>net451>.NETFramework,Version=v4.5.1>mono 4.2.3 #774

Closed tactical-drone closed 8 years ago

tactical-drone commented 8 years ago

Hi.

I am trying to get ASP.Net running under docker. So far so good I got kestrel serving pages but then Razor fails with the following errors produced in the browser.

Cannot define a class or member that utilizes 'dynamic' because the compiler required type 'System.Runtime.CompilerServices.DynamicAttribute' cannot be found. Are you missing a reference?

public class _Views_Home_Index_cshtml : Microsoft.AspNetCore.Mvc.Razor.RazorPage

What can be done about this?

More info

"frameworks": { "net451": { } },

We are on net451 because some libraries don't support netcoreapp yet, like Oracle.ManagedDataAccess. Those Oracle guys are such lazy ass bums busy suing everyone instead of fixing their stuff. Always after the quick buck those guys, sigh.

Wait the kestrel does not have to be on net451...but then nothing works on netcoreapp1.0.

pranavkm commented 8 years ago

Do the views work locally i.e. outside the container?

tactical-drone commented 8 years ago

Not inside linux no.

It only works when you run it natively on windows or through iisexpress.

The issue seems to be that the 'dynamic' type support is not seamless in mono. It comes from Mono's System.Core assembly that is somehow not part of razor's run time environment.

tactical-drone commented 8 years ago

Mono has this type, razor cannot see it for some reason:

https://github.com/mono/mono/blob/ef407901f8fdd9ed8c377dbec8123b5afb932ebb/mcs/class/System.Core/Documentation/en/System.Runtime.CompilerServices/DynamicAttribute.xml

Says it was added a month ago.

I will compile mono from source and report back....

Reporting back

Oh noes it's only reference sources. Don't think those actually go into Mono at all. What a fail.

pranavkm commented 8 years ago

We don't have coverage for Mono at this point, but we've had no issues running apps with Mono 4.0.5. What version are you using? We have coverage for .Net Core and that should definitely work.

tactical-drone commented 8 years ago

I use Mono 4.3.2.

I got by the issue by just copy and pasting that class (public sealed class DynamicAttribute : Attribute) into my project. Now I get a different set of errors that are the same on types that are from mscorlib:

An error occurred during the compilation of a resource required to process this request. Please review the following specific error details and modify your source code appropriately. Generated Code Predefined type 'System.Boolean' is not defined or imported public class _Views_Home_Index_cshtml : Microsoft.AspNetCore.Mvc.Razor.RazorPage The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. public class _Views_Home_Index_cshtml : Microsoft.AspNetCore.Mvc.Razor.RazorPage The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. public Microsoft.AspNetCore.Mvc.IUrlHelper Url { get; private set; } Predefined type 'System.Object' is not defined or imported public Microsoft.AspNetCore.Mvc.IUrlHelper Url { get; private set; } Predefined type 'System.Void' is not defined or imported public Microsoft.AspNetCore.Mvc.IUrlHelper Url { get; private set; } ....

I must say, this is causing all kinds of headaches for me. Research is leading me to places like this: https://blogs.msdn.microsoft.com/mvpawardprogram/2015/06/18/demystifying-pcls-net-core-dnx-and-uwp-redux/

Things are getting too complex now. I tried copying&pasting them (System.Boolean & Object) too but then I get compile errors about duplicate types. Those are already defined the compiler says and that they clash with those defined in mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 same PublicKeyToken and everything.

"frameworks": { "net451": { "frameworkAssemblies": {"System.Runtime":""} }

No effect.

I can define the type System.Boolean just fine in the code, also Object. Cannot understand why razor cannot work with them. I am so close to making this work... so frustrating.

pranavkm commented 8 years ago

I saw your comment in the other bug - are you trying to run netcoreapp1.0 binaries using Mono?

tactical-drone commented 8 years ago

No. AFAIK the netcoreapp1.0 framework does not require or run ontop of Mono. Only net451 does.

We would love to run netcoreapp1.0, but that target framework is not "production ready". 3rd party libraries simply don't work so we have to continue on net451.

The problem is that ASP.Net Core dynamic view compilation does not work on framework net451on Linux (it does on Windows). This is because Mono is not exactly the same as .NetFramework 4.x on Windows.

So basically we are stuck with our CI docker system. We cannot run the Kestrel server on Linux. We can run our API, which is also Kestrel (and net451), under Linux/dotnet/Mono just fine because it does not do the rocket science .cshtml dynamic razor view compilation stuff that fails. So we are almost there.

Therefor, to conclude. We desperately need someone that works on razor to look at these issues. I am sure that an engineer would instantly understand what the problem is. For example, that they are using reflection and that does not work under Mono because the specific types they are looking for does not exist or cannot be found in the way that they are looking for them (such as the mscorelib System.Boolean & Object stuff).

To reproduce the issue: Just create a basic ASP.Net Core MVC Web app with a index.cshtml under net451 and try to run it under Linux with dotnet and Mono installed on it. It will take 5 minutes to reproduce. It will take 6 minutes to fix.

pranavkm commented 8 years ago

@pompomJuice see the discussion here - https://github.com/aspnet/Mvc/issues/4818#issuecomment-224167616 and a possible workaround at https://github.com/aspnet/Mvc/issues/4818#issuecomment-224181486.