September 2007 Entries

Running .NET Windows service project from debugger

It sounds like an easy task, but I have seen many times that people actually do some strange stuff, trying to run a .NET project containing Windows service from debugger. So decided I'll write a small note on how do I do that. If you create a project for Windows service, using wizard in Visual Studio, try to execute it straight from debugger. You'll get that service cannot start or something similar. I do a small trick by checking if debugger is attached and calling some sort of Start method in such case, or executing code created by wizard otherwise....

Access Violation in DsBrowseForContainer on Windows Vista

I have used the example from SDK for browsing Active Directory (can be found here) and in Vista the method DsBrowseForContainer throws AccessViolationException in .NET. While testing, I have created a new MFC (C++) project and added a code for calling to DsBrowseForContainerW (similar to above). That worked perfectly, which means the problem is not in Vista, rather in .NET or marshalling in .NET. Checking the structure returned from the function call, I have found that previously NULL "pszRoot" member is now filled in! Means DsBrowseForContainerW has allocated a memory for it and passed back to me. Looks like marshaller...

Loading WPF TreeView dynamically

In WinForms, I used to catch BeforeExpand event of tree view and add additional items on the fly, from database (or any other source of course). So was looking to do the same thing in WPF TreeView and somehow missed the Expanded event of TreeViewItem. You can subscribe to this event in XAML like this: <TreeView TreeViewItem.Expanded="TreeView_Expanded"></TreeView> The rest of code is pretty simple, but if you want to see a full example, look at this post in MSDN forums: Loading TreeView nodes on demand. Technorati Tags: WPF, .NET