简体   繁体   English

安装 ASP.NET 和 Web Tools 2015 后出现 Visual Studio 错误“未将对象引用设置为对象的实例”

[英]Visual Studio error "Object reference not set to an instance of an object" after install of ASP.NET and Web Tools 2015

After installing the ASP.NET and Web Tools 2015 (RC1 update 1) I get the following error within ASP.NET MVC 4 projects when opening *.cshtml files:安装 ASP.NET 和 Web Tools 2015(RC1 更新 1)后,我在 ASP.NET MVC 4 项目中打开*.cshtml文件时出现以下错误:

Object reference not set to instance of an object未将对象引用设置为对象的实例

在此处输入图片说明

I get the same error message even if I start a new ASP.NET MVC 4 project and try to open a *.cshtml file there.即使我开始一个新的 ASP.NET MVC 4 项目并尝试在那里打开一个*.cshtml文件,我也会收到相同的错误消息。

I'm using Visual Studio 2015我正在使用 Visual Studio 2015

Maybe this helps:也许这有帮助:

  1. Delete the contents from the following folders:删除以下文件夹中的内容:
    1. C:\\Users\\%userprofile%\\AppData\\Local\\Microsoft\\VisualStudio C:\\Users\\%userprofile%\\AppData\\Local\\Microsoft\\VisualStudio
    2. C:\\Users\\%userprofile%\\AppData\\Local\\Microsoft\\VSCommon C:\\Users\\%userprofile%\\AppData\\Local\\Microsoft\\VSCommon
  2. Sometimes, you need to go to:有时,您需要访问:
    1. [x64] C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Common7\\IDE [x64] C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Common7\\IDE
    2. [x86] C:\\Program Files\\Microsoft Visual Studio 14.0\\Common7\\IDE [x86] C:\\Program Files\\Microsoft Visual Studio 14.0\\Common7\\IDE

and run devenv /resetuserdata .并运行devenv /resetuserdata

Expect, that all of your user settings such as Visual Studio layout, linked Microsoft account or start page might disappear.预计您的所有用户设置(例如 Visual Studio 布局、链接的 Microsoft 帐户或起始页)可能会消失。

Delete %LocalAppData%\\Microsoft\\VisualStudio\\14.0\\ComponentModelCache and restart Visual Studio.删除%LocalAppData%\\Microsoft\\VisualStudio\\14.0\\ComponentModelCache并重新启动 Visual Studio。

Alternatively, use the Clear MEF Component Cache extension.或者,使用清除 MEF 组件缓存扩展。

For me,为了我,

  1. I ended the process in Windows Task Manager: VsHub.exe .我在 Windows 任务管理器中结束了这个过程: VsHub.exe
  2. Restarted Visual Studio.重新启动 Visual Studio。

After that, everything works like a charm again!在那之后,一切都像魅力一样!

I solved it doing我解决了它

run devenv /resetuserdata

in this path:在这条路上:

[x64] C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE

I assume that in x86 it works in this path:我假设在 x86 中它在这个路径中工作:

[x86] C:\Program Files\Microsoft Visual Studio 14.0\Common7\IDE

It's recommended to try any or all of the following:建议尝试以下任何或所有方法:

  • Restart Visual Studio重新启动 Visual Studio

  • Try Running As Administrator (right-click Visual Studio and choose "Run As Administrator")尝试以管理员身份运行(右键单击 Visual Studio 并选择“以管理员身份运行”)

  • Check for any updates for Visual Studio (download and install them if any are available)检查 Visual Studio 的任何更新(如果有,请下载并安装它们)

  • Try opening a different solution / project尝试打开不同的解决方案/项目

If problems persist, you might try the following options:如果问题仍然存在,您可以尝试以下选项:

  • Restart your local machine重启你的本地机器

  • Attempt to reset Visual Studio to System Defaults (this can be done from the options within Visual Studio)尝试将 Visual Studio 重置为系统默认值(这可以通过 Visual Studio 中的选项完成)

  • Attempt to repair your Visual Studio installation尝试修复您的 Visual Studio 安装

