ASP MVC and the Dreaded "..operation could not be completed" Error
By Andrew Watson
Recently I was happily developing an ASP MVC website in Visual Studio 2013, when seemingly without warning my development came to a screeching halt. I attempted to open any *.cshtml file in my solution and was greeted with the most helpful of errors:
Catch some sarcasm there? I hope so. It's as if my copy of Visual Studio had become possessed with the worst kind of evil for a developer - horribly unspecific and passive-aggressive (I might be projecting that last part). No indication of what's actually wrong, and no clear path of how to resolve the issue. All I knew is that I wasn't able to get to files I needed to work on for my project.
My first attempt at resolution was what any self-respecting Windows-based developer would do: restarting the software. No luck with that one. My memory is clouded with the haze of confusion, so I don't know if I tried building the website solution. If I had, I would have gotten an error message that would have pointed me in the right direction as to what was actually going on:
"Application Configuration file 'Web.config' is invalid. Unexpected XML declaration. The XML declaration must be the first node in the document, and no white space characters are allowed to appear before it."
Whitespace at the beginning of web.config? I didn't do that. Sure I had web.config open, but I didn't mess with the beginning of the file and it's since been closed. Double-clicking on the error would have confirmed what I was thinking:
Vindication would have been, or surely was mine. Wait. VS was still winning; I still couldn't open my files. So I did the next thing any self-respecting developer would do: googled the error. Turns out I'm not alone on this one, but there's no clear answer as to the resolution. Except, I did find at least one post mentioning the whitespace thing. Maybe VS isn't so crazy.
So I took another look at web.config, deciding to humor what is surely an unclear error message. It looks like I'm at the top of the file, but I pushed my way up the file anyway. Jackpot!
Turns out, the error message was telling me exactly what was wrong: I had inadvertently put a newline at the beginning of web.config! I don't know how it happened; perhaps I sneezed and hit the enter key at one point. At any rate, removing the newline solved my original problem: I was able to open my *.cshml files without issue.
So Visual Studio, I'm sorry I didn't listen to you better. You did try to tell me what was going on. Let's both agree to work on our communication skills, okay?
Published on 01/08/2014