Sdk: Object reference not set to an instance of an object after publish

Created on 25 May 2016  路  9Comments  路  Source: dotnet/sdk

I'm having trouble when publishing my application.
Published output doesn't work, with error:

Object reference not set to an instance of an object

Steps to reproduce

  1. Create Empty ASP.NET Core Web Application (.NET Core)
  2. Setup simple project.json
{
  "dependencies": {
    "Microsoft.NETCore.App": {
      "version": "1.0.0-rc2-3002702"
    },
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-final"
  },

  "tools": {
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": {
      "version": "1.0.0-preview1-final",
      "imports": "portable-net45+win8+dnxcore50"
    }
  },

  "frameworks": {
    "netcoreapp1.0": { }
  },

  "buildOptions": {
    "emitEntryPoint": true
  },

  "runtimes": {
    "osx.10.11-x64": { },
    "win8-x64": { },
    "win10-x64": { },
    "ubuntu.14.04-x64": { }
  },

  "publishOptions": {
    "include": [
      "wwwroot",
      "web.config"
    ]
  },

  "scripts": {
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }
}
  1. dotnet restore
  2. dotnet run
  3. "Hello world" is visible in browser at http://localhost:5000
  4. dotnet publish -r win8-x64 -o "c:tmp\Publish"
  5. Navigate to output directory "c:tmp\Publish"
  6. dotnet run
  7. dotnet run -p WebApplication4.dll - doesn't work either

    Expected behavior

Application will start the same way as before publish

Actual behavior

Object reference not set to an instance of an object.

Environment data

dotnet --info output:

.NET Command Line Tools (1.0.0-preview1-002702)

Product Information:
 Version:     1.0.0-preview1-002702
 Commit Sha:  6cde21225e

Runtime Environment:
 OS Name:     Windows
 OS Version:  6.2.9200
 OS Platform: Windows
 RID:         win8-x64

Most helpful comment

To run a published application, don't use run, just dotnet myapp.dll.

All 9 comments

It should generate and run with WebApplication4.exe (no dotnet ... call required for standalone apps).
The nullref comes from run not finding a project.json/project.lock.json and afaik has been fixed in newer builds.

@dasMulli is right. For a standalone app, you will get an EXE file that you run.

Can you try with the latest builds and see if the dotnet run behavior is correct (not throwing)?

preview2 does indeed include a fix:

The current project is not valid because of the following errors:
/Users/piotrp/.dotnet(1,0): error DOTNET1017: Project file does not exist '/Users/piotrp/.dotnet/project.json'.

I've followed this issue and pulled the latest build and I get the fix but I still don't get a standalone .exe, what have I missed ?

@johnkattenhorn can you share your project.json?

Hey @blackdwarf, I figure it out just now, I needed to remove the platform line from the project.json.

Thanks for following it up

To run a published application, don't use run, just dotnet myapp.dll.

Yep, I was reading some comments in the dotnet run not run in here earlier. I can see why it's confusing for people.

Ugh, @tmds
thank you :)

Was this page helpful?
0 / 5 - 0 ratings