For me, ASP.NET 5 is not yet required, I removed update, and then reinstalled ASP.NET 4.5.对我来说,还不需要 ASP.NET 5,我删除了更新,然后重新安装了 ASP.NET 4.5。 It's a bit tricky:这有点棘手:

  1. Removed from control panel "Microsoft ASP.NET 5 RC1 Update1".从控制面板“Microsoft ASP.NET 5 RC1 Update1”中删除。 After that, you will no longer open ASP.NET MVC projects之后,您将不再打开 ASP.NET MVC 项目
  2. Then I changed the installation of "Microsoft Visual Studio Professional 2015", clicked "Modify", and selected "Microsoft Web Developer Tools"然后我更改了“Microsoft Visual Studio Professional 2015”的安装,点击“修改”,选择“Microsoft Web Developer Tools”

No longer follow the notification of update in Visual Studio 2015!!!不再关注 Visual Studio 2015 中的更新通知!!!

In the hopes it might narrow things down/help someone, I did an investigatory approach.希望它可以缩小范围/帮助某人,我做了一个调查方法。 For me, I initially moved the folder at C:\\Users\\{user}\\AppData\\Local\\Microsoft\\VisualStudio to My Documents and allowed Visual Studio to re-create it by re-launching it.对我来说,我最初将位于 C:\\Users\\{user}\\AppData\\Local\\Microsoft\\VisualStudio 的文件夹移动到我的文档,并允许 Visual Studio 通过重新启动来重新创建它。 This removed the errors.这消除了错误。 So I moved everything back, one-by-one, and restarted Visual Studio each time until I discovered the culprits.因此,我将所有内容一一移回,并每次都重新启动 Visual Studio,直到发现罪魁祸首。 These folders were fine to move back in:这些文件夹可以移回:

  • 1033 (overwrote the auto-generated copy with old) 1033(用旧覆盖自动生成的副本)
  • Designer (was in my old copy, not initially re-created when I re-launched VS, copied it back in)设计器(在我的旧副本中,最初在我重新启动 VS 时没有重新创建,而是将其复制回来)
  • Extensions (overwrote the auto-generated copy with old)扩展(用旧覆盖自动生成的副本)
  • ImageLibrary (overwrote the auto-generated copy with old) ImageLibrary(用旧覆盖自动生成的副本)
  • Notifications (overwrote the auto-generated copy with old)通知(用旧覆盖自动生成的副本)
  • STemplate (was in my old copy, not initially re-created when I re-launched VS, copied it back in) STemplate(在我的旧副本中,最初没有在我重新启动 VS 时重新创建,而是将其复制回来)
  • VTC (was in my old copy, not initially re-created when I re-launched VS, copied it back in) VTC(在我的旧副本中,最初没有在我重新启动 VS 时重新创建,而是将其复制回来)

These files were fine to move back in/overwrite the auto-generated ones:这些文件可以移回/覆盖自动生成的文件:

  • ApplicationPrivateSettings (was in my old copy, not initially re-created when I re-launched VS) ApplicationPrivateSettings(在我的旧副本中,最初在我重新启动 VS 时没有重新创建)
  • ApplicationPrivateSettings.lock (overwrote the auto-generated copy with old) ApplicationPrivateSettings.lock(用旧覆盖自动生成的副本)
  • vspdmc.lock (overwrote the auto-generated copy with old) vspdmc.lock(用旧覆盖自动生成的副本)

These files were fine to move back in. Each was in my old copy, and not initially re-created when I re-launched VS:这些文件可以移回。每个文件都在我的旧副本中,并且在我重新启动 VS 时最初没有重新创建:

  • .NETFramework,Version=v4.0,Set=Framework,Hash=C958D412.dat .NETFramework,Version=v4.0,Set=Framework,Hash=C958D412.dat
  • .NETFramework,Version=v4.0,Set=RecentAssemblies,Hash=0.dat .NETFramework,Version=v4.0,Set=RecentAssemblies,Hash=0.dat
  • .NETFramework,Version=v4.5,Set=Extensions,Hash=75EAE334.dat .NETFramework,Version=v4.5,Set=Extensions,Hash=75EAE334.dat
  • .NETFramework,Version=v4.5,Set=Extensions,Hash=497525A2.dat .NETFramework,Version=v4.5,Set=Extensions,Hash=497525A2.dat
  • .NETFramework,Version=v4.5,Set=Framework,Hash=5AE9A175.dat .NETFramework,Version=v4.5,Set=Framework,Hash=5AE9A175.dat
  • .NETFramework,Version=v4.5.2,Set=Extensions,Hash=24CEEB0D.dat .NETFramework,Version=v4.5.2,Set=Extensions,Hash=24CEEB0D.dat
  • .NETFramework,Version=v4.5.2,Set=Extensions,Hash=72AE305.dat .NETFramework,Version=v4.5.2,Set=Extensions,Hash=72AE305.dat
  • .NETFramework,Version=v4.5.2,Set=Extensions,Hash=ADF899D7.dat .NETFramework,Version=v4.5.2,Set=Extensions,Hash=ADF899D7.dat
  • .NETFramework,Version=v4.5.2,Set=Framework,Hash=D8E943A2.dat .NETFramework,Version=v4.5.2,Set=Framework,Hash=D8E943A2.dat

