Publishing ASP.Net Core Fails with NullReferenceException - asp.net

I have built a relatively simple ASP.Net Core web application that uses Angular 2 & bootstrap for the front end and WebApi as the back end.
I am able to build and run my application locally (to IIS Express) and it works just fine, however, when I attempt to use the Build -> Publish menu I encounter a NullReferenceExceptionError that is terrible unhelpful. Here is the output when I run Publish:
1>------ Publish started: Project: MyProject, Configuration: Release Any CPU ------
Connecting to C:\ProjectDir\MyProject\./bin/Release/PublishTest...
rmdir /S /Q "C:\Users\UserName\AppData\Local\Temp\PublishTemp\MyProject86\"
Environment variables:
Path=%PATH%;.\node_modules\.bin;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Web\External;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Web\External\git
C:\Program Files\dotnet\dotnet.exe publish "C:\ProjectDir\MyProject" --framework net452 --output "C:\Users\UserName\AppData\Local\Temp\PublishTemp\MyProject86" --configuration Release --no-build
Publishing MyProject for .NETFramework,Version=v4.5.2/win7-x64
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Publishing.targets(149,5): Error : Object reference not set to an instance of an object.
1>Publish failed due to build errors. Check the error list for more details.
========== Build: 0 succeeded, 0 failed, 3 up-to-date, 0 skipped ==========
========== Publish: 0 succeeded, 1 failed, 0 skipped ==========
I have attempted to do a FileSystem publish to both a directory on a server running IIS as well as just a local directory, and I get the same output in both of these instances.
I have cleaned my solution, rebuilt, and restarted Visual Studio just in case it had been in a bad state. I've created a few different publish profiles just to make certain that something wasn't misconfigured with that (some of them were created after the restart of VS2015, as well).
In addition I made sure to update VS2015 after I started having this problem, and I am now running version 14.0.25425.01 Update 3. I also have the latest web tools installed.
Here is my project.json file:
{
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.0-rc2-3002702",
"type": "platform"
},
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-final",
"Microsoft.AspNetCore.StaticFiles": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Mvc.ViewFeatures": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Mvc": "1.0.0-rc2-final"
},
"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": {
"version": "1.0.0-preview1-final",
"imports": "portable-net45+win8+dnxcore50"
}
},
"frameworks": {
"net452": {
"imports": [
"dotnet5.6",
"dnxcore50",
"portable-net45+win8"
],
"dependencies": {
"aDependency": {
"target": "project"
}
}
}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"runtimeOptions": {
"gcServer": true
},
"publishOptions": {
"include": [
"wwwroot",
"web.config"
]
},
"scripts": {
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}
I've been searching for anyone else having this issue and I believe I found one or two other places where this seems to have been encountered but I haven't found anyone that has replied with a solution or even a theory to what is happening exactly. Any help, theories, or leads would be appreciated.
Thanks for your time.
EDIT: As suggested in the comments I created a new ASP.NET Core application since 1.0.0 was released and took a look at the differences. It worked and I feel silly for missing this, anyway, for anyone else who runs into this (albeit temporally limited) issue, here's the fixed project.json file:
{
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.0",
"type": "platform"
},
"Microsoft.AspNetCore.Diagnostics": "1.0.0",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.AspNetCore.Mvc.ViewFeatures": "1.0.0",
"Microsoft.AspNetCore.Mvc": "1.0.0",
"Microsoft.AspNetCore.StaticFiles": "1.0.0"
},
"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
},
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"dnxcore50",
"portable-net45+win8"
],
"dependencies": {
"aDependency": {
"target": "project"
}
}
}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"runtimeOptions": {
"configProperties": {
"System.GC.Server": true
}
},
"publishOptions": {
"include": [
"wwwroot",
"web.config"
]
},
"scripts": {
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}

I think you should update your app from RC2 to 1.0.0 and you may want to create a new web app with 1.0.0 and the latest tooling/vs project templates from dot.net then compare the project.json and startup code to your existing app and update the existing app

Related

TFS 2015 Build builds solution and its projects in wrong order (ASP.NET Core Framework 4.6.1)

