Starting Windows Phone development

I have recently started to make Windows Phone apps. I am doing this mainly as a learning exercise as I am interested in learning the technologies involved which I’m not really able to do during my day job. I am working on some real high end server applications for a client and therefore don’t have time to mess around learning GUI tech, we have real WPF developers for that.

The other reason I am doing this is because I have a windows phone and I love it. I’ll admit, there are times when I miss aspects of my old phone, no not an iPhone or Android, a Windows Mobile 6.5 device. Anyway, I love my phone and its great to see it gets great reviews in the press. However what I hate about it and the reason I think it suffers is that there aren’t enough good apps for it. It doesn’t have the market share for people to bother porting their successful iPhone apps and it won’t gain that market share without the top apps. Therefore as I see it, if I want good apps I need to write them myself to try to help seed the platform and help it grow.
The last reason is a lesser one but it is a factor. I work in a pretty cool company with pretty cool people. It encourages learning and self empowerment and my bosses recognize things like this as positives and I get kudos at work.
So along with the new metro design for this site you should expect to see a lot more windows phone content here

Posted in windows phone | Tagged | Leave a comment

Generating your app.config at runtime.

So I am working on a project at a client which is a server application and a component of other server applications. Its a complex data service which can be deployed as a component of other applications and can be hosted as a WCF service and called by remote clients. The application has a lot of configuration settings which we control in the app.config file. We have service locator settings, middle-ware settings, database settings, logging settings, etc etc.

This is a re-engineering of an old system which used to take all these settings on the command line, or when running as a windows service, through registry entries. In order to smooth the transition to this new system, we have enabled the software to continue to take these settings through the command line/registry settings in that it used to use. The way we do this is to use a base application configuration file, open it as an XML document and use XPaths to swap the overrides into the XML. We then write that XML out to a seperate file and repoint our App Domain to use that config file. The base application config file can even be passed as a command line argument.

This has been working for use since about last summer when we implemented it. We had one simple stumbling block along the way when somebody added a Log4Net call in application before the configuration swap has been completed. This is a problem as when log4net initialises it reads the configuration file. The problem with this is that .NET caches the application config file on first read. However, with the help of a great little tool called Reflector I found this little static cache and therefore was able to use reflection to wipe it out and reset the framework to think it hasn’t loaded it yet. With this little change in place, all was right with the world. Until this week.

This week another change was implemented thanks to some unknown obscure functionality required some a couple of people located in one small corner of one office in the world. We had to read one of our configuration overrides from a database, otherwise we weren’t going to get signed off for release. Therefore, without a choice, we had to use the config/override settings that we had for the database connection to connect the database and read this setting. We put this change in and tested it, it all seemed good. We then promoted our change to the QA environment and it was tested when used as a component of another application. That is when it started to throw an Exception. It was actually WCF which threw the Exception saying that there was no endpoint in the config file for the contract we wanted.

This exception puzzled us a lot, we could see that our config file was being generated properly, we could see that our application was able to read it properly, otherwise it wouldn’t have known to call a WCF service. It was even more confusing when the error didn’t happen on one of the machines. After a whole day of debugging a head scratching, we figured out that the .NET framework has a SECOND cache for configuration data. Not that actual configuration file, as when we asked for our sections from the System.Configuration.ConfigurationManager, we got the values we expected. The reason the single machine that did work worked, was because the Sybase database driver wasn’t installed properly and therefore the connection didn’t open.

The only solution I have come up with so far this week is the run the database connection code in a separate AppDomain. This obviously has prevented the caching on configuration in the primary AppDomain as static variables are per AppDomain. Once I have found this extra little cache I will let you all know where it is. Until then, if anyone else knows or has the same issue, let me know.

Posted in Uncategorized | Tagged , , , , | Leave a comment

Better Know A Framework: Getting the windows proxy settings

It’s a question I have seen a few times on the Microsoft forums: How do you get the default system proxy settings? Well, let me tell you the answer:

WebRequest.GetSystemWebProxy will return a proxy object with the default system proxy in it.

http://msdn.microsoft.com/en-us/library/system.net.webrequest.getsystemwebproxy.aspx

Using the DefaultWebProxy property on WebRequest you can get the proxy for the system unless it has been overridden in your app.config file. This is the best property to use so your app can be repointed to a different proxy. That property can also be set by your code to repoint your app

http://msdn.microsoft.com/en-us/library/system.net.webrequest.defaultwebproxy.aspx

So that’s the simplest way to get hold of the proxy settings for Windows apps.

Posted in Better Know a Framework | Tagged , , , | Leave a comment

Better Know a Framework: System.Environment.FailFast

Ok, a new method on System.Enviroment in .NET 4.0 is the FailFast method. This a new nuclear option for ending your program should it have gone horribly, horribly wrong. There are 2 overloads, one takes a string, the other takes the string and an exception. When the application exits the string and exception details are written the event log and a dump is created for the application.

One thing to note is that NO catch blocks, finalizers or any other form of code will run in the application. This can be a good thing if your finalizers clean up stuff that in bad crashes you would rather was left behind. However, be careful, it means any Dispose methods or Finalizers that release shared or unmanaged resources will also not run.

Its nice they gave us the nuclear option, but we should also be careful how they are used.

Posted in Better Know a Framework | Leave a comment

Better Know A Framework: System.Enum.HasFlag()

Ok, so first ‘Better Know A Framework’. This one is for the new .NET 4.0 method HasFlag on System.Enum

I chose this one because a while back in my blog I posted an Enum helper that had a method like this. The method just replaces the:

bool isFlagSet = (value & flag == flag);

with:

bool isFlagSet = value.HasFlag(flag);

Another helpful little thing is that the flag value you pass in can also be a combination of flag values. Its simple but helpful. However on my helper, I also put the SetFlag method. Maybe Microsoft are working that one up for .NET 5

So that’s it for the first of these, there is the new method, give it a whirl

Posted in Better Know a Framework | Leave a comment

Better know a framework

Ok, so for those of you that listen to DotNetRocks then you will have heard Carls ‘Better Know a Framework’ bit. Well this is my version, posts in this category will be telling you about a little bit of the framework I have discovered or just one that I like. I’ll tell you what its for and how to use it. Like a little mini-guide.

Its open to requests too, so send ’em if you got ’em

Posted in Better Know a Framework | Leave a comment

Managing a Development team

I have been a consultant on a development team for nearly 2 years now and it has undergone a lot of changes in that time and I have witnessed changes in how the team views itself and its direction over that period. I thought I would post up a few posts on what I have learned over that drips. This post is a brief summary of the period and the big leadership mistakes I think happened. Hopefully if people I know read this they won’t be offended I posted it up. Continue reading

Posted in Comment | Tagged | Leave a comment