The symbolic link cannot be followed because its type is disabled

When access a symbolic link on a file server, sometimes you may see the following error: “The symbolic link cannot be followed because its type is disabled” This is because by default remote to remote symbolic links are disabled. You can enable it with fsutil. C:\Windows\system32>fsutil behavior query SymlinkEvaluation Local to local symbolic links are enabled.Local…

Internal Manifest vs External Manifest

Internal manifest is the RT_MANIFEST resource in the executable.  External manifest is App.exe.manifest. In Windows XP, Sxs searches external manifest before internal manifest. If an external manifest is found, the internal manifest is ignored.  In Windows Server 2003 and later, the order is reversed.  Internal manifest is preferred over external manifest. If you use external…



CLR HRESULT’ facility code is 0x13. If an HRESULT error is 0x8013xxxx, it is likely a CLR error. All CLR errors are defined in CorError.h. You can find CorError.h in your Visual Studio install (or Microsoft Platform SDK). C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include\CorError.h For example, #define FUSION_E_REF_DEF_MISMATCH       EMAKEHR(0x1040)     // The located assembly’s manifest definition does not match…


Be careful about exception after resource allocation

The following is a common code pattern         Resource resource = GetResource();         DoWork();                    return resource; If DoWork() throws exception, the resource will be leaked. We need to guard against this. For example         bool success = false;         Resource resource = GetResource();         try         {             DoWork();             success = true;            …


Exception Filter

C# does not support exception filter. However, VB and IL support it. To add exception filter to C#, we can build a function in VB or IL, then call it in C#. The example below is one way we may implement the function to support exception filter. It asks the caller to provide four delegates,…



I mentioned that we can use ThreadPool.BindHandle to implement asynchronous IO. Here are roughly the steps necessary to make it happen: 1.       Create an overlapped file handle             SafeFileHandle handle = CreateFile(                                 filename,                                 Win32.GENERIC_READ_ACCESS,                                 Win32.FILE_SHARE_READ | Win32.FILE_SHARE_WRITE | Win32.FILE_SHARE_DELETE,                                 (IntPtr)null,                                 Win32.OPEN_EXISTING,                                 Win32.FILE_FLAG_OVERLAPPED,                                 new SafeFileHandle(IntPtr.Zero, false));         [DllImport(“kernel32.dll”, CharSet…



CLR’s thread pool has two pools of threads. The first pool is used by ThreadPool.QueueUserWorkItem. The second pool is an IoCompletionPort thread pool used by ThreadPool.BindHandle and ThreadPool.UnsafeQueueNativeOverlapped. ThreadPool.BindHandle is used by CLR to implement asynchronous IO. For example, FileStream uses it to implement BeginRead/BeginWrite. Developers can take advantage of it too. We will talk…


Conversion between System.String and char *

We can convert a char * to System.String with System.String’s constructor string str = new string((char*)p); And for the reverse: fixed(char *p = str){} Why do we care about conversion between System.String and char *? From this article, this is the fastest way to marshal strings between managed and native boundary.


XXX is not a valid Win32 application

If you have used your Vista SP1-based computer for extended period, you may experience some problems starting large applications, for example, Office 2007 applications. Specifically, you may receive a message “XXX is not a valid Win32 application”. If you do experience this problem, you can install hotfix KB952709.