I have Asp.Net core (Framework 4.6.1) solution with the following structure:
API sln
|-- WebApi.Project_1
|-- Project_2 (Core library, referencing Framework 4.6.1)
references Project_4 (Core Library, referencing Framework 4.6.1)
|-- Project_3 (Core library, referencing Framework 4.6.1)
references Project_4 (Core Library, referencing Framework 4.6.1)
See the "sanitized" project.json files below.
Some notes:
• there is a number of classic (4.6.1 .net) libraries added to the solution but not referenced yet by any other core projects.
• I created the core libraries and manually referenced .net framework 4.6.1 from their json files
•they use x86 platform, specified in project.json -> buildOptions
Everything is built and run OK by using VisualStudio 2015 (either on my local machine or locally on the same build agent server)
The solution build fails when it is built in CI build by TFS 2015 build engine with the following error:
"C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Common.Targets(265,5): Error: D:\tfsAgent_work\folder\folder\Project_2\error CS0006: metadata file '\folder\folder\bin\debug\net461\Project_4.dll' could not be found"
Same error, but for Project_3, referencing Project_4 as well.
By looking at the build log I see that Project_4 is built after Projects 2 and 3, thus the file is not there yet.
I tried different options:
•adding the references in project.json
•using Project references
•Solution properties -> Project dependencies...
•manually reorder the projects in API.sln file.
No difference.
**WebApi_Project_1.json:**
{
"dependencies": {
"Project_2": "1.0.0-*",
"Project_3": "1.0.0-*",
"Microsoft.AspNetCore.Mvc": "1.0.0",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
"Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.Logging": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
"System.Net.Http": "4.1.0"
},
"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
},
"frameworks": {
"net461": {}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true,
"platform": "x86",
"copyToOutput": {
"include": [
"Folder/Folder/Folder/*.xsd",
"Folder/Folder/Folder/*.xml"
]
}
},
"publishOptions": {
"include": [
"wwwroot",
"Views",
"Areas/**/Views",
"appsettings.json",
"web.config"
]
},
"scripts": {
"postpublish": [ "dotnet publish-iis --publish-folder % publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}
**Project_2.json**
{
"dependencies": {
"Project_4": "1.0.0.0"
},
"buildOptions": {"platform": "x86"},
"frameworks": {
"net461": {}
}
}
**Project_3.json**
{
"buildOptions": { "platform": "x86" },
"dependencies": {
"Project_4": "1.0.0.0"
},
"frameworks": {
"net461": {
"frameworkAssemblies": {
"System.Xml": "4.0.0.0"
}
}
}
}
**Project_4.json**
{
"version": "1.0.0.0",
"buildOptions": { "platform": "x86" },
"frameworks": {
"net461": {}
}
}

.Net Core tag helper intellisense and color coding not working

I am having issues with .NET core and tag helpers. The color coding and the intellisense are not displaying or being registered when I type in asp-for. I've tried creating a new solution in a separate instance, verified that the intellisense works, and then copied the project.json into the project that doesn't have working intellisense/color coding, and it doesn't fix the issue.
Here is my project.json
{
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.0",
"type": "platform"
},
"Microsoft.AspNet.Tooling.Razor": "1.0.0-rc1-final",
"Microsoft.AspNetCore.Diagnostics": "1.0.0",
"Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0",
"Microsoft.AspNetCore.Mvc": "1.0.1",
"Microsoft.AspNetCore.Mvc.TagHelpers": "1.0.1",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
"Microsoft.AspNetCore.StaticFiles": "1.0.0",
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.1",
"Microsoft.Extensions.Configuration.FileExtensions": "1.1.0",
"Microsoft.Extensions.Configuration.Json": "1.1.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Microsoft.AspNetCore.Routing": "1.0.1",
"Microsoft.AspNetCore.Razor.Tools": {
"version": "1.0.0-preview2-final",
"type": "build"
},
"Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
"version": "1.0.0-preview2-final",
"type": "build"
},
"Microsoft.VisualStudio.Web.CodeGenerators.Mvc": {
"version": "1.0.0-preview2-final",
"type": "build"
}
},
"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final",
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"
},
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"portable-net45+win8"
]
}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"runtimeOptions": {
"configProperties": {
"System.GC.Server": true
}
},
"publishOptions": {
"include": [
"wwwroot",
"web.config"
]
},
"scripts": {
"prepublish": [ "bower install" ],
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}
I've also made the reference/injection in the _ViewImports file for the mvc tag helpers. This is the view where I'm testing that it works.
And here is my project structure, just in case you can see something that I'm not seeing.
If it helps at all, here is the version of Visual Studio I am using.
I fixed it in two steps.
1.Install Razor tool from package manager console. It is pre-release for now
Install-Package Microsoft.AspNetCore.Razor.Tools –Pre
Download and install Razor Language Services from marketplace. (Your visual studio instance should be closed)
After restart visual studio, intellisense and coloring should be working for tag helpers.
This is a semi-old Q&A, but I recently solved a similar problem where tag helper intellisense and highlighting/colorization suddenly stopped working, so I post this for posterity.
I tried to repair and reinstall Visual Studio to no avail. What ultimately solved this issue follows:
Close all instances of Visual Studio.
Download and install the latest .NET Core SDK.
Open "Apps & features" (Add or remove programs)
Search for ".NET Core SDK" and uninstall all except the latest version (x64 and/or x86).
Reopen Visual Studio.
There is a BUG in .net, When you create project and name it starting with number, TagHelper will not work,
in my project this was a problem
I had to install Microsoft.AspNetCore.Mvc.TagHelpers and add below line in _ViewImports.cshtml file
#addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
UPDATE
I had this issue recently, but the solution is a little bit different right now. To install the package in VS Code, run in terminal:
dotnet add package Microsoft.AspNetCore.Razor.Tools --prerelease
If it doesn't solve, delete your .vscode folder inside your user folder and install C# and other extensions again.
You do not need to install Razor Language Services anymore. After restart VS Code, everything works again.
Regards!

