If you publish a WCF service using EF to IIS, do not forget to distribute sqlserver.dll manually

I’ve spent several hours this week debugging a WCF application using Entity Framework, that was published to an IIS server, only to have every call to the service fill with the error message “The type initializer for [My]DbContext has caused an exception”. Of course, on the dev machine everything was working fine. Short answer: as the blog title implies, the application was missing EntityFramework.SqlServer.dll in its bin folder, because Visual Studio failed to recognize the fact it is referenced by the application. Lees meer over dit bericht

You cannot use a null propagating operator in an expression tree lambda

One of the features I like about the new C# 6.0 is the null conditional operator, and I tend to use it everywhere I can (and should). Until yesterday, when at a statement I wasn’t expecting it, the compiler bit me with error CS8072, An expression tree lambda may not contain a null propagating operator. If you think about it, it makes sense, but it is easy to miss. Lees meer over dit bericht

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:


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

Implementing IEquatable is not enough to use a class as a Dictionary key

Note to future self: it is not enough to implement IEquatable<T> to use a class as a Dictionary key.

Today I needed a Dictionary with a composite key, a combination of several values. So I quickly cooked up a class with public properties to cover the values and for ease of use, a constructor to quickly set those values. But to be able to use it as a dictionary key, I would need a little more. Per default, classes are only checked for reference equality, which makes sense. But I would need to have the system evaluate two separate instances of this class as equal, if all of their properties were equal. Lees meer over dit bericht

.Net Compact Framework project takes very long to build, appears to freeze

On Compact Framework project I was working on from Visual Studio 2008, targeting a Windows Mobile 6  device, I noticed that doing a build was getting slower and slower. Watching the output window, the build process would start off really quick and then seem to hang around for several minutes, sometimes making Visual Studio appear “not responding”, and after that finish off real quick.

I used Process Explorer to try to see what it was doing in that time, but did not get any wiser. I tried to learn my malware scanner to ignore the locations Visual Studio was reading from and writing to, thinking maybe it was slowing the compiler down because of troubles verifying executables targeting a non-desktop-Windows platform. But that was not it either.

Until I read a tip somewhere to increase the build output verbosity. That can be done from Tools / Options / Projects and Solutions / Build and Run:

So I set that to diagnostic, launched another build and went for a cup of coffee.

About ten minutes later I returned and found, at the end of a really big pile of text, a.o. this:

Task Performance Summary:
        0 ms  FindAppConfigFile                          1 calls
        0 ms  AssignTargetPath                          10 calls
        0 ms  Delete                                     1 calls
        0 ms  ReadLinesFromFile                          1 calls
        0 ms  CreateProperty                             1 calls
        0 ms  GetDeviceFrameworkPath                     1 calls
        0 ms  GetFrameworkPath                           1 calls
        0 ms  ResolveNonMSBuildProjectOutput             1 calls
        1 ms  AssignCulture                              1 calls
        1 ms  ConvertToAbsolutePath                      1 calls
        2 ms  RemoveDuplicates                           2 calls
        2 ms  Message                                    5 calls
        5 ms  MakeDir                                    5 calls
        6 ms  CreateVisualBasicManifestResourceName      2 calls
        8 ms  GenerateResource                           1 calls
        9 ms  ResolveAssemblyReference                   1 calls
        9 ms  Copy                                       6 calls
       16 ms  FindUnderPath                              5 calls
       21 ms  AddHighDPIResource                         1 calls
       42 ms  MSBuild                                    3 calls
      193 ms  AL                                         4 calls
      249 ms  Vbc                                        1 calls
    329655 ms  PlatformVerificationTask                   1 calls

Build succeeded.

Time Elapsed 00:05:30.33
========== Build: 2 succeeded or up-to-date, 0 failed, 0 skipped ==========

Woah! PlatformVerificationTask? What’s that thing? I don’t know what it’s doing, and why is it taking so long? Well, i now had an extra keyword to google, which lead me to this discussion and another (which unfortunately could only be accessed from google’s cache).

It turns out that, for my situation, it’s safe to turn the entire task off.

So I opened the file


and looked up the key:

<Target Name="PlatformVerificationTask">

I changed that to:

<Target Name="PlatformVerificationTask" Condition="0==1">

(Note that with UAC you need to be elevated to save to that location). The condition obviously always evaluates to false, which effectively disables the task. Close the solution, re-open and build again. Now it’s done in seconds again. Great!

If you can’t disable the task completely like I did, because it’s a build machine, because you need it for some projects and not for some other, etc., there are some suggestions in the linked thread about making the task conditional.