These caused problems - delete these files and re-launch VS to allow it to re-create them:这些引起的问题 - 删除这些文件并重新启动 VS 以允许它重新创建它们:

  • ComponentModelCache - When I overwrote this folder's contents with my old ones (4 files: MS.VS.Default.cache, .catalogs, .err, .external), this gave me all of the errors I had gotten before about not being able to load packages when loading my project, and the "object reference not set to an instance of an object" error when trying to close VS. ComponentModelCache - 当我用我的旧文件(4 个文件:MS.VS.Default.cache、.catalogs、.err、.external)覆盖这个文件夹的内容时,这给了我之前遇到的关于无法执行的所有错误加载我的项目时加载包,并在尝试关闭 VS 时出现“对象引用未设置为对象的实例”错误。
  • devenv.exe.config - same as ComponentModelCache devenv.exe.config - 与 ComponentModelCache 相同
  • .NETFramework,Version=v4.0,Set=Extensions,Hash=6D09DECC.dat - causes error output from the JavaScript Language Service, complaining of missing js files .NETFramework,Version=v4.0,Set=Extensions,Hash=6D09DECC.dat - 导致 JavaScript 语言服务输出错误,抱怨缺少 js 文件
  • .NETFramework,Version=v4.0,Set=Extensions,Hash=9951BC03.dat - causes error output from the JavaScript Language Service, complaining of missing js files .NETFramework,Version=v4.0,Set=Extensions,Hash=9951BC03.dat - 导致 JavaScript 语言服务输出错误,抱怨缺少 js 文件
  • .NETFramework,Version=v4.5.2,Set=RecentAssemblies,Hash=0.dat - causes error output from the JavaScript Language Service, complaining of missing js files .NETFramework,Version=v4.5.2,Set=RecentAssemblies,Hash=0.dat - 导致 JavaScript 语言服务输出错误,抱怨缺少 js 文件

These are the errors from those last .NETFramework files (which I do not get if I do not add them back in):这些是来自最后那些 .NETFramework 文件的错误(如果我不重新添加它们,我不会得到这些文件):

01:10:11.7550: Referenced file 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\JavaScript\References\libhelp.js' not found.
01:10:11.7550: Referenced file 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\JavaScript\References\sitetypesWeb.js' not found.
01:10:11.7550: Referenced file 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\JavaScript\References\domWeb.js' not found.
01:10:11.7550: Referenced file 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\JavaScript\References\underscorefilter.js' not found.
01:10:11.7550: Referenced file 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\JavaScript\References\showPlainComments.js' not found.

I might just need to re-install/repair the JavaScript Language Service plug-in, so it might be un-related.我可能只需要重新安装/修复 JavaScript 语言服务插件,所以它可能是无关的。 But definitely devenv.exe.config and ComponentModelCache need to go to correct the "object reference not set to an instance of an object" error.但绝对 devenv.exe.config 和 ComponentModelCache 需要去纠正“对象引用未设置为对象的实例”错误。

After trying the top answer, I found that you must also restart the computer.在尝试了最佳答案后,我发现您还必须重新启动计算机。 The error may be part of a git issue as well where restarting your computer will reset.该错误可能是 git 问题的一部分,也可能是重新启动计算机将重置的地方。

