dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
18.99k stars 4.03k forks source link

Asp.Net Razor Compilation using Roslyn fails under net451(mono) in Linux. #11908

Open tactical-drone opened 8 years ago

tactical-drone commented 8 years ago

Version Used: 1.3.0-beta1-20160525-03

Mono JIT compiler version 4.2.3 (Stable 4.2.3.4/832de4b Wed Mar 16 13:19:08 UTC 2016)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
    TLS:           __thread
    SIGSEGV:       altstack
    Notifications: epoll
    Architecture:  amd64
    Disabled:      none
    Misc:          softdebug 
    LLVM:          supported, not enabled.
    GC:            sgen
.NET Command Line Tools (1.0.0-preview2-002900)

Product Information:
 Version:            1.0.0-preview2-002900
 Commit SHA-1 hash:  f4ceb1f213

Runtime Environment:
 OS Name:     ubuntu
 OS Version:  14.04
 OS Platform: Linux
 RID:         ubuntu.14.04-x64

Steps to Reproduce:

  1. Create a Asp.Net Core application with targetframework set to net451 under Linux with Mono installed
  2. Create a view that uses the new Asp.Net TagHelper functionality
  3. Watch roslyn fail.

Expected Behavior: It should work

Actual Behavior: Roslyn cannot compile Razor code and fails with error:

Microsoft.AspNetCore.Mvc.Razor.Compilation.CompilationFailedException: One or more compilation failures occurred:
kcbt71yi.vod(129,149): error CS0246: The type or namespace name 'TValue' could not be found (are you missing a using directive or an assembly reference?)
kcbt71yi.vod(129,197): error CS1662: Cannot convert lambda expression to intended delegate type because some of the return types in the block are not implicitly convertible to the delegate return type
  at Microsoft.AspNetCore.Mvc.Razor.Compilation.CompilationResult.EnsureSuccessful () <0x4225c570 + 0x00063> in <filename unknown>:0 
  at Microsoft.AspNetCore.Mvc.Razor.Internal.CompilerCache.CreateCacheEntry (System.String normalizedPath, System.Func`2 compile) <0x41f97ec0 + 0x003af> in <filename unknown>:0 
svick commented 8 years ago

Why do you think this is a Roslyn issue? To me, it sounds like another instance of https://github.com/aspnet/Mvc/issues/4818, which is caused by https://github.com/dotnet/cli/issues/1613.

tactical-drone commented 8 years ago

I believe they originate from Roslyn. Because I threw all Mono assemblies at it and it did get by some of those earlier issues which led us to new and fresh issues.

Those errors above, CS0246 & CS1662 come from the Roslyn compiler and are not emitted when running on a windows platform.

Further more error CS0246 does not make sense. It is saying that it cannot find a reference to type or namespace TValue, but TValue is clearly non of those. It's a generic parameter. So the compiler is clearly confused about something there. I therefor believe it has something to do with Roslyn running on Linux.

Error CS1662 looks something like #2735 because of the<TKey,TValue> convention.

Razor has options that you can pass to the compiler via: CSharpCompilationOptions & CSharpParseOptions & RoslynCompilationContext. Is there an option I can pass to it so that it emits some debug information about what it is trying to do? For example I have tried pulling some levers like: options.ParseOptions.WithLanguageVersion(Microsoft.CodeAnalysis.CSharp.LanguageVersion.CSharp5); but it does not help. It would really help me find where this problem comes from, the code generated by razor or Roslyn that is trying to compile it.

tactical-drone commented 8 years ago

This issue seems to be resolved in 1.0.0