NullReferenceException from dnu build with precompilation module
Hi i'm trying to build my project but I get NullReferenceException from Roslyn Compiler. The issue happens on Visual Studio or after running dnu build.
I created sample project under https://github.com/pgrudzien12/dnxcompileerror. Problem is somehow related to the precompilation file which can be found under ITConsole\Compiler\Preprocess\RazorPreCompilation.cs
I noticed that issue occurs when project framework is set to dnxcore50 but DNX version is set to beta8 clr. When changing to beta8 coreclr message is different and more informative. Issue here is that Visual Studio always use clr version of DNX.
Steps to reproduce:
- Download sample project
- dnvm use 1.0.0-beta8 -r clr -arch x86
- dnu build
When using command line dnu build on debug build of DNX i get following output:
System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.Dnx.Compilation.CSharp.RoslynCompiler.<>c__DisplayClass10_0.1.<Get>b__0(CacheContext ctx) in c:\code\dnx\src\Microsoft.Dnx.Compilatio n.Abstractions\Caching\CacheExtensions.cs:line 9 at Microsoft.Dnx.Compilation.Caching.Cache.CreateEntry(Object k, Func2 acquire) in c:\code\dnx\src\Microsoft.Dnx.Compilation\Caching\Cache.cs:line
98
at Microsoft.Dnx.Compilation.Caching.Cache.<>c__DisplayClass5_0.1.CreateValue() at System.Lazy1.LazyInitValue()
at System.Lazy1.get_Value() at Microsoft.Dnx.Compilation.Caching.Cache.Get(Object key, Func2 factory) in c:\code\dnx\src\Microsoft.Dnx.Compilation\Caching\Cache.cs:line 24
at Microsoft.Dnx.Compilation.Caching.CacheExtensions.Get[T](ICache cache, Object key, Func2 factory) in c:\code\dnx\src\Microsoft.Dnx.Compilation. Abstractions\Caching\CacheExtensions.cs:line 9 at Microsoft.Dnx.Compilation.CSharp.RoslynCompiler.GetCompileModules(CompilationTarget target) in c:\code\dnx\src\Microsoft.Dnx.Compilation.CSharp\ RoslynCompiler.cs:line 226 at Microsoft.Dnx.Compilation.CSharp.RoslynCompiler.CompileProject(CompilationProjectContext projectContext, IEnumerable1 incomingReferences, IEnum
erable1 incomingSourceReferences, Func1 resourcesResolver) in c:\code\dnx\src\Microsoft.Dnx.Compilation.CSharp\RoslynCompiler.cs:line 139
at Microsoft.Dnx.Compilation.CSharp.RoslynProjectCompiler.CompileProject(CompilationProjectContext projectContext, Func1 referenceResolver, Func1
resourcesResolver) in c:\code\dnx\src\Microsoft.Dnx.Compilation.CSharp\RoslynProjectCompiler.cs:line 43
at Microsoft.Dnx.Compilation.LibraryExporter.<>c__DisplayClass17_0.1.<Get>b__0(CacheContext ctx) in c:\code\dnx\src\Microsoft.Dnx.Compilatio n.Abstractions\Caching\CacheExtensions.cs:line 9 at Microsoft.Dnx.Compilation.Caching.Cache.CreateEntry(Object k, Func2 acquire) in c:\code\dnx\src\Microsoft.Dnx.Compilation\Caching\Cache.cs:line
98
at Microsoft.Dnx.Compilation.Caching.Cache.<>c__DisplayClass5_0.1.CreateValue() at System.Lazy1.LazyInitValue()
at System.Lazy1.get_Value() at Microsoft.Dnx.Compilation.Caching.Cache.Get(Object key, Func2 factory) in c:\code\dnx\src\Microsoft.Dnx.Compilation\Caching\Cache.cs:line 24
at Microsoft.Dnx.Compilation.Caching.CacheExtensions.Get[T](ICache cache, Object key, Func2 factory) in c:\code\dnx\src\Microsoft.Dnx.Compilation. Abstractions\Caching\CacheExtensions.cs:line 9 at Microsoft.Dnx.Compilation.LibraryExporter.ExportProject(ProjectDescription project, String aspect) in c:\code\dnx\src\Microsoft.Dnx.Compilation\ LibraryExporter.cs:line 217 at Microsoft.Dnx.Compilation.LibraryExporter.GetExport(LibraryDescription library, String aspect) in c:\code\dnx\src\Microsoft.Dnx.Compilation\Libr aryExporter.cs:line 187 at Microsoft.Dnx.Compilation.LibraryExporter.GetAllExports(LibraryDescription root, String aspect, Func2 include) in c:\code\dnx\src\Microsoft.Dnx
.Compilation\LibraryExporter.cs:line 116
at Microsoft.Dnx.Compilation.LibraryExporter.GetAllExports(String name, String aspect, Func2 libraryFilter) in c:\code\dnx\src\Microsoft.Dnx.Compi lation\LibraryExporter.cs:line 79 at Microsoft.Dnx.Compilation.LibraryExporter.GetAllExports(String name, String aspect) in c:\code\dnx\src\Microsoft.Dnx.Compilation\LibraryExporter .cs:line 51 at Microsoft.Dnx.Compilation.LibraryExporter.GetAllExports(String name) in c:\code\dnx\src\Microsoft.Dnx.Compilation\LibraryExporter.cs:line 46 at Microsoft.Dnx.Tooling.BuildContext.ShowDependencyInformation(IReport report) in c:\code\dnx\src\Microsoft.Dnx.Tooling\Building\BuildContext.cs:l ine 173 at Microsoft.Dnx.Tooling.BuildContext.Initialize(IReport report) in c:\code\dnx\src\Microsoft.Dnx.Tooling\Building\BuildContext.cs:line 43 at Microsoft.Dnx.Tooling.BuildManager.BuildConfiguration(String baseOutputPath, IEnumerable1 frameworks, List1 allDiagnostics, String configurati on) in c:\code\dnx\src\Microsoft.Dnx.Tooling\Building\BuildManager.cs:line 213 at Microsoft.Dnx.Tooling.BuildManager.BuildInternal(String projectPath) in c:\code\dnx\src\Microsoft.Dnx.Tooling\Building\BuildManager.cs:line 136 at Microsoft.Dnx.Tooling.BuildManager.Build() in c:\code\dnx\src\Microsoft.Dnx.Tooling\Building\BuildManager.cs:line 82 at Microsoft.Dnx.Tooling.BuildConsoleCommand.<>c__DisplayClass0_0.<Register>b__1() in c:\code\dnx\src\Microsoft.Dnx.Tooling\ConsoleCommands\BuildCo nsoleCommand.cs:line 47 at Microsoft.Dnx.Runtime.Common.CommandLine.CommandLineApplication.Execute(String[] args) in c:\code\dnx\src\Microsoft.Extensions.CommandLineUtils. Sources\CommandLine\CommandLineApplication.cs:line 263 at Microsoft.Dnx.Tooling.Program.Main(String[] args) in c:\code\dnx\src\Microsoft.Dnx.Tooling\Program.cs:line 98 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Microsoft.Dnx.Runtime.Common.EntryPointExecutor.Execute(Assembly assembly, String[] args, IServiceProvider serviceProvider) in c:\code\dnx\src\M icrosoft.Dnx.Runtime.Sources\Impl\EntryPointExecutor.cs:line 43 at Microsoft.Dnx.Host.Bootstrapper.RunAsync(List1 args, IRuntimeEnvironment env, String appBase, FrameworkName targetFramework) in c:\code\dnx\src
\Microsoft.Dnx.Host\Bootstrapper.cs:line 104
at Microsoft.Dnx.Host.RuntimeBootstrapper.ExecuteAsync(String[] args, BootstrapperContext bootstrapperContext) in c:\code\dnx\src\Microsoft.Dnx.Hos
t\RuntimeBootstrapper.cs:line 159
at Microsoft.Dnx.Host.RuntimeBootstrapper.Execute(String[] args, BootstrapperContext bootstrapperContext) in c:\code\dnx\src\Microsoft.Dnx.Host\Run
timeBootstrapper.cs:line 22
Great that you reported this issue! I just spent lots of hours yesterday and today after upgrading a solution from beta7 to beta 8 before finding that this was the cause. I assume that there will be lots of people getting this issue since this commented class was part of the sample solution previously.
I have run into the same problem with dnx46. However with dnx46, I received almost no information from the compiler, so tracking down the cause was a pain. This is easily reproducible:
- Create an empty asp.net 5 app
- Change dnx451 to dnx46 (Note I also removed core)
- Create folder Compiler\PreProcess
- Create file RazorPreCompilation.cs
After this, you would typically create a class that inherits from RazorPreCompileModule, however I have found that even an empty file will cause dnx to throw "The design time host build failed with the following error: Object reference not set to an instance of an object."
Yep, you need to keep both frameworks around.
Holy fast response batman! Thanks, adding dnx451 back in fixed it. Is this temporary? Will dnx46 support the precompilation module at some point, or do we just need to leave dnx451 in there?
I think that plans are to move precompilation from dnu to roslyn. @davidfowl am I right that precompilation modules will not be avaliable for RTM?
@mattfraley1 above exception is not available normally - you have to compile your own debug version of dnx.