无法在.net-core 2上运行简单的程序。

时间:2018-08-29 17:40:44

标签: asp.net-core .net-core asp.net-core-mvc

尝试开始使用.netcore编程。遵循了asp.net网站上的基本说明,但失败了。

https://www.asp.net/get-started

dotnet运行命令后出现错误(附加)。 powershell_output

这是我全新安装最新SDK之后的第一个程序(到目前为止)。我已经尝试过控制台应用程序,并且效果很好。即使是带有“网络”模板的简单应用程序也可以正常运行,并在浏览器中显示“ Hello World”。但是,一旦我将“ services.addMVC”添加到应用程序,它就会因相同的错误而中断。我已经做了所有的研究,并尝试了很多事情,但不确定是怎么回事。

     NIN@DATASCAPE  C\..\dotnetcore  md tryx


    Directory: C:\#NIN\dotnetcore


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       30/08/2018   1:15 AM                tryx


 ⚡ NIN@DATASCAPE  C\..\dotnetcore  cd tryx
 ⚡ NIN@DATASCAPE  C\..\..\tryx  dotnet --info
.NET Core SDK (reflecting any global.json):
 Version:   2.1.401
 Commit:    91b1c13032

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.17134
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.1.401\

Host (useful for support):
  Version: 2.1.3
  Commit:  124038c13e

.NET Core SDKs installed:
  2.1.401 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download
 ⚡ NIN@DATASCAPE  C\..\..\tryx  dotnet new webapp -o try1
The template "ASP.NET Core Web App" was created successfully.
This template contains technologies from parties other than Microsoft, see https://aka.ms/aspnetcore-template-3pn-210 for details.

Processing post-creation actions...
Running 'dotnet restore' on try1\try1.csproj...
  Restoring packages for C:\#NIN\dotnetcore\tryx\try1\try1.csproj...
  Generating MSBuild file C:\#NIN\dotnetcore\tryx\try1\obj\try1.csproj.nuget.g.props.
  Generating MSBuild file C:\#NIN\dotnetcore\tryx\try1\obj\try1.csproj.nuget.g.targets.
  Restore completed in 9.24 sec for C:\#NIN\dotnetcore\tryx\try1\try1.csproj.

Restore succeeded.

 ⚡ NIN@DATASCAPE  C\..\..\tryx  cd .\try1\
 ⚡ NIN@DATASCAPE  C\..\..\..\try1  ls


    Directory: C:\#NIN\dotnetcore\tryx\try1


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       30/08/2018   1:17 AM                obj
d-----       30/08/2018   1:17 AM                Pages
d-----       30/08/2018   1:17 AM                Properties
d-----       30/08/2018   1:17 AM                wwwroot
-a----       30/08/2018   1:17 AM            146 appsettings.Development.json
-a----       30/08/2018   1:17 AM            105 appsettings.json
-a----       30/08/2018   1:17 AM            626 Program.cs
-a----       30/08/2018   1:17 AM           1856 Startup.cs
-a----       30/08/2018   1:17 AM            242 try1.csproj


 ⚡ NIN@DATASCAPE  C\..\..\..\try1  dotnet dev-certs https --trust
Trusting the HTTPS development certificate was requested. A confirmation prompt will be displayed if the certificate was not previously trusted. Click yes on the prompt to trust the certificate.
A valid HTTPS certificate is already present.
 ⚡ NIN@DATASCAPE  C\..\..\..\try1  dotnet run
Using launch settings from C:\#NIN\dotnetcore\tryx\try1\Properties\launchSettings.json...

Unhandled Exception: System.ArgumentNullException: Value cannot be null.
Parameter name: path1
   at System.IO.Path.Combine(String path1, String path2)
   at Microsoft.AspNetCore.Mvc.ApplicationParts.RelatedAssemblyAttribute.GetRelatedAssemblies(Assembly assembly, Boolean throwOnError, Func`2 fileExists, Func`2 loadFile)
   at Microsoft.AspNetCore.Mvc.ApplicationParts.RelatedAssemblyAttribute.GetRelatedAssemblies(Assembly assembly, Boolean throwOnError)
   at Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationAssembliesProvider.GetRelatedAssemblies(Assembly assembly)
   at Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationAssembliesProvider.GetAssemblyItem(Assembly assembly)
   at Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationAssembliesProvider.ResolveFromDependencyContext(DependencyContext dependencyContext)
   at Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationAssembliesProvider.ResolveAssemblies(Assembly entryAssembly)+MoveNext()
   at Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartManager.PopulateDefaultParts(String entryAssemblyName)
   at Microsoft.Extensions.DependencyInjection.MvcCoreServiceCollectionExtensions.GetApplicationPartManager(IServiceCollection services)
   at Microsoft.Extensions.DependencyInjection.MvcCoreServiceCollectionExtensions.AddMvcCore(IServiceCollection services)
   at Microsoft.Extensions.DependencyInjection.MvcServiceCollectionExtensions.AddMvc(IServiceCollection services)
   at try1.Startup.ConfigureServices(IServiceCollection services) in C:\#NIN\dotnetcore\tryx\try1\Startup.cs:line 35
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.ConfigureServices(IServiceCollection services)
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureApplicationServices()
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.Initialize()
   at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
   at try1.Program.Main(String[] args) in C:\#NIN\dotnetcore\tryx\try1\Program.cs:line 17
 ⚡ NIN@DATASCAPE  C\..\..\..\try1 

1 个答案:

答案 0 :(得分:0)

我也遇到了同样的问题,这是由于项目路径(C:\#WorkSpace \ api \ .. etc)中的特殊数字符号引起的,通过移动到另一个目录,它可以正常工作