Syntax highlighting and intellisense not working .net core vs 2015

I am trying to work on a .net core project and syntax highlighting is not functioning properly for razor views. Is there a dev dependency or configuration property that I am missing. Intellisense is also not working properly for asp-* tags. Any suggestions? I've already tried deleting the ComponentModelCache in appdata.
Here is my project.json so you can see what packages I'm using. It seems to be project setup related, most likely a package. I am importing the tag helpers in my _ViewImports.cshtml file. I'm just not sure what's different in this project compared to default .NET Core projects. This project was started with an empty web core project.
{
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.0",
"type": "platform"
},
"Microsoft.AspNet.Tooling.Razor": "1.0.0-rc1-final",
"Microsoft.AspNetCore.Diagnostics": "1.0.0",
"Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0",
"Microsoft.AspNetCore.Mvc": "1.0.1",
"Microsoft.AspNetCore.Mvc.TagHelpers": "1.0.1",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
"Microsoft.AspNetCore.StaticFiles": "1.0.0",
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.1",
"Microsoft.Extensions.Configuration.FileExtensions": "1.1.0",
"Microsoft.Extensions.Configuration.Json": "1.1.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Microsoft.AspNetCore.Routing": "1.0.1",
"Microsoft.AspNetCore.Razor.Tools": {
"version": "1.0.0-preview2-final",
"type": "build"
},
"Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
"version": "1.0.0-preview2-final",
"type": "build"
},
"Microsoft.VisualStudio.Web.CodeGenerators.Mvc": {
"version": "1.0.0-preview2-final",
"type": "build"
}
},
"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final",
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"
},
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"portable-net45+win8"
]
}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"runtimeOptions": {
"configProperties": {
"System.GC.Server": true
}
},
"publishOptions": {
"include": [
"wwwroot",
"web.config"
]
},
"scripts": {
"prepublish": [ "bower install" ],
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}
Do you have Resharper installed? It seems there's a problem with it and .NET Core syntax highlighting and intellisense.
http://blog.jetbrains.com/dotnet/2016/05/27/resharper-ultimate-2016-2-eap-kicks-off/
Initial support of ASP.NET Core 1.0 RC2, including support for tag helpers in terms of code completion, navigation, search and refactorings. At this point, ASP.NET Core web applications are supported if they’re targeting .NET Framework but are not supported if they’re targeting .NET Core. We’re looking to improve this in subsequent builds.
So if you have a library targeting .netstandard1.5 Resharper will not correctly display intellisense information but the project will compile.
However if you add the .netcoreapp1.0 framework as an additional framework to the project.json file Resharper will work and you get full intellisense support.
frameworks": {
"netstandard1.5": {
"imports": [ "dnxcore50", "portable-net45+win8" ],
"dependencies": {
"NETStandard.Library": "1.5.0-rc2-24027",
"System.Security.Principal": "4.0.1-rc2-24027"
}
},
".netcoreapp1.0": {
"imports": [ "dnxcore50", "portable-net45+win8" ]
}
},
How to fix intellisense with referenced netstandard1.5 library projects in Visual Studio 2015?
After hours of trying different packages and searching forums and issue threads, I gave this package a shot Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final and this seemed to do the trick. All the syntax highlighting seemed to take effect once I referenced this package.

