I have a piece of code like this:
public class NoFollowWebClient : WebClient
{
protected override WebRequest GetWebRequest(Uri address)
{
var request = (HttpWebRequest)base.GetWebRequest(address);
request.AllowAutoRedirect = false;
return request;
}
}
Whenever I add this to a .cs file though, Visual Studio 2012, in it's infinite wisdom, converts my C# source file to a "design time component". So, when I double click on the file now, instead of seeing my C# code, I see "To add components to your class, drag them from the Toolbox and use the Properties window to set their properties".
I know I can right click and do "view code", but that's extremely annoying.
Is there anyway to force Visual Studio to not assume I'm making a component or that I care about their stupid visual designer that serves no purpose for my class?
The problem is that Visual Studio will automatically add
<SubType>Component</SubType>
in your .csproj file as soon as you inherit from WebClient. Even if you try to remove this, Visual Studio adds it again when you reopen the project.
A solution is to add the following attribute to your class.
[System.ComponentModel.DesignerCategory("Code")]
Class with System.ComponentModel.Component on their inheritance path are automatically treated as "components" within Visual Studio
(Unfortunately) WebClient has System.ComponentModel.Component in its inheritance path: http://msdn.microsoft.com/en-us/library/system.componentmodel.component(v=vs.110).aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With