ReSharper Postfix Templates plugin

Developers: ever notice how you often, when typing some piece of code, most often a variable or other class reference, have to track back your keystrokes to surround it or prefix it with something else? The Postfix Templates extension for ReSharper by Alexander Shvedov (@ControlFlow) minimizes the times you have to backtrack what you typed, by enabling you to continue typing and selecting what you actually wanted from intellitype as if it were a virtual extension method, after which the templating engine completes your code including prefixing and surrounding where needed. That may sound difficult as I describe it perhaps, but pictures paint a thousand words: check out the small demonstration videos on the github site, it explains much better than I can. Using it for a couple of days it has already saved me a lot of backspacing and cursor-left presses and it just… feels more intuitive what you are doing.

Lees meer over dit bericht

Update to SQL server tooling for Visual Studio

MS recently released the “March 2014” update to the SQL Server tooling for Visual Studio 2013, which was named SQL Server Data Tools for previous Visual Studio versions. Among the most notable new features are support for SQL Server 2014 and several productivity updates that simplify development and testing, also on SQL Azure. Read more about it on the SQL Server Data Tools team blog here.

Worth noting for some of us, is that Visual Studio 2010 is no longer supported with new features and updates for SSDT, although the dacpac’s and other projects remain fully compatible throughout 2010/2012/2013. The update to SSDT that was released at the time VS2013 came out, was the last one. Personally, I am only keeping my VS2010 around for its Installer support, so I am ok with that.

(Add. 10-04)

Today I noticed that the order of installation of updates is important. On another machine, I upgraded SSDT first, but was then unable to install the 1.3 update to the Microsoft Office Developer Tools (12.0.30225.00, to be precise). The latter’s Web Installer the complains about missing requirements and refuses to continue:

ssdt_required

SQL Server Data Tools not installed?

SQL Server Data Tools is installed, obviously, but not recognized, probably because of newer version numbers. I don’t really mind much since I don’t actively develop using the Office Developer Tools, so I’ll just wait for the next update. But if you do use both, I recommend you should install the ODT update first, and then SSDT!

Downloading UTF-8 filenames from an FTP-server that does not support them, with System.Net.FtpWebRequest

I have written a windows service in .Net that monitors an FTP location for new files, which it then downloads to a local folder for processing. To be precise, the tool first renames the file before downloading it. It uses the .Net standard FtpWebRequest class from System.Net. Every once in a while, a file could not be downloaded, and the FtpResponse would be 550 – Action not taken, file unavailable. This happened especially if the file name had “special characters” in it, one example being a file named ANDRÉ.XML. The workaround was simple: I’d launch an FTP application, rename the file to ANDRE.XML, and it would quickly be picked up by my tool again.

It bothered me that somehow the FTP application was able to rename the file, while FtpWebRequest was not. (It also bothered me that every once in a while I had to fix a stuck file like this, but let’s not go down that road here.) So I attached a trace log to see what was going on.
Lees meer over dit bericht

The case of the blank Visual Studio properties window — part 2

Earlier this year I suffered from a case of a Visual Studio properties window that appeared to get “stuck” in the middle of developing an application. It would show up blank and the only way to get it to work was to fix the project and restart Visual Studio (not just close and reopen the solution). For more details, please read the first article.

Blank Properties window in Visual Studio

Although I haven’t written about it, after applying the solution from the first article, my problems weren’t entirely over. Every once in a while, the properties window would get stuck again, and after tweaking the .xsd file a little or reverting it to a previous revision, I could get it to work again. But I never got the feeling that I really understood what I was doing. It would just work sometimes, or not. I even got hesitant to make any changes to the dataset, unless absolutely necessary. But it only happened on that single solution.

Until last week. In an entirely different solution, all of a sudden the properties window was blank again. It’s subtle, you don’t always notice immediately and because of that I could not simply undo the last the thing I did. This solution contained a dataset file too, so after cursing a little (I admit) the first thing I did was revert that and reapply the changes one by one. But this time, that didn’t work. I reverted the dataset to points way before the property editor got broken but still nothing. It was starting to look like the dataset file being the solution was not a generic one, but just the solution for that first project. This time, it was something else. Lees meer over dit bericht

Error when compiling .resx file – Attempt to load a program with an invalid structure

I have seen this before and fixed it, but ran into it again today and could not remember what is was. When compiling a WinForms application in Visual Studio 2010, I got an error message stating “Kan bestand of assembly (…) of een van de afhankelijkheden hiervan niet laden. Poging om een programma te laden met een onjuiste indeling. ” (Roughly translated, “Can not load assembly (…) or one of its dependencies. Attempt to load a program with an invalid structure.”).

When double-clicking the error, it points to a base64-encoded piece of a resx-file, in this case an image stream for an image list.

This is a bug in Visual Studio 2010 that has not yet been fixed. See here on Microsoft Connect.

The workaround suggested by Pellet21 works for me in the mean time. I’ll copy it here to save myself from Googling for it next time:

Workaround
1.    Open Form in Designer and make needed GUI changes. Close designer and save
2.    Compile project and receive RESX compile error (only forms with Imagelist should have this problem)
3.    Double-click resx compile error to open resx file.
4.    Scroll to top of imagestream.
5.    Edit the top line of the Image stream:
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
TO
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj0yLjAuMC4w
6.    Close and save resx file and recompile.
**NOTE: the only difference are the characters at end “j00LjAuMC4w’ to “j0yLjAuMC4w”

