ASP.NET MVC应用程序无法访问路径错误 - c#

我已经在论坛上搜索了答案,但是没有任何效果,即时通讯正处于障碍之中。我使用默认模板制作了一个基本的MVC应用程序,并添加了一个.mdf数据库文件(包含有关学生和课程信息的基本数据库)。我为数据库中的每个表添加了带有基本类的ADO.NET实体模型。然后,我添加了一个控制器,以仅显示数据库中的每个项目。现在,当我第一次运行该程序时,一切正常,并且列出了所有项目。如果我关闭站点并重建,我将无法访问路径错误,并且无法从某些路径中删除文件错误。如果我注销,登录,然后从项目位置删除obj和bin文件夹,打开Visual Studio社区2017,然后再次进行重建,则它将首次运行。然后其相同的问题具有相同的错误。该数据库是使用Visual Studio创建的。我认为这是一个项目,因此我启动了一个新项目,删除了.mdf文件以外的所有旧文件,无论我使用哪个项目,即使是一个全新的项目,它只能正确编译1次。我尝试以管理员身份运行,遵循我在该站点上可以执行的操作,但似乎没有任何效果,这绝对使我感到沮丧。我在管理员帐户上,所以不能成为问题。我得到的错误如下:

“ C:\ Users \ Austin \ source \ repos \ StudentRegistrationSystem \ packages \ Microsoft.Net.Compilers.2.1.0 \ tools \ System.Collections.Immutable.dll”
到“ bin \ roslyn \ System.Collections.Immutable.dll”。进入路径
'bin \ roslyn \ System.Collections.Immutable.dll'是
否认。 StudentRegistrationSystem错误无法复制文件
“ C:\ Users \ Austin \ source \ repos \ StudentRegistrationSystem \ packages \ Microsoft.Net.Compilers.2.1.0 \ tools \ System.Diagnostics.FileVersionInfo.dll”
到“ bin \ roslyn \ System.Diagnostics.FileVersionInfo.dll”。进入
路径'bin \ roslyn \ System.Diagnostics.FileVersionInfo.dll'是
否认。 StudentRegistrationSystem警告无法删除文件
“ C:\ Users \ Austin \ source \ repos \ StudentRegistrationSystem \ StudentRegistrationSystem \ bin \ roslyn \ VBCSCompiler.exe”。
进入路径
'C:\ Users \ Austin \ source \ repos \ StudentRegistrationSystem \ StudentRegistrationSystem \ bin \ roslyn \ VBCSCompiler.exe'
被拒绝。 StudentRegistrationSystem警告无法删除文件
“ C:\ Users \ Austin \ source \ repos \ StudentRegistrationSystem \ StudentRegistrationSystem \ bin \ roslyn \ System.IO.Compression.dll”。
进入路径
'C:\ Users \ Austin \ source \ repos \ StudentRegistrationSystem \ StudentRegistrationSystem \ bin \ roslyn \ System.IO.Compression.dll'
被拒绝。 StudentRegistrationSystem警告无法删除文件
“ C:\ Users \ Austin \ source \ repos \ StudentRegistrationSystem \ StudentRegistrationSystem \ bin \ roslyn \ Microsoft.DiaSymReader.Native.amd64.dll”。
进入路径
'C:\ Users \ Austin \ source \ repos \ StudentRegistrationSystem \ StudentRegistrationSystem \ bin \ roslyn \ Microsoft.DiaSymReader.Native.amd64.dll'
被拒绝。 StudentRegistrationSystem警告无法删除文件
“ C:\ Users \ Austin \ source \ repos \ StudentRegistrationSystem \ StudentRegistrationSystem \ bin \ roslyn \ Microsoft.CodeAnalysis.VisualBasic.dll”。
进入路径
'C:\ Users \ Austin \ source \ repos \ StudentRegistrationSystem \ StudentRegistrationSystem \ bin \ roslyn \ Microsoft.CodeAnalysis.VisualBasic.dll'
被拒绝。 StudentRegistrationSystem警告无法删除文件
“ C:\ Users \ Austin \ source \ repos \ StudentRegistrationSystem \ StudentRegistrationSystem \ bin \ roslyn \ Microsoft.CodeAnalysis.dll”。
进入路径
'C:\ Users \ Austin \ source \ repos \ StudentRegistrationSystem \ StudentRegistrationSystem \ bin \ roslyn \ Microsoft.CodeAnalysis.dll'
被拒绝。 StudentRegistrationSystem错误无法复制文件
“ C:\ Users \ Austin \ source \ repos \ StudentRegistrationSystem \ packages \ Microsoft.Net.Compilers.2.1.0 \ tools \ System.ValueTuple.dll”
到“ bin \ roslyn \ System.ValueTuple.dll”。进入路径
'bin \ roslyn \ System.ValueTuple.dll'是
否认。 StudentRegistrationSystem警告无法删除文件
“ C:\ Users \ Austin \ source \ repos \ StudentRegistrationSystem \ StudentRegistrationSystem \ bin \ roslyn \ Microsoft.CodeAnalysis.CSharp.dll”。
进入路径
'C:\ Users \ Austin \ source \ repos \ StudentRegistrationSystem \ StudentRegistrationSystem \ bin \ roslyn \ Microsoft.CodeAnalysis.CSharp.dll'
被拒绝。 StudentRegistrationSystem错误无法复制文件
“ C:\ Users \ Austin \ source \ repos \ StudentRegistrationSystem \ packages \ Microsoft.Net.Compilers.2.1.0 \ tools \ System.Security.Cryptography.Primitives.dll”
到“ bin \ roslyn \ System.Security.Cryptography.Primitives.dll”。进入
路径'bin \ roslyn \ System.Security.Cryptography.Primitives.dll'为
否认。 StudentRegistrationSystem错误无法复制文件
“ C:\ Users \ Austin \ source \ repos \ StudentRegistrationSystem \ packages \ Microsoft.Net.Compilers.2.1.0 \ tools \ System.Security.Cryptography.Algorithms.dll”
到“ bin \ roslyn \ System.Security.Cryptography.Algorithms.dll”。进入
路径'bin \ roslyn \ System.Security.Cryptography.Algorithms.dll'为
否认。 StudentRegistrationSystem错误无法复制文件
“ C:\ Users \ Austin \ source \ repos \ StudentRegistrationSystem \ packages \ Microsoft.Net.Compilers.2.1.0 \ tools \ System.IO.FileSystem.Primitives.dll”
到“ bin \ roslyn \ System.IO.FileSystem.Primitives.dll”。进入
路径'bin \ roslyn \ System.IO.FileSystem.Primitives.dll'是
否认。 StudentRegistrationSystem错误无法复制文件
“ C:\ Users \ Austin \ source \ repos \ StudentRegistrationSystem \ packages \ Microsoft.Net.Compilers.2.1.0 \ tools \ System.Reflection.Metadata.dll”
到“ bin \ roslyn \ System.Reflection.Metadata.dll”。进入路径
'bin \ roslyn \ System.Reflection.Metadata.dll'是
否认。 StudentRegistrationSystem错误无法复制文件
“ C:\ Users \ Austin \ source \ repos \ StudentRegistrationSystem \ packages \ Microsoft.Net.Compilers.2.1.0 \ tools \ System.IO.FileSystem.dll”
到“ bin \ roslyn \ System.IO.FileSystem.dll”。进入路径
'bin \ roslyn \ System.IO.FileSystem.dll'是
否认。学生注册系统

