Contents tagged with .Net

  • How to leak memory in .Net - Statics and Event Handlers

    For the past few days I’ve been investigating some memory leak issues in our desktop application. The problem started showing up when we saw that opening new documents and then closing them didn’t have any negative impact on the memory usage. Initial tests using vadump and process explorer confirmed that there was an issue and so we the developers started looking into it.

  • .Net framework hotfix wreaks havoc

    Last week all of us were baffled when suddenly one part of our application that uploads files to a FTP server stopped working. The strange thing was that the same build has been working without any issues for the past one week. We looked at everything that could have gone wrong, server, configuration, code but everything was setup fine and hadn't been changed. Also interestingly it stopped working for everyone except the developer who was responsible for the feature.

    The first thing we did was to enable detailed logging to see what was happening, the logs showed two problems

    1. We were incorrectly formatting the path of file to upload
    2. The .Net framework code was changing folders after login to the root folder of the ftp where it didn't have permissions to upload the file
    Further investigation showed that the second issue was not coming on the developer's machine. Most puzzling indeed.

    Then I remembered that last week .Net had issued a critical hotfix for .Net 2.0, could this be the issue. We verified that the developer didn't have the hotfix and all machines which were failing did have, Strike 1! Next we uninstalled the hotfix from one of the machines and the FTP uploads started working, Strike 2!! Finally we fixed the incorrect formatting of the ftp url and the issue got resolved on all machines with or without the hotfix, Strike 3! Issue resolved!

    The problem was that the hotfix changed the implementation of the FTP code inside the .Net framework so that it behaved differently when passed an incorrectly formatted url.

    This was the first time I saw a working app fail because of the way an incorrect argument was handled by a newer version of the framework. It was a good learning experience though :) Also this strengthens my belief in asserting all assumptions in code because if we had asserted that the url was infact of the format that we were expecting, this issue would never have happened in the first place.

  • Make sure you know what you're fixing

    I’ve been working on this bug for the past one week, basically a call to the GDI+ APIs MeasureString and DrawString was failing with a very useful exception “A generic GDI+ error has occured” ;) , my initial hypotehesis was that the problem was coming because of the length of the string that we were trying to measure, at that time around 100000+ characters. In retrospect this now seems like such a foolish thing to hypotheize.

  • Notes on the software build process

    The build process is more than just a compilation of the code that is done on a developer's workstation, a good build process is able to generate the final set of artifacts that is sent to the user in one step. For e.g. a build process for a desktop application would build the installer, documentation, licenses etc. for the entire product, in case of a web application the build will compile the code files, supporting assets and deploy to a test or staging server. A good build system should be configurable and able to build multiple editions of the product.

  • NDepend 2.0 released

    Patrick has released version 2.0 of his absolutely cool code analyzer NDepend .The VisualNDepend tool is looking slick and Code Query Lanaguage looks damn interesting. Also be sure to take a look at the metrics that are generated by NDepend, very nice.

    Also while you're at the site be sure to check out his excellent and very well written book Practical .Net and C# 2.0


  • Equivalent of sys* tables of SQL Server in Access

    When working with SQL Server it is easy to get access to database metadata like tables, stored procedures etc, by using the sys* tables. I was doing some work with Access and wanted to do something similar, turns out that it is quite easy to do.

    Basically the OleDbCommand.GetOleDbSchemaTable() method allows you to get as much metadata you want about the DB.

    Pretty obscure but a God send when you really need it :)

  • ADO.Net connection pooling

    Connections are precious commodities, and writing code to minimize the stress on the server of having too many connections open concurrently will help with overall database performance. Fortunately, ADO.NET (like its predecessors) tries to help manage those connections with a facility called Connection Pooling. Connection Pooling is the process of managing connections as shared resources that can be doled out from a pool of recently used connections. Connection pooling takes advantage of the fact that many different parts of most applications require connections for a short amount of time as well as the fact that building and tearing down connections is an inherently expensive operation. Connection pooling is a method of reusing connections. The real magic occurs when connections are closed, because the pool hangs on to the connection for some short time (the pooling timeout) before actually closing the connection. If another connection is requested before that short amount of time has elapsed, it hands the open connection to the requestor. This saves the actual work of tearing down the connection and opening a new one. By utilizing connection pooling, you reduce the likelihood of making a round trip to the database only to find out that the database is out of connections. The connection pool reduces the time it takes to determine the out-of-connections state. In fact, with the connection pool, the additional requests can block to wait for a new connection to be available. This allows a machine to throttle its actual usage of the database so as not to swamp a particular database server with requests.

  • Load event gets fired on each call to ShowDialog()

    While chasing down one bug in my custom message box at codeproject I came acorss an interesting fact. If you use ShowDialog() to show your form then the Load event gets fired everytime. I've been using Winforms for such a long time and was surprised that I had never really come across this behaviour.

    It's not a bug, if you use reflector and take a look at Form.ShowDialog() you will see that the flag which is used to prevent Load event from getting fired more than once is disabled everytime ShowDialog() gets called.

  • A new approach to Web Forms

    Mike Roberts talks about a new approach to WebForms, he is the author of CruiseControl.Net a continuous integration software for .Net.

    Extract

    'What??' you may cry. 'You've stopped using ASP.NET??' No, I've just stopped using Web Forms. Web Forms are those .aspx files you write and their code behinds. They're also the things that use server controls, view state and other such components that make up most of .NET web apps. I'm still using the ASP.NET runtime in the form of an IHttpHandler. This is a much more lightweight way of developing web apps, similar to Java's Servlets.

    http://mikeroberts.thoughtworks.net/blog/archive/Tech/dotNet/GoodbyeWebForms.html