This needs to be done EVERY TIME you open the form in Designer mode.

Initializing a combobox to a blank value might be harder than you think

Combobox troubles again today. No matter how hard I tried to have Comboboxes in my dialog form to initially display blank (SelectedIndex = -1), as soon as the dialog was displayed, the combos would always show the first item in the List that populated it. Despite being set to -1 explicitly. It was driving me nuts.

When created at runtime using a List as DataSource, getting this (empty combos) might be harder than you think

The situation: I had a dialog form that should have a variable number of comboboxes on it, determined at runtime. So the form had an Init method where I dynamically added the comboboxes, and set its DataSource to a List of items (directly, no BindingSource). The form also has a LoadData method, that sets the SelectedIndex of each combo to the actual value from the data, or to -1 of it was unknown or uninitialized at that time. This was to be able to make the combo appear blank instead of preselecting the first item, which was undesired. The caller of the dialog executes Init(), LoadData() and finally ShowDialog().

I was expecting a blank combobox, but it showed the first item in the list preselected. I triple checked that the SelectedIndex was correctly set to -1 at the end of LoadData(), but as soon as the form was displayed, it was 0. What the *** happened there in between and “who” was secretly setting my property!? Lees meer over dit bericht

SP1 for SQL server 2008R2 brings back Intellisense to SMSS

Yay! Installed Service Pack 1 for SQL Server 2008 R2 today. Among other fixes, it brought back IntelliSense support in SQL Server Management Studio, which had been broken since I installed SP1 for Visual Studio 2010 on that machine.

SSMS Intellisense is back!

So those of you that were bothered by the same issue, are advised to install the service pack as soon as you can.

Jet OleDB 4.0 provider not registered on the local computer

I have a C# WinForms program that attempts to import some data from Excel into a SQL Server database using the Ole DB provider. Today the import suddenly failed with an error message saying that the Jet Ole DB provider was not registered on the local computer.

InvalidOperationException: Jet OleDB 4.0 provider not registered on the local computer

Well, I was pretty sure that it was. So what was wrong then?

Turned out that the Configuration Manager accidentally got reset to “Any CPU” setting. I have an x64 machine on which that leads to running the application in 64-bit mode, in which there is indeed no Jet OleDB provider available (and no Edit-and-Continue either, among other things…).

Setting the target platform to compile to x86 immediately solved the problem.

WinForms ComboBox does not always fire SelectionChangeCommitted

Today I ran into the problem that a ComboBox in my project did not always fire the SelectionChangeCommitted event when I expected it to. To be specific, if a user dropped down the list, used the arrow keys to move to an item, and then TABbed to the next control, the new item would be selected but the event never fired. This was a problem for me, because I relied on this event to filter the items in the next control, depending on the selection made in the first.

Some googling quickly learned that this was a known problem with the ComboBox, although the thread is about the SelectedIndexChanged event, it appears the same error prevents SelectionChangeCommitted from behaving as expected. As user comecme in that thread pointed out, there even was a knowledgebase item including a workaround available from Microsoft. But as he also points out… the workaround does not work.

So I decided to cook up my own solution. This would involve subclassing the Combobox to change the behavior I needed. I had one advantage, I was already using a subclassed ComboBox in all places I needed this behavior, so no Find+Replace was required to replace all standard ComboBoxes with my own.

To this subclassed combobox (named CatalogComboBox) I added the following code:

private CatalogComboItem keepSelection;

protected override void OnEnter(EventArgs e) {
  keepSelection = this.SelectedItem;
  base.OnEnter(e);
}

protected override void OnLeave(EventArgs e) {
  if (this.SelectedItem != keepSelection)
    OnSelectionChangeCommitted(EventArgs.Empty);
  base.OnLeave(e);
}

protected override void OnSelectionChangeCommitted(EventArgs e) {
  base.OnSelectionChangeCommitted(e);
  keepSelection = this.SelectedItem;
}

(I used CatalogComboItem because my combo items where typed as such, but you can always use object.) It’s a not spectacularly elegant or high-tech solution, but it works like a charm.

The case of the Visual Studio blank properties window

I experienced the strangest thing with my installation of Visual Studio 2008 last Friday. In the middle of developing a Windows Forms application, I noticed that the Properties window had stopped working. It was still there, just blank, and so was the dropdown above it where the components usually reside.

Update 19-12: This blog post will be revised soon. I have since experienced this same error under different conditions which had a different solution.

Update 20-12: This blog post is superseeded by this one. I have now found a generic strategy to follow if this situations occurs. The solution presented below was probably a one-time fix that will most probably not help you. Please read the new article.

Blank Properties window in Visual Studio

This was not just with the current file, but for all files in my solution. It would not even display the mainly informal properties of the current file selected in the Solution Explorer. Closing the solution and re-opening it did not help. Hiding the properties window and re-showing it did not help. Google led me to several suggestions, most of them telling me to execute a command in the Visual Studio command prompt (devenv /setup) would fix things. Nope, not for me. Starting VS in safe mode to eliminate plugins. Still blank. Even other solutions I opened now had a blank properties window. Oh dear. I was now getting worried that I broke something very serious in my VS installation.

Lees meer over dit bericht