很难完整地解释这个问题,我将回答任何人的任何问题。这真的很令人沮丧,也不确定它是否归结于我的Visual Studio Community 2017版本。

我拥有2017年最新的Visual Studio社区。即使在使用新数据库的新项目中,该错误似乎仍然存在。

更新
刚刚构建了一个全新的项目,一个全新的sql server数据库,在其中放置了一个表,并在其中添加了一个条目,为我的测试数据库添加了一个条目的ADO.NET实体模型,并添加了带有自动生成视图的控制器以列出其中的所有项数据库,并且第一次工作,重建后也给了我同样的错误。

参考方案

看来您遭受的是项目的Roslyn版本冲突。您可能已经安装了某些依赖项(可能是Nuget或与项目模板一起提供的),与为项目安装的Roslyn版本冲突。

如果查看上面的跟踪中的大量错误,您会发现问题出在编译器努力复制与Roslyn相关的库这一事实。这是一个例子:

无法将文件“ C:\ Users \ Austin \ source \ repos \ StudentRegistrationSystem \ packages \ Microsoft.Net.Compilers.2.1.0 \ tools \ System.Security.Cryptography.Algorithms.dll”复制到“ bin \ roslyn \ System”。 Security.Cryptography.Algorithms.dll”。拒绝访问路径“ bin \ roslyn \ System.Security.Cryptography.Algorithms.dll”。学生注册系统

