Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to make the following project runnable (Object reference not set to an instance of an object.)

When I create default web project in Visual Studio 2015 (Update 3) with installed .NET Core 1.0 SDK and Tooling (preview 2) and restart the Visual Studio after reverting local source control changes I am getting the following compilation error:

Failed to make the following project runnable: MyDefaultWebProject (.NETCoreApp,Version=v1.0) reason: Object reference not set to an instance of an object.

According to Visual Studio the error is located in C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Common.Targets on line 262

On this line there is the following code:

<Dnx
  RuntimeExe="$(SDKToolingExe)"
  Condition="'$(_DesignTimeHostBuild)' != 'true'"
  ProjectFolder="$(MSBuildProjectDirectory)"
  Arguments="$(_BuildArguments)"
  />

How can I fix such a problem?

like image 312
Nikolay Kostov Avatar asked Jul 12 '16 12:07

Nikolay Kostov


People also ask

What does the error'object has no reference'?

This error's description speaks for itself but when you do not have much experience in development, it is very difficult to understand. So, this error description says that an object that is being called to get or set its value has no reference. This means that you are trying to access an object that was not instantiated. Why should I know this?

What does the error was- object reference not set to an instance?

I was making a game, basically an angry bird rip-off. This is the coding- the error was- object reference not set to an instance of an object It means that somewhere in your code you are trying to use a variable reference that has never been initialised.

How to avoid the error of utility reference not set to object?

In order to avoid the error of utility reference not set to an instance of object, you can choose to use the null context. Of course, in order to avoid nullreferenceexception:object reference not set to an instance of an object, you can take other measures.

Why does my request fail to return an object?

Either you forgot to initialize the object, either some code failed to return an expected object. Sometimes, the fail is do to exhausted limited resource, in this case, you need to check if request succeed or not. The content must be between 30 and 50000 characters. …


2 Answers

The only working solution I managed to find is to run the dotnet restore command:

C:\Dev\*****>dotnet restore

Welcome to .NET Core!
---------------------
Learn more about .NET Core @ https://aka.ms/dotnet-docs. Use dotnet --help to see available commands or go to https://aka.ms/dotnet-cli-docs.
Telemetry
--------------
The .NET Core tools collect usage data in order to improve your experience. The data is anonymous and does not include commandline arguments. The data is collected by Microsoft and shared with the community.
You can opt out of telemetry by setting a DOTNET_CLI_TELEMETRY_OPTOUT environment variable to 1 using your favorite shell.
You can read more about .NET Core tools telemetry @ https://aka.ms/dotnet-cli-telemetry.
Configuring...
-------------------
A command is running to initially populate your local package cache, to improve restore speed and enable offline access. This command will take up to a minute to complete and will only happen once.
Decompressing 100% 2181 ms
Expanding 100% 9113 ms
log  : Restoring packages for C:\Dev\*****\project.json...
log  : Restoring packages for tool 'BundlerMinifier.Core' in C:\Dev\*****\project.json...
log  : Restoring packages for tool 'Microsoft.AspNetCore.Razor.Tools' in C:\Dev\*****\project.json...
log  : Restoring packages for tool 'Microsoft.AspNetCore.Server.IISIntegration.Tools' in C:\Dev\*****\project.json...
log  : Restoring packages for tool 'Microsoft.EntityFrameworkCore.Tools' in C:\Dev\*****\project.json...
log  : Restoring packages for tool 'Microsoft.Extensions.SecretManager.Tools' in C:\Dev\*****\project.json...
log  : Restoring packages for tool 'Microsoft.VisualStudio.Web.CodeGeneration.Tools' in C:\Dev\*****\project.json...
log  : Writing lock file to disk. Path: C:\Dev\*****\project.lock.json
log  : C:\Dev\*****\project.json
log  : Restore completed in 13207ms.

after which the compilation in Visual Studio is successful again.

like image 66
Nikolay Kostov Avatar answered Oct 12 '22 02:10

Nikolay Kostov


In my case the problem was that one of the class library projects in a solution was referencing an AspNetCore.Identity library by the absolute path when I pulled sources from the source control. Because of that - wrong paths were generated in project.fragment.lock.json file and solution couldn not build. Fixing that absolute path reference in .csproj file made it work.

like image 33
Alex Avatar answered Oct 12 '22 04:10

Alex