Ajax Control Toolkit Calendar doesn’t close when clicking outside the calendar

Just a quick one: if you have a textbox with a Calendar (extender) from the Ajax Control Toolkit and an associated PopupButtonID which is an image, the calendar won’t close when you click outside the popup. Use an input type=”image”or an ImageButton to solve this problem.

Hope this helps.

Documents.Open returns null, running Word automation under ASP.NET on x64

When building an ASPapplication that generates Word documents,  it was working fine on the local machine. A windows XP installation with Office 2007. When we deployed it to windows 2008 (64 bit) and Word 2007 we saw that Documents.Open returned null. Other than this, there are no exceptions.

The code that returned the error (simplified):

Application app = new Application();
Document doc = app.Documents.Open(ref name);

As it turns out, a 64 bit system stores temporary files in “C:WindowsSysWOW64configsystemprofileDesktop” folder.

The solution: create a new directory called “Desktop” inside “C:WindowsSysWOW64configsystemprofile”

Hope this helps.

Unhandled exception installing SQL Server 2008 R2 on a Windows XP / Windows 7 machine

System.Configuration.ConfigurationErrorsException: An error occurred creating the configuration section handler for userSettings/Microsoft.SqlServer.Configuration.LandingPage.Properties.Settings: Could not load file or assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified. (C:Documents and SettingsBoschRLocal SettingsApplication DataMicrosoft_CorporationLandingPage.exe_StrongName_ryspccglaxmt4nhllj5z3thycltsvyyx10.0.0.0user.config line 5) ---> System.IO.FileNotFoundException: Could not load file or assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified.When installing SQL Server 2008 R2 on a Windows XP (or, according to the comments, Windows 7) development machine that has been around for quite some time, I got an error stating an unhandled exception occured in the application (see image). The error showed up directly upon startup and read:

An error occurred creating the configuration section handler for userSettings/Microsoft.SqlServer.Configuration.LandingPage.Properties.Settings: Could not load file or assembly ‘System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’ or one of its dependencies.

Repairing the .NET 4.0 framework didn’t solve the issue. Neither did removing all SQL stuff through ‘Add or Remove Programs’. Looking into the error a bit further…

 The system cannot find the file specified. (C:Documents and Settings_USERNAME_Local SettingsApplication DataMicrosoft_CorporationLandingPage.exe_StrongName_ryspccglaxmt4nhllj5z3thycltsvyyx10.0.0.0user.config line 5) —> System.IO.FileNotFoundException: Could not load file or assembly ‘System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’ or one of its dependencies. The system cannot find the file specified.

 So the problem probably wasn’t that System.dll couldn’t be found, but some user.config file for the landingpage executable. The solution is as simple as it is radical: remove the entire (temporary) folder ‘C:Documents and Settings_USERNAME_Local SettingsApplication DataMicrosoft_Corporation’ (where USERNAME_ is, of course, the current username). After this the setup should start up without any problems.

By |January 27th, 2012|.Net, Development, Error, SQL, Work|1 Comment

Error installing the Windows Azure AppFabric Tools for Visual Studio (CTP)

Windows Server AppFabric is installed and is not compatible with this release of Windows Azure AppFabric Developer Tools for Microsoft Visual Studio 2010 - June 2011 CTP. Please uninstall Windows Server AppFabric and rerun this setup if you want to install Windows Azure AppFabric Developer Tools for Microsoft Visual Studio 2010 - June 2011 CTP.When installing the Windows Azure AppFabric Tools for Visual Studio (found here), you might get the error message shown on the right, stating that Windows Server AppFabric is installed and that it is not compatible with this release of Windows Azure AppFabric Developer Tools for Microsoft Visual Studio 2010 – June 2011 CTP. It asks to uninstall Windows Server AppFabric and rerun this setup if you want to install Windows Azure AppFabric Developer Tools for Microsoft Visual Studio 2010 – June 2011 CTP.

When looking for the install of ‘Windows Server AppFabric’ to remove it through ‘Uninstall a program’ you won’t find this item in the list of installed programs. This might feel as a big problem heading your way…

