If you are like me, (and the government hasn’t abducted you yet), then you hate those app.config’s that are 2,000 lines long and just messy as hell. What to do….oh what to do….
Well, one thing that is a great little gem of .NET 2.0 and above is the ability to put each of your sections in their own file. Sounds too good to be true, right? I go to the connection strings file, and just see …Connection strings. Not wading through the first 200 lines of crap to find the little section I want to work with.
So, how does one take advantage of this little documented trick? Super easy. The magical configSource attribute. Why isn’t this easily found in the docs, no idea. All I know is that it works.
So, lets say you have your messy web.config and turn it into this:
I am just getting used to some of the workflow enhancements in Visual Studio 2010. I was a bit miffed when I had to go to another submenu off of my context menu to do a quick watch on a variable, until….I got annoyed enough to hit the innocuous looking Pin to Source option. It eluded me at first what the hell this option was but then it all came to light.
My watch sitting their waiting for me happily right there in code. Watching my variables never got so damn easy. So, thumbs up to the VS team on this one. Monitoring my loops and data is now a lot more convenient seeing the values right where my eyes are wanting to actually look.
The context option:
The result of this option:
I hope this new feature helps you as much as it does me.
I upgraded to Visual Studio 2010 Beta and so far it has been a pretty good experience. One thing that bit me was building my project to find I had over 4,000 warnings. Geee. I didn’t think I coded that badly.
Well, it turns out each one was a warning about almost every single one of my aspx pages html tags. So, WTF?
This manifests itself not only as the
Validation ($SCHEMA$): Element ‘html’ is not supported
but all your other tags.
Validation ($SCHEMA$): Element ‘div’ is not supported ,etc.
It turns out the default settings for the validator was, wait for it……NOTHING. Freaking blank.
The resolution was that the validator had no idea what to validate against, so everything was wrong. Simple solution though, just set the validation type in your options box.
I had an issue where my client was connecting to a WCF service that was using certificate authentication, but the certificate was for a different dns name.
i.e. server was foobar.comp and the certificate was for foo.foobar.comp.
This presented an issue. Of course, you can change the Identity tag in the configuration file, but I wanted my program to be a little smarter. I grab the error from the WCF service and switch the Identity on the fly. Mainly I did this for a test application in a load balancing scenario due to the load balancer having a different DNS name than the servers. (Obviously!)
Hopefully you have written your own proxy class with a constructor that takes in the configuration name and an EndPointAddress.
You can then use the following style code to create your proxy with the Identity mismatch taken care of.
protected override MyProxyClient CreateConnection(string Server, string altIdentity)
altIdentity = Server;
return new MyProxyClient ("MyServiceBindingConfiguration",
We only are using the configuration for the primary settings, such as binding info. The actual server endpoint is being set on the fly with the altIdentity param being used to allow the server to masquerade with a different certificate.
It was driving me nuts to do such a simple task as setting the font on the label to Underline in WPF. Well, its not that easy. You can’t just set the TextDecoration on the label since the label is a container control. Yes, you can set text to its Content property, but that just implicitly creates a TextBlock.
So, I wrote a quick helper function to let me set underlined text to any label.
lblServer.Content = CreateUnderlinedTextBlock( "Your Text Here" );
The actual function
/// Creates the underlined text block.
private TextBlock CreateUnderlinedTextBlock(string text)
// Create an underline text decoration. Default is underline.
TextDecoration myUnderline = new TextDecoration();
// Create a linear gradient pen for the text decoration.
Pen myPen = new Pen();
myUnderline.Pen = new Pen(Brushes.Gray, 1);
myUnderline.PenThicknessUnit = TextDecorationUnit.FontRecommended;
// Set the underline decoration to a TextDecorationCollection and add it to the text block.
TextDecorationCollection myCollection = new TextDecorationCollection();
TextBlock blockHead = new TextBlock();
blockHead.TextDecorations = myCollection;
blockHead.Text = text;