就解决方案而言,您有两种选择:

选项#1:良好的旧时尚删除密钥。

转到您的\bin\roslyn文件夹并删除其中的所有内容;并重新编译您的项目。这将导致Visual Studio重新计算依赖关系,并为项目所需的Roslyn选择正确的库版本,并将其放回\bin\roslyn文件夹中。

选项#2删除罗斯林

事实是,对于您的用例,您可能实际上不需要Roslyn用于您的项目,并且您可以摆脱依赖关系...是的,没有它就可以正常工作。除非您的项目正在做一些非常酷的代码分析工作,否则您可能根本不需要Roslyn库。

为了清楚起见:我不建议使用Option#2,但是如果需要,可以将其删除。这是Galdin Raphael的一篇简短博客文章,解释了如何从项目=> https://gldraphael.com/blog/removing-roslyn-from-asp-net-4-5-2-project-template/中抽出Roslyn。

ddl在服务器中未更新-asp.net - javascript

我在ASP.NET c#上工作。我有一个DropDownList。 (runat =“ server”)在$ {document).ready上,我更新了它的值:$(document).ready(function () { document.getElementById("ddl").value = "abc"; ……

ASP.NET MVC 5自定义登录,无需脚手架,数据库优先 - c#

我对asp.net和mvc还是很陌生,所以我正在努力学习尽可能多的知识...为此,我从头开始编写博客网站,但是我对身份验证和授权有些困惑。由于我倾向于不真正使用任何脚手架的东西,所以我首先要使用数据库,所以不希望asp.net身份为我创建表。我对散列和加盐密码很酷,并对照数据库检查用户,我遇到的麻烦是将用户设置为登录状态并检查他们应该能够访问什么。我真的很想…

asp.net mvc或javascript将另一页的结果返回给方法 - c#

是否可以将另一个页面的结果返回给JavaScript方法或C#控制器操作?我有一个共享的复杂页面,该页面在我的网站上遍布使用,当前用于在C#后端的用户数据上设置单个变量。当用户完成共享的复杂页面后,我将返回引用页面。当用户在刷新或返回时将其作为url参数传递给返回的页面时,我返回的页面包含新选择的变量。我有一个新页面,我希望从我的共享复杂页面中返回该变量。但…

ASP.NET-如何更改JSON序列化的方式? - javascript

我正在使用ASP.NET通过以下查询返回Json文件:public ActionResult getTransactionTotals(int itemID) { DBEntities db = new DBEntities(); var query = from trans in db.Transactions // Linq query removed …

asp.net oledbcommand返回所有行 - c#

我正在使用Oledbconnection连接到Microsoft Access数据库,并且正在使用OleDbCommand检索一些信息。我在数据库中有一个名为retrieveInfo的查询,该查询检索3行数据。字段中有一些重复项,但是应该是这样。我的数据如下所示: Name Email A [email protected] B [email protected] B C@gmai…