Visual Studio error "Object reference not set to an instance of an object" after install of ASP.NET and Web Tools 2015 - asp.net

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:
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.
I'm using Visual Studio 2015

Maybe this helps:
Delete the contents from the following folders:
C:\Users\%userprofile%\AppData\Local\Microsoft\VisualStudio
C:\Users\%userprofile%\AppData\Local\Microsoft\VSCommon
Sometimes, you need to go to:
[x64] C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE
[x86] C:\Program Files\Microsoft Visual Studio 14.0\Common7\IDE
and run devenv /resetuserdata.
Expect, that all of your user settings such as Visual Studio layout, linked Microsoft account or start page might disappear.

Delete %LocalAppData%\Microsoft\VisualStudio\14.0\ComponentModelCache and restart Visual Studio.
Alternatively, use the Clear MEF Component Cache extension.

For me,
I ended the process in Windows Task Manager: VsHub.exe.
Restarted 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] C:\Program Files\Microsoft Visual Studio 14.0\Common7\IDE

It's recommended to try any or all of the following:
Restart Visual Studio
Try Running As Administrator (right-click Visual Studio and choose "Run As Administrator")
Check for any updates for Visual Studio (download and install them if any are available)
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)
Attempt to repair your Visual Studio installation

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. This removed the errors. So I moved everything back, one-by-one, and restarted Visual Studio each time until I discovered the culprits. These folders were fine to move back in:
1033 (overwrote the auto-generated copy with old)
Designer (was in my old copy, not initially re-created when I re-launched VS, copied it back in)
Extensions (overwrote the auto-generated copy with old)
ImageLibrary (overwrote the auto-generated copy with old)
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)
VTC (was in my old copy, not initially re-created when I re-launched VS, copied it back in)
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.lock (overwrote the auto-generated copy with old)
vspdmc.lock (overwrote the auto-generated copy with old)
These files were fine to move back in. Each was in my old copy, and not initially re-created when I re-launched VS:
.NETFramework,Version=v4.0,Set=Framework,Hash=C958D412.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=497525A2.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=72AE305.dat
.NETFramework,Version=v4.5.2,Set=Extensions,Hash=ADF899D7.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:
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.
devenv.exe.config - same as 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=9951BC03.dat - causes error output from the JavaScript Language Service, complaining of missing js files
.NETFramework,Version=v4.5.2,Set=RecentAssemblies,Hash=0.dat - causes error output from the JavaScript Language Service, complaining of missing js files
These are the errors from those last .NETFramework files (which I do not get if I do not add them back in):
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. But definitely devenv.exe.config and ComponentModelCache need to go to correct the "object reference not set to an instance of an object" error.

For me, ASP.NET 5 is not yet required, I removed update, and then reinstalled ASP.NET 4.5. It's a bit tricky:
Removed from control panel "Microsoft ASP.NET 5 RC1 Update1". After that, you will no longer open ASP.NET MVC projects
Then I changed the installation of "Microsoft Visual Studio Professional 2015", clicked "Modify", and selected "Microsoft Web Developer Tools"
No longer follow the notification of update in Visual Studio 2015!!!

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.

I was getting an exception every time I tried to create a "new" project.
My solution was:
Go menu Tools → Extensions and Updates
Check the "Updates" link... There was an update to Microsoft ASP.NET and Web Tools. Install it.
That fixed it for me.

In my case (not necessarily be the solution for you, but it may be helpful for someone), the solution was:
Go menu Tools → Extensions and Updates
Select the Online tab from the right panel
Search for the words web tools, and then select Microsoft ASP.NET and Web Tools and install it.
In my case, this was missing from my computer because of a lot of repairing operations for Visual Studio.

I was getting similar error in VS2017 while trying to publish my solution to Azure.
This algorithm helped me to resolve it:
Close VS2017
Open C:\Users{your user name}\AppData\Local\Microsoft\VisualStudio\ folder
Rename 15.0_08edcd83 folder
Start VS
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.
This method is slightly different from the Top answer. Here you don't have to delete other folders except renaming abovementioned one.

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". There was an
update to Microsoft ASP.NET and Web Tools. Get it as
AspNetWebFrameworksTools2015_KB3137909.exe and install it.
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.
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\FipsAlgorithmPolicy]
Enabled=dword:00000000 And All fixed.

Goto windows+R and type %temp% and hit enter. delete the temp folder and files and then try opening the same

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. On the next run, it displayed a "Scanning new and updated MEF components ..." and then it executed normally.
It seems to be related to Windows update somehow, although I don't have proof.

Delete bin and obj folders in all projects of that solution.
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.

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. Once removed the functionality returned.