Solution
This is, however, only a small problem on your way to Azure AppFabric development. Go to your list of installed programs and click ‘View installed updates’. Under Windows, you will find the update ‘Windows Server AppFabric (KB970622)’. Uninstall the update, restart your machine and try installing the Windows Azure AppFabric Tools for Visual Studio again…

Enjoy!

The Visual Studio 2010 Test Client for WCF services

When writing WCF services, most of us find ourselves writing quick test applications. To give you more time to do what a developer should be doing (adding business value to the project) the Visual Studio team added a WCF test client that can help you reach goals faster.

This is not a very difficult application, but it does the trick and is more than sufficient for simple testing. The WCF Test Client can be found at this location (without the ‘ (x86)’ for x86 machines): C:Program Files (x86)Microsoft Visual Studio 10.0Common7IDE.

Taken from the help:

Windows Communication Foundation (WCF) Test Client (WcfTestClient.exe) is a GUI tool that allows users to input test parameters, submit that input to the service, and view the response that the service sends back. It provides a seamless service testing experience when combined with WCF Service Host.

WCF Test Client screenshots:
image image

Updated: Thanks to Marco for pointing out my typo…!

HowTo: Save a file from Silverlight using the SaveFileDialog

Saving a file from Silverlight using the SaveFileDialog, added in Silverlight 3, is easy. If you’re used to desktop development however, you might find yourself getting a SecurityException with the message ‘File operation not permitted. Access to path ‘xxx’ is denied.’. Here’s why:

In desktop development, you’re used to getting a filename from a SaveFileDialog. Next, you start doing whatever you need to be doing to the file, based on the filename. This would look something like this:

SaveFileDialog saveFileDialog = new SaveFileDialog();

if (saveFileDialog.ShowDialog() == true)
{
    StreamWriter streamWriter = new StreamWriter(saveFileDialog.SafeFileName);
    streamWriter.Write("Follow me on twitter: @rickvdbosch");
    streamWriter.Flush();
    streamWriter.Close();
}

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

This results in the SecurityException. First time I saw the property, I genuinely thought it said SaveFileName. But, as you can see, it says SafeFileName. It is named safe, because the returned file name has all file path information removed for security purposes.

In Silverlight, if you want the above functionality, it should look something like this:

SaveFileDialog saveFileDialog = new SaveFileDialog();

if (saveFileDialog.ShowDialog() == true)
{
    StreamWriter streamWriter = new StreamWriter(saveFileDialog.OpenFile());
    streamWriter.WriteLine("Follow me on twitter: @rickvdbosch");
    streamWriter.Flush();
    streamWriter.Close();
}

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }The OpenFile method opens the file specified by the SafeFileName returning a Stream, giving you the opportunity to save whatever you want to save over there.

Hope this helps.

On a side note: the ‘== true’ part in the if condition is needed in this case. Because the ShowDialog method returns a nullable boolean it is not enough to use saveFileDiaolog.ShowDialog() in the condition. Just so you know… :)

HowTo: open all files from the Find Results window

Here’s a quick Visual Studio tip for you…

I frequently search for a specific text in my solution because I need to do something in all places where that text occurs. Today I found out how you can open all the files that are mentioned in the Find Results window.

Search for the text you’re looking for. In my case this is ITest*.
Open up the Search Results window and select all the records where the text was found. You can do this by dragging your mouse cursor over the text or clicking the text of the first search result, holding SHIFT and clicking the text of the last.
Search Results for ITest

Right click anywhere on the selected text and choose ‘Go to location’. If you click anywhere other than on selected text, you will lose the selection and you’ll probably get just one file opened. When all files are opened you will keep the ‘Go To Next Location F8’ and ‘Go To Previous Location SHIFT + F8’ functionality. That might be a nice one to loop through all the locations where your text was found. Especially when it was found more than once in one file.

Hope this helps.

 

* The usefulness of searching for this interface is arbitrary due to functionality as ‘Find all references’ and so on. Luckily I’m only using it for this example. So lets not focus on that but on the tip this post is about ;)

‘Cannot find entry to delete’ deleting files from a Zip with (SL) SharpZipLib

For a project I’ll probably dedicate a post on this blog to in the future, I needed a ZIP library for Silverlight. After asking around on twitter (@rickvdbosch) I was pointed towards the SharpZipLib port on Codeplex, found on http://slsharpziplib.codeplex.com.

