Category Archives: Development

Generate GUID in PERL

It’s very common for developer to generate a GUID in code to guarantee uniqueness. Here is the sample code to generate a GUID in Perl

my $guid = `uuidgen.exe`;
chomp $guid;

Uuuidgen.exe is a tool from DotNet Framework. You can append "-c" option to generate uppercase letters

Run uuidgen /? to see the detail usage of uuidgen.
Microsoft UUID Generator v1.01 Copyright (c) Microsoft Corporation. All rights reserved.

usage: uuidgen [-xisconvh?]
        x – Generate sequential (V1) UUIDs
        i – Output UUID in an IDL interface template
        s – Output UUID as an initialized C struct
        c – Output UUID in upper case
        o<filename> – redirect output to a file, specified immediately after o
        n<number> – Number of UUIDs to generate, specified immediately after n
        v – display version information about uuidgen
        h,? – Display command option summary

IIS 7.5 Error The temp directory in chart handler configuration is not accessible

If you build a web application with Chart control for ASP.NET 4.0 and deploy the site to web server.  You might get following error on the live site:

The temp directory in chart handler configuration is not accessible

To resolve this, first go to web.config and find the ChartImage directory in appsettings.

<appSettings>
<add key="ChartImageHandler" value="storage=file;timeout=20;dir=c:TempImageFiles;" />
</appSettings>

The go to the temp chart image directory and grant read and write permission to IIS working process account in share properties – security tab. Note that the account runs IIS working process is different between IIS 7 and IIS 7.5

  • On Windows Server 2008 has IIS7, grant Read and Write permission to Network Service
  • On Windows server 2008 R2 has IIS 7.5, grant Read and Write permission to AppPool<PoolName>. Replace <PoolName> to the actual machine pool your site is running on, for example, if your site is running on pool named ASP.NET v4.0, then the account you need grant permission would be IIS AppPoolASP.NET v4.0, you can refer this step by step instructions for detail

Could not load file or assembly TraceWrapper, Version=1.0.523.0

There are two versions of the TraceWrapper.dll in SCVMM install CD. One is x86 version and the other is x64 version. When you build your application on top of SCVMM library Microsoft.SystemCenter.VirtualMachineManager, it’s very important to pick up the correct version TraceWrapper.dll. In general, you should copy the 32 bit dll if you are using 32 bit system, copy 64 bit dll if you are using 64 bit system. Otherwise following BadImageFormatException would occur during runtime.

Could not load file or assembly ‘TraceWrapper, Version=1.0.523.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35’ or one of its dependencies. An attempt was made to load a program with an incorrect format.

However, you should keep using 32 bit TraceWrapper on a 64 bit system for following scenarios:

  • You need debug your app in Visual Studio directly. In this case, process launched from Visual Studio debugger runs in WOW64 mode.
  • IIS is configured to run in 32 bit mode. In this case, all working processes run in WOW64 mode.

This is because in 64 bit windows, processes in WOW64 mode are 32 bit processes and can’t load 64 bit TraceWrapper.dll.

Handler “PageHandlerFactory-Integrated” has a bad module “ManagedPipelineHandler” in its module list

You might see following error when browse your application site targeting ASP.NET 4.0 on IIS 7 or 7.5 server.

HTTP Error 500.21 – Internal Server Error
Handler “PageHandlerFactory-Integrated” has a bad module “ManagedPipelineHandler” in its module list

Cause & Solution

If IIS is enabled after DotNet 4 installation then ASP.NET is not registered with IIS. You will see the error if your site is targeting ASP.NET 4. To resolve this issue, run the following from elevated command line to register ASP.NET 4:

aspnet_regiis.exe –i

This will register asp.net with IIS. The aspnet_regiis.exe file can be found in either

  • %windir%Microsoft.NETFrameworkv4.0.30319
  • %windir%Microsoft.NETFramework64v4.0.30319 (on a 64-bit machine)

More info for ASP.NET IIS Registration Tool (Aspnet_regiis.exe) can be found at http://msdn.microsoft.com/en-us/library/k6h9cz8h.aspx

Configure WordPress to Use Proxy

If you setup a WordPress site on a server in intranet behind a proxy, you might get following error when you search plugins and themes in admin console.

An Unexpected HTTP Error occured during the API request.

This is because WordPress does not know the proxy server to talk to external internet. To resolve this, simply enable proxy by adding following lines to wp-config.php file

define(‘WP_PROXY_HOST’, ‘192.168.110.1’);
define(‘WP_PROXY_PORT’, ’80’);

Replace 192.168.110.1 and 80 with your actual proxy server and port.

If the intranet proxy requires user authentication, appending following lines.

define(‘WP_PROXY_USERNAME’, ‘UserName_ReplaceMe’);
define(‘WP_PROXY_PASSWORD’, ‘UserPassword_ReplaceMe’);

Common TFS commands

tf.exe is Team Foundation source control command-line tool which can be used to perform source control operations without GUI interaction. Here are some common tf commands I use in my daily work. You can run command tf /? to view more or visit MSDN TF Command Line Tool Reference

Common tf commands

sync Sync files under current folder tf get
Sync files under current folder and all sub folders tf get . /r
Sync file to a given revision tf get <filename>;<revision>
Display what would be synced tf get /preview
Force sync tf get /all
Force sync, will override existing files tf get /force
add Add new file tf add <filename>
checkout Checkout file for editing tf checkout <filename>
delete Delete file tf delete <filename>
rename Rename file tf rename
checkin Submit open files to tfs server tf checkin
resolve Resolve file conflicts tf resolve
Resolve file with automatical merge tf resolve /i /auto:acceptmerge>
shelve Package pending change and store to tfs server tf shelve <shelvesetname>
unshelve Unpackage shelve from tfs server into current workspace tf unshelve <shelvesetname>
workspace Update workspace configurations tf workspace <workspacename>

Common tfpt commands

tftp.exe is a command line tool that you can use to work with files and directories under version control, team projects, and work items. Some commands display a graphical user interface when run. tfpt.exe is part of Team Foundation Server Power Tools which can be downloaded here.

Revert unchanged files tfpt uu /noget
Search all modified files not in source control and add to pending change list tfpt online
Scorch – Remove all files in local workspaces but not in source control tfpt treeclean -delete
Undo submitted change tfpt undo
View difference of a shelve tfpt review /shelveset

How to debug msbuild issues

To debug msbuild build failures, you can run following from VS command prompt to get more build log output

msbuild /v:diag <solutionname>

If you want to log messages for debug during build, you can use Message tasks. For example, use Message task inside a target

<Target Name="DisplayMessages">
  <Message Text="Project File Name = $(MSBuildProjectFile)" />
  <Message Text="Project Extension = $(MSBuildProjectExtension)" />
</Target>

If you are doing build in VS2010 IDE, you can follow these steps to turn on verbose building to help debug msbuild issues.

  1. Open Visual Studio and go into the Tools->Options menu
  2. Go to Projects and Solutions->Build and Run and set MSBuild project build output verbosity to Diagnostic.
  3. Rebuild your project and now the output will show you all the environment variables and parameters.