Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is ASP.NET vNext 'dnu build' not working on OSX

Installed DNVM and DNX on OSX as instructed via https://github.com/aspnet/Home.

I used generator-aspnet to create a console application with one source file, Program.cs:

using System;

namespace HelloWorldConsole
{
    public class Program
    {
        public static void Main(string[] args)
        {
            Console.WriteLine("Hello World");
            Console.ReadLine();
        }
    }
}

and a package.json:

{
    "version": "1.0.0-*",
    "dependencies": {},
    "commands": {
        "run": "run"
    },
    "frameworks": {
        "dnx451": {},
        "dnxcore50": {
            "dependencies": {
                "System.Console": "4.0.0-beta-*"
            }
        }
    }
}

When I run it using dnu . run, it works as expected and prints "Hello World!".

However when I try to generate assemblies from it by running dnu build I get the following error:

System.IO.EndOfStreamException: Failed to read past end of stream.
at System.IO.BinaryReader.ReadChar () [0x00000] in :0 at Microsoft.CodeAnalysis.CvtResFile.ReadStringOrID (System.IO.BinaryReader fhIn) [0x00000] in :0 at Microsoft.CodeAnalysis.CvtResFile.ReadResFile (System.IO.Stream stream) [0x00000] in :0 at Microsoft.CodeAnalysis.Compilation.MakeWin32ResourceList (System.IO.Stream win32Resources, Microsoft.CodeAnalysis.DiagnosticBag diagnostics) [0x00000] in :0 at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.SetupWin32Resources (Microsoft.CodeAnalysis.CSharp.Emit.PEModuleBuilder moduleBeingBuilt, System.IO.Stream win32Resources, Microsoft.CodeAnalysis.DiagnosticBag diagnostics) [0x00000] in :0 at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.CompileImpl (Microsoft.CodeAnalysis.Emit.CommonPEModuleBuilder moduleBuilder, System.IO.Stream win32Resources, System.IO.Stream xmlDocStream, Boolean generateDebugInfo, Microsoft.CodeAnalysis.DiagnosticBag diagnostics, System.Predicate1 filterOpt, CancellationToken cancellationToken) [0x00000] in <filename unknown>:0 at Microsoft.CodeAnalysis.Compilation.Compile (Microsoft.CodeAnalysis.Emit.CommonPEModuleBuilder moduleBuilder, System.IO.Stream win32Resources, System.IO.Stream xmlDocStream, Boolean generateDebugInfo, Microsoft.CodeAnalysis.DiagnosticBag diagnostics, System.Predicate1 filterOpt, CancellationToken cancellationToken) [0x00000] in :0 at Microsoft.CodeAnalysis.Compilation.Emit (Microsoft.CodeAnalysis.EmitStreamProvider peStreamProvider, Microsoft.CodeAnalysis.EmitStreamProvider pdbStreamProvider, Microsoft.CodeAnalysis.EmitStreamProvider xmlDocumentationStreamProvider, Microsoft.CodeAnalysis.EmitStreamProvider win32ResourcesStreamProvider, IEnumerable1 manifestResources, Microsoft.CodeAnalysis.Emit.EmitOptions options, Microsoft.CodeAnalysis.CodeGen.CompilationTestData testData, System.Func1 getHostDiagnostics, CancellationToken cancellationToken) [0x00000] in :0 at Microsoft.CodeAnalysis.Compilation.Emit (System.IO.Stream peStream, System.IO.Stream pdbStream, System.IO.Stream xmlDocumentationStream, System.IO.Stream win32Resources, IEnumerable1 manifestResources, Microsoft.CodeAnalysis.Emit.EmitOptions options, Microsoft.CodeAnalysis.CodeGen.CompilationTestData testData, System.Func1 getHostDiagnostics, CancellationToken cancellationToken) [0x00000] in :0 at Microsoft.CodeAnalysis.Compilation.Emit (System.IO.Stream peStream, System.IO.Stream pdbStream, System.IO.Stream xmlDocumentationStream, System.IO.Stream win32Resources, IEnumerable1 manifestResources, Microsoft.CodeAnalysis.Emit.EmitOptions options, CancellationToken cancellationToken) [0x00000] in <filename unknown>:0 at Microsoft.Framework.Runtime.Roslyn.RoslynProjectReference.EmitAssembly (System.String outputPath) [0x00000] in <filename unknown>:0 at Microsoft.Framework.PackageManager.ProjectBuilder.Build (System.String name, System.String outputPath) [0x00000] in <filename unknown>:0
at Microsoft.Framework.PackageManager.BuildContext.Build (System.Collections.Generic.List
1 diagnostics) [0x00000] in :0 at Microsoft.Framework.PackageManager.BuildManager.Build () [0x00000] in :0 at Microsoft.Framework.PackageManager.Program+<>c__DisplayClass3_4.b__8 () [0x00000] in :0 at Microsoft.Framework.Runtime.Common.CommandLine.CommandLineApplication.Execute (System.String[] args) [0x00000] in :0 at Microsoft.Framework.PackageManager.Program.Main (System.String[] args) [0x00000] in :0 at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&) at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in :0

Any ideas why dnx . run works but dnu build doesn't? The core libs seem to be getting referenced and loaded hence the run working. What's missing with the dnu build command?

like image 597
Ravi Amin Avatar asked Apr 30 '15 02:04

Ravi Amin


3 Answers

What I did is this:

  1. clone the mono repository, compile and install it following the directions here http://www.mono-project.com/docs/compiling-mono/ (make sure to follow the directions for compiling from git source)
  2. brew tap aspnet/dnx
  3. brew upgrade
  4. brew install dnvm --without-mono

After doing this I was able to run dnu build successfully.

like image 104
James Pack Avatar answered Oct 17 '22 12:10

James Pack


It is a known Mono bug: https://bugzilla.xamarin.com/show_bug.cgi?id=29499

Discussion is here: https://github.com/aspnet/Home/issues/498

like image 28
Victor Hurdugaci Avatar answered Oct 17 '22 11:10

Victor Hurdugaci


The issue seems to be brew is pointing at a version of mono that doesn't seem to work well with the latest build of aspnet/dnx. Here is a way to get it pointing to a workable version.

  1. nano /usr/local/Library/Formula/mono.rb
  2. changed line 4 and 5 to

    url "http://download.mono-project.com/sources/mono/mono-4.0.1.44.tar.bz2" sha256 "eaf5bd9d19818cb89483b3c9cae2ee3569643fd621560da036f6a49f6b3e3a6f"

  3. brew upgrade mono

  4. You should be able to properly run dnu build on the project

    • source dnvm.sh
    • cd projectdir
    • dnu restore
    • dnu build
    • export MONO_MANAGED_WATCHER=false (for mono bug, see link below)
    • dnx . kestrel
    • open http://localhost:5001

about mono bug - Running first ASP.NET 5 application using VSCode, DNX and kestrel results in IOException

If you have problems with brew, use brew doctor

Thanks to salerth https://github.com/aspnet/Home/issues/498

like image 4
Paully Avatar answered Oct 17 '22 12:10

Paully