Basically what I wanted to do was replace a file inside the ZIP file with my version of that file. The file was located in a specific folder inside the ZIP and could be found by either iterating through the ZipEntries in the ZIP, or by getting it based on its name. But deleting the file gave me a ZipException with the error message ‘Cannot find entry to delete’. When I added a file myself, it could be deleted just fine, but the ZIP just did not want the existing file to be removed.

After searching around on some forums, I found there was a new development version of SharpZipLib which might solve the problem. But that was the full version, not the Silverlight port. So I searched around some more and found something about subfolders.

As it turns out, and existing file can be deleted when it is located in the root of the ZIP. Apparently there’s some bug keeping you from deleting files in subfolders. Anyhow, moving the file I need updated to the root of the ZIP solved my problem for me (for now), so I can continue my project. If and when slsharpziplib is updated in the future, I’ll have a look if they solved this in the port too…

Hope this helps.

By |January 12th, 2011|.Net, Error, Silverlight|0 Comments

Patches available for scrolling context menu in Visual Studio 2010

The past couple of days I’ve been experiencing some issues with the context menu for my Solution Explorer in Visual Studio 2010. It contained scrollbars even when there was sufficient space on the screen to show the menu without scrolling.

Searching for that issue I immediately found this blog post on The Visual Studio Blog. Taken from that post:

We’re pleased to announce that there are patches available for Visual Studio and Windows Presentation Foundation that fix this problem. You will need to install both patches to fix this issue

  1. Visual Studio 2010 patch: http://code.msdn.microsoft.com/KB2345133
  2. Windows Presentation Foundation 4.0 patch: http://code.msdn.microsoft.com/KB2413613
    1. X86: NDP40-KB2413613-x86.exe.
    2. X64: NDP40-KB2413613-x64.exe.

I installed both patches and find Visual Studio no longer shows scrollbars in my context menu when I don’t need ‘em. Next to that I am now able to scroll through the menu (when using scrollbars) by using the mousewheel. I think this didn’t work before the patches, but I can’t test my ‘before’ situation anymore…

Hope this helps.

Using Crystal Reports in ASP.NET on a 64 bit machine

The above scenario gave me the well-known could not load file or assembly error message. The assembly that couldn’t be found was  ‘log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=692fbea5521e1304’. Or one of its dependencies of course… The situation in which I was getting this error message:

  • using the CrystalReportViewer in an ASP.NET application
  • having the ASP.NET application hosted in IIS (the error did not occur on the ASP.NET Development Server)
  • running on a 64 bit machine

Log4net was available in the GAC, with the exact version and PublicKeyToken stated in the error message. So that couldn’t be the problem. Or could it…? Having a second (and closer) look at the log4net assembly in the GAC one thing stood out.
log4net-x86

The Processor Architecture for the log4net assembly is set to x86. That means it can’t be loaded by IIS, which is x64 on this machine. OK, so now we know what’s wrong. Next: how to solve this?

Solution
I tried several things to get my (x64) IIS, Crystal Reports and log4net to get to play together nicely. Things that did not help to get this problem fixed included removing log4net from the assemblies section of the web.config, kicking my machine around the office and trying to recompile log4net for the x64 architecture.

As far as I have been able to find out, these two steps will get it working:

  1. Enable 32 bit ASP.NET IIS integration
    Open a command prompt, go to the non x64 framework folder of your choice (for instance C:WindowsMicrosoft.NETFrameworkv4.0.30319) and execute “aspnet_regiis –enable –i”
  2. Enable 32 bit apps for 64 bit IIS
    Open a command prompt and execute “cscript.exe %SystemDrive%inetpubAdminScriptsadsutil.vbs set W3SVC/AppPools/Enable32BitAppOnWin64 true
    If you do not have the admin scripts installed, install the from the ‘Turn Windows features on or off’ option in your Control Panel. The scripts are located under Internet Information Services – Web Management Tools – IIS 6 Management Compatibility – IIS 6 Scripting Tools.

I’m not sure of any negative side-effects at this point. If I run into any in the future I’ll let you know. For now my application is working like a charm!

Hope this helps.

By |January 5th, 2011|.Net, Error, x64|2 Comments