In my case (not necessarily be the solution for you, but it may be helpful for someone), the solution was:就我而言(不一定是您的解决方案,但可能对某人有帮助),解决方案是:

  1. Go menu ToolsExtensions and Updates转到菜单工具扩展和更新

  2. Select the Online tab from the right panel从右侧面板中选择“ Online选项卡

  3. Search for the words web tools , and then select Microsoft ASP.NET and Web Tools and install it.搜索词web tools ,然后选择Microsoft ASP.NET and Web Tools并安装它。

In my case, this was missing from my computer because of a lot of repairing operations for Visual Studio.就我而言,由于对 Visual Studio 进行了大量修复操作,因此我的计算机中缺少此信息。

I was getting an exception every time I tried to create a "new" project.每次尝试创建“新”项目时,我都会遇到异常。

My solution was:我的解决方案是:

  1. Go menu ToolsExtensions and Updates转到菜单工具扩展和更新

  2. Check the "Updates" link... There was an update to Microsoft ASP.NET and Web Tools.检查“更新”链接... Microsoft ASP.NET 和 Web 工具有更新。 Install it.安装它。

That fixed it for me.那为我修好了。

I was getting this exception every time I created a "new" project.每次我创建一个“新”项目时,我都会遇到这个异常。

My solution was:我的解决方案是:

  • Go menu Tools ?转到菜单工具 Extensions and Updates扩展和更新
  • Not check the "Updates" link...search "asp.net".不检查“更新”链接...搜索“asp.net”。 There was an update to Microsoft ASP.NET and Web Tools. Microsoft ASP.NET 和 Web 工具有更新。 Get it as AspNetWebFrameworksTools2015_KB3137909.exe and install it.将其作为 AspNetWebFrameworksTools2015_KB3137909.exe 获取并安装。

That fixed it for me.那为我修好了。


Unfortunately, I ran into another exception:不幸的是,我遇到了另一个例外:

"Exception has been thrown by the target of an invocation" “调用的目标已抛出异常”

I disabled the FIPS setting Enabled DWORD value to zero.我将FIPS设置 Enabled DWORD值禁用为零。

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\FipsAlgorithmPolicy]
Enabled=dword:00000000 And All fixed.

Goto windows+R and type %temp% and hit enter.转到 windows+R 并键入 %temp% 并按回车键。 delete the temp folder and files and then try opening the same删除临时文件夹和文件,然后尝试打开相同的

I was getting similar error in VS2017 while trying to publish my solution to Azure.在尝试将我的解决方案发布到 Azure 时,我在 VS2017 中遇到了类似的错误。

This algorithm helped me to resolve it:这个算法帮我解决了这个问题:

  1. Close VS2017关闭 VS2017
  2. Open C:\\Users{your user name}\\AppData\\Local\\Microsoft\\VisualStudio\\ folder打开 C:\\Users{您的用户名}\\AppData\\Local\\Microsoft\\VisualStudio\\ 文件夹
  3. Rename 15.0_08edcd83 folder重命名 15.0_08edcd83 文件夹
  4. Start VS开始VS
  5. Publish works fine!发布工作正常!

Note that this will remove your Visual Studio's recent files / projects from it's history and also linking to MS account.请注意,这将从它的历史记录中删除您的 Visual Studio 最近的文件/项目,并链接到 MS 帐户。

This method is slightly different from the Top answer.此方法与 Top 答案略有不同。 Here you don't have to delete other folders except renaming abovementioned one.这里除了重命名上述文件夹外,您不必删除其他文件夹。

I have been fighting with this during the whole weekend.整个周末我都在与这个作斗争。 But it's pretty easy to do it.但它很容易做到。 What I did was to click on repair rather than uninstall.我所做的是点击修复而不是卸载。 After repairing, I clicked on restart directly.修复后,我直接点击重启。 After that, everything is working perfectly.之后,一切正常。 You should try this, may be it can work also for you!!!你应该试试这个,也许它也适合你!!!

Restarting Visual Studio did it for me.重新启动 Visual Studio 为我做到了。 On the next run, it displayed a "Scanning new and updated MEF components ..." and then it executed normally.在下一次运行时,它显示“正在扫描新的和更新的 MEF 组件...”,然后正常执行。

It seems to be related to Windows update somehow, although I don't have proof.虽然我没有证据,但它似乎与 Windows 更新有关。

Delete bin and obj folders in all projects of that solution.删除该解决方案的所有项目中的 bin 和 obj 文件夹。