Problem:
My VS 2015 was throwing up error after I installed SSDT. 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. 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". 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.
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
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>

Related

Visual Studio 2017 won't compile my ASP.NET web project, saying "could not load file or assembly" for a library that is definitely being referenced

Current Situation:
I have an ASP.NET web project. (Framework Version: .NET Framework 4.5.2)
One developer here is able to compile it and run it fine in Visual Studio 2017.
I cannot, I get the "could not load file or assembly" error for a reference that is in my list of references.
Screenshots:
Error:
Bin Folder:
Web.config Potential Relevant Sections:
DevExpress Licenses File:
DevExpress Library File's Details:
Things I've Tried:
Clean Solution & Rebuild Solution
Deleted solution locally and clean get of solution from source control
Clearing out my temp directory
Opening the project in Visual Studio 2015
Having the developer zip up his local copy of the solution / project and sending it to me (When I ran his copy locally I continued to get the same error.)
Re-adding the existing library it's complaining about
Manually deleting and re-adding all the libraries in my BIN folder
Messing with the license file, web.config, and assembly references in code (including adjusting the version numbers because for some reason the version number is 17.2.5.0 anywhere it's referenced in the project, but the file's Details actually says it's 17.2.9.0?)
Smashing my face into my keyboard...
...Always the same error.
Additional Information
Other developers run into the same exact error under the same conditions as me, only my one developer who's been working in this project can build it fine
I just noticed that on a new copy of the work project, my references window is showing 2 of the same reference to the DevExpress.Data library (one in the GAC and one in the BIN) but when I try re-adding the reference to my project, the one in the BIN disappears from my references window:

ASP.Net Core 2 - IIS 502.5 Error

I am creating an ASP .Net Core (2.0) MVC application within Visual Studio 2017 which was working absolutely fine.
After turning off my computer yesterday and coming back to my application today, I now receive this browser error when I start the application in chrome without debugging.
Running dotnet run within the directory of the application, I can access the site just fine. It is just when I run it via Visual Studio/IIS Express I get this error.
HTTP Error 502.5 - Process Failure
The application builds and compiles just fine. I have also cleaned the solution.
Looking in the event logs I find:
Application 'MACHINE/WEBROOT/APPHOST/MYAPP' with
physical root 'C:\Users\Ben Hawkins\Desktop\Development Folder
\Dev\Website\Version_2\MYAPP\MYAPP\'
failed to start process with commandline 'C:\Program Files
(x86)\Microsoft Visual
Studio\2017\Community\Common7\IDE\Extensions\Microsoft\Web
Tools\ProjectSystem\VSIISExeLauncher.exe -argFile "C:\Users\Ben
Hawkins\AppData\Local\Temp\tmp3547.tmp"', ErrorCode = '0x80004005 :
0.
Within my output window in Visual Studio 2017 I recieve this message under
ASP NET CORE WebServer
Failed to initialize CoreCLR, HRESULT: 0x80131534
What I have tried:
Cleaning the solution, rebuilding etc
Restarting the computer
Trying to launch another application. (Same result)
Created a new application from scratch. Same result.
Repairing Visual Studio Community 2017. Same result.
Stopping/Closing IIS Express
My setup was working perfectly yesterday and suddenly is not.
Thank you for your time. I hope we can find a solution.
We finally found the issue! After logging on to the machine as a different user, we saw a warning that the main user had ignored initially. There was a 0 byte file in the root of the directory named "Program" with no file extension. It appears that this causes some sort of issue when VSIISExeLauncher.exe is invoked through Visual Studio. (Note it would work if executed from the command prompt). After deleting the file, everything worked!
We do not know how this file was placed there for certain, but suspect it was some sort of copy error when the user was pulling in files from his old hard drive.
I don't know if anyone else will come across this, but if so hopefully this helps!
Maybe you need install previous versions of .NET Core, isn't it? I installed here and it works now. I had only .NET Core 2.0 installed and I realized that applications with 1.1 stopped so when running. In Windows' event logs I've had the same error registered.
Try to change the IISExpress to IIS by creating new IIS profile and change the Lunch to IIS. It resolved my problem.
I have hit a very similar issue with ASP.net Core 2.0. I had copied my VS project to a new one, and I was getting this error message.
After doing some research, I was able to determine that the nlog.config file was not copied into the bin > Debug > net461 folder. Once I did this, I was able to run my application.
I found it by running dotnet run from the command line on my project where the csproj files live.
Had same issue yesterday (windows 10).
Solved it this way:
Update Microsoft.AspNetCore to latest (Nuget manager - 2.1.3)
Make sure the sdk also updated to latest version. if not, update it manually from Nuget console like this:
Install-Package Microsoft.NETCore.App -Version 2.1.3
Download and install latest ASP.NET Core/.NET Core: Runtime & Hosting Bundle
from here
Same problem with version 2.2. Reinstalling .NET Core SDK fixed the problem for us.
In my case, my project was setup as a website in IIS and the file "bin\IISSupport\VSIISExeLauncher.exe" was missing in the project's directory.
I simply selected "IIS" when debugging the project in Visual Studio 2019 and it generated the missing file. It also generated 2 text files (IISExeLauncherArgs.txt, pidfile.txt) in the IISSupport folder, made changes to my web.config file, and my project ran successfully.
After that I was able to access the local website that was setup in IIS without running it in Visual Studio.

Is there any solution to Visual Studio 2013 not correctly generating .designer files for ASPX pages?

We have been encountering more and more frequently the Visual Studio error of being unable to generate the designer file in a web project. This problem has been occurring for a few months now, in several of our ASP.NET projects.
The errors occur when saving a file or when building the project, and are variations of errors like this:
Generation of the designer file for [filename] failed: Error HRESULT
E_FAIL has been returned from a call to a COM component.
Generation of the designer file for [filename] failed: Unspecified
error (Exception from HRESULT: 0x80004005 (E_FAIL))
Generation of the designer file for [filename] failed: An entry with
the same key already exists.
Generation of the designer file for [filename] failed: Value cannot
be null.
Sometimes, additional error messages are displayed for valid, previously-working code/markup; errors such as:
The name 'Eval' does not exist in the current context
This is with Visual Studio 2013 (Premium), with "Web Application Projects" type projects using the .NET 4.5 framework. Some of the projects were originally created in Visual Studio 2010 or Visual Studio 2012, but one of the projects was a new project created in Visual Studio 2013.
We have a few Visual Studio extensions installed, such as "Web Essentials 2013", but I have tried disabling all the installed Visual Studio extensions and the same designer file errors still occur. We do not have Resharper or CodeRush installed. We are also using a third-party components package (DevExpress) for ASP.NET. We are using IIS Express for the local development web server.
All available updates (including Update 1 for Visual Studio 2013) have been installed for Visual Studio, the operating system (Windows 8.1), .NET, Visual Studio extensions, and DevExpress.
I have searched StackOverflow and the web for this issue, and have found some suggestions but no solutions, and I have also seen that the issue has been reported to Microsoft several times, dating back some years.
Many indications are that the problem with generating designer files is caused by some invalid syntax (in an ASPX file), or multiple elements with the same ID in the same scope, or collisions in namespace or class names, etc. I have searched through our projects as best as I can for issues like this, but haven't found any.
I found the Redesigner project on Sourceforge (thanks very much to the author), and I tried using that to verify the designer files, but unfortunately it can't handle the DevExpress components (it reports that DevExpress elements are using invalid child tags when the tags are valid and correct for DevExpress).
I have also tried clearing the Visual Studio development cache on my workstation (that is, deleting everything from the folders "\Temp\IISExpress", "\Temp\Temporary ASP.NET Files", and "\Microsoft\WebsiteCache" folders in the %localappdata% folder, rebooting and restarting Visual Studio.
I also found a website that explained how to turn on additional logging for Visual Studio to help with tracking down designer file generation issues. For Visual Studio 2013, this requires adding a key HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\12.0\WebApplicationProjects\Debug and then adding values under that key for "Enabled" (set to 1), "LogFieldGeneratorFailures" (set to 1), and "LogFile" (set to a path and filename that you have permission to write to).
When I added this key, Visual Studio 2013 did write to the debug log file, but it only included error messages similar to the error messages above plus a small stack trace plus the entire content of the ASPX file for which the designer file could not be generated (with no apparent indication of where in the ASPX page there might be an error or invalid syntax).
I think I have tried essentially all suggested approaches in this topic:
How do you force Visual Studio to regenerate the .designer files for aspx/ascx files?
None of these have worked for me. The "Convert to Web Application" option for the ASPX file is not available for me in Visual Studio 2013 in these projects.
Does anyone have any suggestions for potential causes or fixes for this desinger file issue or for any other troubleshooting approaches?
The latest that we have discovered with this issue is that it's related to the Source Control option in Visual Studio to "Get everything when a solution or project is opened".
Having this option UNCHECKED seems to have resolved the problems for our team so far (for the past few days).
There is also this issue posted at Microsoft Connect: http://connect.microsoft.com/VisualStudio/feedback/details/760443/visual-studio-2012-ide-loses-intellisense-and-reference-resolution
The comments at the link above suggest that the bug is caused by asynchronous retrieval of files from source control or the asynchronous solution load when Visual Studio is opened. The choices suggested for fixing the problem are to either turn off the asynchronous solution load or to disable the "get everything on open" option.
There are also suggestions that deleting the .suo (Solution User Options) file in the project directory resolves the problem, but this seems to be only temporary.
The only solution that I've found to work is to delete the Visual Studio cache # C:\Users\<>\AppData\Local\Microsoft\VisualStudio and then running Visual Studio with the /resetuserdata switch. It's a horrible solution that deletes all of your local settings, and resets Visual Studio.
(You can try exporting and importing your settings before and after the surgery.)
Links
(Delete the 2013 cache)
http://blogs.msdn.com/b/willy-peter_schaub/archive/2010/09/15/if-you-have-problems-with-tfs-or-visual-studio-flush-the-user-cache-or-not.aspx
(Fixing the error in 2010, which is slightly different)http://rathodkrunal.blogspot.com/2011/11/visual-studio-2010-error-hresult-efail.html
It's also an open item on connect, if you want to bug MS into fixing it.
https://connect.microsoft.com/VisualStudio/feedback/details/799832/constant-call-to-com-component-fails#tabs
Ran into a very similar issue assisting a colleague. The project had been converted from 2010 to 2013 and was working for most developers. To "resolve" this, we had him close the solution, then delete all of the source control files at the solution level, (vsssc). Once reopening the solution, all was fine.
I've had this issue constantly in different dev environments for the last while. I managed to solve it in one case without using the cache clearing technique by launching component services->DCOM Config. When I did this I was prompted to register a missing key. (didn't quite catch it but something related to EventManagement). Clicked OK and lauched visual studio...hey presto...back in business. Hopefully this advice might catch a few cases out there.

Opening web.config file causes Visual Studio 2010 Ultimate to hang and crash

Situation:
I installed Visual Studio 2012 on top of my previous Visual Studio 2010 Ultimate. I uninstalled VS2012 shortly thereafter along with all SQL 2012 database junk and yadda yadda. Everything in VS 2010 seems to be good, but when I try to open my web.config file VS hangs indefinitely.
Tried:
(1) Downloading and replacing the dsref80.dll that gets overridden by VS2012
(2) Uninstalled all VS extensions, including NuGet
(3) Created new website and web.config file. Problem persists
Question: Does anyone have any other ideas about what could cause the web.config file to cause VS2010 to hang and crash after clicking on it?
I figured it out. For some reason the web.config file was set to open with source code editor by default and not the HTML editor.
For anyone else who runs into this issue, the answer is simple.
Right-click the web.config file ---> Open with ----> Highlight HTML Editor ---> Set as Default.
Update (Dec, 2013): Although I was able to access the web.config file using the method mentioned above, I later realized that it was more of a Band-Aid than a solution. Using the html editor causes a lot of validation warnings and renders intelliSense useless. The correct solution is to run the repair option from the Visual Studio 2010 install DVD, that fixes everything.

MVC: Visual Studio Publish Web dialog cannot find my application's Views

I am using these steps to publish my ASP.NET MVC 4 application using Visual Studio 2010 on IIS 7.5 running on a 64-bit Windows 7 Professional machine.
When I click the Publish button on the wizard after entering the values, it reports a single error that reads:
Copying file Views\Shared\Error.cshtml
to obj\Debug\Package\PackageTmp\Views\Shared\Error.cshtml failed.
Could not find file 'Views\Shared\Error.cshtml'.
I looked into the target folder where the wizard dumps the necessary files that will be needed to deploy the application. It turns out that the folder had the Views folder which had only the _ViewStart.cshtml of the root Views folder, but no other View. My application has at least 20 views, perhaps more.
I realized that it was my fault. The local copy of my project had the file Error.cshtml in the Views\Shared folder. However, the TFS copy of the project file did not. Apparently, the file had been excluded from the project at some stage.
I excluded the file from my project locally and ran the build and it worked.
In my case the problem was that the file was in the solution but didn't actually exist on the local file system.
For me, this problem occurred when I moved a file (via explorer) from the shared folder to another folder.
I added the file in visual studio, but did not "delete" the file from the shared folder (as far as visual studio was concerned).
For some reason, visual studio did not put a little flag or warning sign to tell me the expected file was missing (even after a refresh), so I didn't notice (although trying to open the missing file revealed the problem).
The error message is clear, and self explanatory. I just couldn't understand it for some reason.

Resources