ASP.NET Core build on different platforms

I created a simple ASP.NET Core application and I want to build it on Windows 10 for Windows 10 and CentOS 7. So my I have this in my project.json file:
"runtimes": {
"win10-x64": { },
"centos.7-x64": { },
"win81-x64": { }
},
Without "win81-x64" I got an error:
Can not find runtime target for framework '.NETCoreApp,Version=v1.0' compatible with one of the target runtimes: 'win81-x64, win8-x64, win7-x64'
After dotnet build command i see this:
Project ListService (.NETCoreApp,Version=v1.0) will be compiled because expected outputs are missing Compiling ListService for .NETCoreApp,Version=v1.0
Compilation succeeded.
0 Warning(s)
0 Error(s)
Time elapsed 00:00:14.3853704
And command dotnet --info shows:
Product Information:
Version: 1.0.0-preview2-003131
Commit SHA-1 hash: 635cf40e58
Runtime Environment:
OS Name: Windows
OS Version: 6.3.9600
OS Platform: Windows
RID: win81-x64
Am I missing something? Also the dotnet publish -r foo-version did not helped.
{
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.1"
},
"Microsoft.ApplicationInsights.AspNetCore": "1.0.0",
"Microsoft.AspNetCore.Mvc": "1.0.1",
"Microsoft.AspNetCore.Routing": "1.0.1",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
"Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.Logging": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0"
},
"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
},
"runtimes": {
"win10-x64": { },
"centos.7-x64": { },
"win81-x64": { }
},
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"portable-net45+win8"
]
}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"runtimeOptions": {
"configProperties": {
"System.GC.Server": true
}
},
"publishOptions": {
"include": [
"wwwroot",
"**/*.cshtml",
"appsettings.json",
"web.config"
]
},
"scripts": {
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}
Ok so now it works.
What I did was:
I removed "type":"platform" from project.json file
I ran command dotnet build -r centos.7-x64 in cmd from project folder
And now i see

Error when trying to referance .net core Class library from Web app ASP.NET Core RC2

So it sounds like a trivial task, I just want to use common code from my class library in both my web api and webapp but I am unable to reference the class library from my webapp projects, so I made a clean project to test it out.
I have 3 projects:ClassLib1, ClassLib2, WebApp
I am able to reference ClassLib1 From ClassLib2 but I cannot referance either Class librarys from the webapp project
Here are my project.json's
ClassLib1
{
"version": "1.0.0-*",
"dependencies": {
"NETStandard.Library": "1.5.0-rc2-24027"
},
"frameworks": {
"netstandard1.5": {
}
}
}
ClassLib2 is exactly the same as ClassLib1
Web App
{
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.0-rc2-3002702",
"type": "platform"
},
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-final",
"ClassLib1": "1.0.0-*"
},
"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": {
"version": "1.0.0-preview1-final",
"imports": "portable-net45+win8+dnxcore50"
}
},
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"portable-net45+win8"
]
}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"runtimeOptions": {
"gcServer": true
},
"publishOptions": {
"include": [
"wwwroot",
"web.config"
]
},
"scripts": {
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}
SS showing using ClassLib1 in ClassLib2 successfully
SS showing error in webapp when trying to use ClassLib1
The error when moused over is `cannot resolve symbol 'ClassFromLib1'
Edit: I just noticed that if I change the web app to use netstandard1.5 from netcoreapp1.0 I can then referance code between the projects.
Should I do this? are there any downside by changing the framework in targeting?
So I figured out that the issue I was having was with Resharper. It was making the text red and giving me the errors, it did actually build and work fine but I just didn't see past the red text.

Resources