Seems like those folders were having old files generated by some older version of visual studio, which are not compatible with new version of visual studio.似乎这些文件夹中有一些旧版本的visual studio 生成的旧文件,这些文件与新版本的visual studio 不兼容。

The solution to the issue when i had this earlier today was that there was an additional set of tags bolted on the end of my Web.config.我今天早些时候遇到这个问题的解决方案是在我的 Web.config 的末尾附加了一组额外的标签。 Once removed the functionality returned.删除后功能返回。

Problem: My VS 2015 was throwing up error after I installed SSDT.问题:安装 SSDT 后,我的 VS 2015 出现错误。 Whenever I clicked on Tools >> Extensions and Update it was throwing "Object reference not set to an instance of an object" error.每当我单击工具>>扩展并更新时,它都会抛出“未将对象引用设置为对象的实例”错误。 When I tried to open a solution it threw some provider not set correctly.当我尝试打开一个解决方案时,它抛出了一些未正确设置的提供程序。

Solution: After many hours of research trying out all the solutions previously mentioned by others didn't solve my problem.解决方案:经过数小时的研究尝试其他人之前提到的所有解决方案都没有解决我的问题。 Every time the error popup was pointing to check the ActivityLog.xml.每次错误弹出窗口都指向检查 ActivityLog.xml。 But I was ignoring it.但我忽略了它。 After hours of frustration I decided to read the error carefully and looked into ActivitLog.xml and found that it was looking for "Could not load file or assembly 'System.Collections.Immutable, Version=1.1.37.0" .经过数小时的沮丧,我决定仔细阅读错误并查看 ActivitLog.xml,发现它正在寻找"Could not load file or assembly 'System.Collections.Immutable, Version=1.1.37.0" So I just started searching for this assembly and stumbled upon this link https://sergeytihon.com/2015/12/01/how-to-restore-viual-studio-2015-after-update-1-dependency-dance/ and followed the steps there, which fixed my issue.所以我刚开始搜索这个程序集并偶然发现了这个链接https://sergeytihon.com/2015/12/01/how-to-restore-viual-studio-2015-after-update-1-dependency-dance/和按照那里的步骤操作,这解决了我的问题。

Went into %LOCALAPPDATA%/Local\\Microsoft\\VisualStudio\\14.0\\devenv.exe.config and searched for "System.Collections.Immutable" and change newVersion from 1.1.36.0 to 1.1.37.0进入 %LOCALAPPDATA%/Local\\Microsoft\\VisualStudio\\14.0\\devenv.exe.config 并搜索“System.Collections.Immutable”并将 newVersion 从 1.1.36.0 更改为 1.1.37.0

Final config should look like this最终配置应该是这样的

<dependentAssembly>
 <assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
 <bindingRedirect oldVersion="1.0.27.0-1.1.65535.65535" newVersion="1.1.37.0"/>
</dependentAssembly>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试在 asp .net web 应用程序上创建新项目后,Visual Studio 2022 错误“对象引用未设置为对象的实例” - Visual Studio 2022 error "Object reference not set to an instance of an object" after trying to create new project on asp .net web application ASP.NET错误:IsBadPath()对象引用未设置为对象的实例 - ASP.NET error: IsBadPath() Object reference not set to an instance of an object ASP.NET错误对象引用未设置为对象的实例 - ASP.NET Error Object reference not set to an instance of an object 发布我的 asp.net web 应用程序会给出“对象引用未设置为 object 的实例。” - Publishing my asp.net web application gives 'Object reference not set to an instance of an object.' 对象引用未设置为对象asp.net的实例 - object reference not set to an instance of an object asp.net ASP.NET:对象引用未设置为对象的实例 - ASP.NET: Object reference not set to an instance of an object 未将对象引用设置为ASP.net中的对象实例 - Object Reference Not Set to the Instance of the Object in ASP.net Asp.Net MVC4&#39;对象引用未设置为对象的实例&#39; - Asp.Net MVC4 'Object reference not set to an instance of an object' ASP.NET会话对象引用未设置为对象的实例 - ASP.NET Session Object reference not set to instance of an object ASP.NET Object引用未设置为对象的实例 - ASP.NET Object reference not set to an instance of an object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM