首页 新闻 会员 周边 捐助

新建.net core MVC 视图和控制器项目,运行时services.AddMvc()报错

0
[已解决问题] 解决于 2020-11-26 11:52

新建.net core MVC 视图和控制器项目,运行时services.AddMvc()报错

给位大佬这是什么原因,叩谢!!!

笑叹、的主页 笑叹、 | 初学一级 | 园豆:34
提问于:2020-11-25 15:45
< >
分享
最佳答案
0

经过测试验证,是文件夹目录中包含#的原因。项目从2.0升级2.1,2.0时文件目录和发布目录包含#没问题,升级2.1就不行,感谢!!!

笑叹、 | 初学一级 |园豆:34 | 2020-11-26 11:52
其他回答(3)
0

项目是怎么运行的?

dudu | 园豆:30778 (高人七级) | 2020-11-25 16:41

直接F5运行,我换了个磁盘创建可以,但发布后部署在iis又出现这个问题

支持(0) 反对(0) 笑叹、 | 园豆:34 (初学一级) | 2020-11-26 10:21

这是发布之后的错误提示

Application startup 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, Func2 fileExists, Func2 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 Tencent.Web.Startup.ConfigureServices(IServiceCollection services) in D:\Demo\Tencent.Web\Startup.cs:line 38
--- 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()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
crit: Microsoft.AspNetCore.Hosting.Internal.WebHost[6]
Application startup 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, Func2 fileExists, Func2 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 Tencent.Web.Startup.ConfigureServices(IServiceCollection services) in D:\Demo\Tencent.Web\Startup.cs:line 38
--- 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()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
Hosting environment: Production
Content root path: D:#Publish\Demo
Now listening on: http://127.0.0.1:2668
Application started. Press Ctrl+C to shut down.
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
Request starting HTTP/1.1 GET http://localhost/
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
Request finished in 13.1851ms 500 text/html; charset=utf-8
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
Request starting HTTP/1.1 GET http://localhost/favicon.ico
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
Request finished in 0.3941ms 500 text/html; charset=utf-8

支持(0) 反对(0) 笑叹、 | 园豆:34 (初学一级) | 2020-11-26 10:28
0

新建项目是不可能有这样的问题的。首先回答@dudu的问题是怎样运行的?

Jonny-Xhl | 园豆:691 (小虾三级) | 2020-11-25 17:41
0


参数path1是什么

刘下来 | 园豆:919 (小虾三级) | 2020-11-26 10:29

services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

支持(0) 反对(0) 笑叹、 | 园豆:34 (初学一级) | 2020-11-26 10:45

官方就是这样写,这个里面没有传递参数的地方

支持(0) 反对(0) 笑叹、 | 园豆:34 (初学一级) | 2020-11-26 10:46
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册