Rick Strahl's Weblog  

Wind, waves, code and everything in between...
.NET • C# • Markdown • WPF • All Things Web
Contact   •   Articles   •   Products   •   Support   •   Advertise
Sponsored by:
Markdown Monster - The Markdown Editor for Windows

Text Editor Associations/Extensions in Visual Studio getting lost


:P
On this page:

Here's something that's coming up frequently since I maintain a framework that requires custom script map extensions: So you create a custom script map for your application and then map that script map into the Visual Studio editor. And you go happily along editing your files using the custom extension mapping in Visual Studio. For my particular scenario I have an extension .wcsx mapped to the WebForms Editor.

So now I'm happily using my custom extension document. Everything is hunky dory. Then one day I shut down and open the project back up the next day only to find something like this when opening the .wcsx file:

NoAssociation

What I should be seeing is syntax coloring for your custom extension, but instead I just get a wall of black text - with the text not highlighted. What the hey? It worked last night, right?

Unfortunately, this can happen from time to time with Visual Studio (problem has existed since Visual Studio 2008).

Fix it

When you lose the file association and your previously mapped extensions no longer show syntax highlighting, there's an easy fix - annoying as it may be.

Go to Tools | Options | Text Editor | File Extensions

Now when you open this dialog you're probably going to find your extension actually mapped. My dialog looks like this even while displaying the text non-highlighted as shown in the image:

ExtensionEditro

It looks like the association is set, the .wcsx extension is there, but even so the syntax coloring does not work. Visual Studio internally tracks the associations but for some reason or other is not actually applying them when opening the file in the editor.

To fix this is a two step process - and yes it's not very intuitive:

  • Select the extension that doesn't work
  • Click on Remove
  • Type the extension into the Extension textbox
  • Click Apply

It's important that you remove the extension first before adding it back in! Just clicking apply on the extension has no effect.

Once that's done the extension once again works properly and my text shows up properly syntax colored:

SyntaxColoring 

It's a hassle when this happens, because usually it's not just one association that gets wiped out but all of them. I tend to have 5-10 of them active and it takes a few minutes to go through all of those and reset them.

What sucks is that I've not been able to trace this down reliably to repro. One of my products - West Wind Web Connection - relies on script map extensions and this is a common problem that pops up with customers who are utterly perplexed that their editor window all of a sudden doesn't show the syntax highlighting anymore. It's even more perplexing to them when they go to the file extensions dialog and find that the mapping apparently is there and doesn't work. It's not exactly intuitive to remove the mapping and then put it back in… heck it took me a while to figure this out myself.

So I hope somebody from Microsoft is looking at this and decides to fix this once and for all. This bug has been in Visual Studio since VS 2005. If anybody else has run into this and has some reliable repo steps that would be useful too - please post those and I can forward them to the right folks at Microsoft. I've brought this up a few times, but I've always been called to provide a reliable repro which unfortunately I've not been able to provide.

In any case, hopefully this post will help out somebody that's stuck with this.

Posted in Visual Studio  

The Voices of Reason


 

Chris
March 26, 2013

# re: Text Editor Associations/Extensions in Visual Studio getting lost

I constantly have a similar issue with "FontsAndColors". Sometimes when VS starts, it hangs and looking with Process Monitor, you can see it is "iterating" on the FontsAndColors-settings. Maybe there is a similar root cause, who knows?

Rick Strahl
March 26, 2013

# re: Text Editor Associations/Extensions in Visual Studio getting lost

@Chris - interesting. I've never seen that and I often do switch font themes for presentation purposes. It could be permissions issues - UAC vs. true Administrator account or something to that effect too.

Jorge Mota
April 12, 2013

# re: Text Editor Associations/Extensions in Visual Studio getting lost

I was a web connection user a few years ago, and I always was setting this again and again and again, but I always thought was my installation. :|

Rick Strahl
April 12, 2013

# re: Text Editor Associations/Extensions in Visual Studio getting lost

No definitely not your installation. This is a bug in Visual Studio to this date. It has to do with multiple instances.

Robert Phillips
February 25, 2014

# re: Text Editor Associations/Extensions in Visual Studio getting lost

I think this is due to running multiple instances of Visual Studio as Administrator ('Run as Admnistrator').

File extension associations made in one instance get overwritten (i.e. forgotten) by the most recently opened instance. Running the additional VS instances as a normal user does not cause this problem to occur.

If you need to run multiple instances of VS as administrator, you're all out of luck. Sorry.

See: https://connect.microsoft.com/VisualStudio/feedback/details/533759/vs2010-rc-ide-sometimes-forget-file-extension-setting

Rick Strahl
February 26, 2014

# re: Text Editor Associations/Extensions in Visual Studio getting lost

@Robert - well that sort of makes sense, but why would the extensions be wiped out if they are already there? I can see multiple instances of stepping on each other and skipping changes written by one. But if you add an extension, exit the changes are written and done. Then at some point in the future they're gone again but nothing may have touched the items. That honestly doesn't make sense.

Unfortunately I do need to run as Admin because we use IIS rather than IISExpress for a number of reasons.

West Wind  © Rick Strahl, West Wind Technologies, 2005 - 2024