Case of the Network Name That Couldn’t Be Found

Continuing the series on .NET patching from

An application when moved from XP to Windows 8.1 started reporting error The network name cannot be found.


A dump file was taken at this point with procdump –ma option ( )

Because this is 32-bit .NET 2.0 process, we load in x86 WinDbg and load .NET 2.0 SOS extension:


0:000> .load C:\Windows\Microsoft.NET\Framework\v2.0.50727\SOS.dll
0:000> .cordll -ve -u -l
CLRDLL: C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscordacwks.dll:2.0.50727.5485 f:0
doesn’t match desired version 2.0.50727.8009 f:0
CLRDLL: Unable to find ” on the path
Cannot Automatically load SOS
CLRDLL: Loaded DLL g:\symbols\mscordacwks_x86_x86_2.0.50727.8009.dll\53A11D015b0000\mscordacwks_x86_x86_2.0.50727.8009.dll
CLR DLL status: Loaded DLL g:\symbols\mscordacwks_x86_x86_2.0.50727.8009.dll\53A11D015b0000\mscordacwks_x86_x86_2.0.50727.8009.dll
0:000> !pe
Exception object: 02651d00
Exception type: System.ComponentModel.Win32Exception
Message: The network name cannot be found
InnerException: <none>
StackTrace (generated):
    SP       IP       Function
    0038EB74 6143C043 System_ni!System.Diagnostics.Process.StartWithShellExecuteEx(System.Diagnostics.ProcessStartInfo)+0x267
    0038EBA4 6143B1DD System_ni!System.Diagnostics.Process.Start()+0x39
    0038EBB4 6143AEAA System_ni!System.Diagnostics.Process.Start(System.Diagnostics.ProcessStartInfo)+0x32
    0038EBC4 6143AF1C System_ni!System.Diagnostics.Process.Start(System.String)+0x20
    0038EBCC 05853E67 wds!StreamlineUI.MainForm.DisplayImage(System.String)+0x7f

StackTraceString: <none>
HResult: 80004005

From dumping stack objects, it seems like the file path has too many double back slashes

0:000> !dso
OS Thread Id: 0x1e3c (0)
ESP/REG  Object   Name
0038ea70 02291198 System.String   
0038ea74 02651fbc System.String    The network name cannot be found
0038ea88 025add10 System.Windows.Forms.ControlBindingsCollection
0038eadc 02651fbc System.String    The network name cannot be found
0038eb20 025add10 System.Windows.Forms.ControlBindingsCollection
0038eb24 02651fbc System.String    The network name cannot be found
0038eb28 025fceb0 System.String    \\server01\\Images\\WDS\\FaxImages\\2015\09\17\104510_Fax_FILE01_0309.tif
0038eb48 02291198 System.String   
0038eb4c 02293be0 StreamlineUI.MainForm
0038eb8c 025add10 System.Windows.Forms.ControlBindingsCollection
0038eb98 025fd174 System.Diagnostics.ProcessStartInfo
0038ebb4 025fceb0 System.String    \\server01\\Images\\WDS\\FaxImages\\2015\09\17\104510_Fax_FILE01_0309.tif
0038ebb8 025fceb0 System.String    \\server01\\Images\\WDS\\FaxImages\\2015\09\17\104510_Fax_FILE01_0309.tif
0038ebcc 025fceb0 System.String    \\server01\\Images\\WDS\\FaxImages\\2015\09\17\104510_Fax_FILE01_0309.tif
0038ebd0 02293be0 StreamlineUI.MainForm

Further investigation identified the fact that these filenames came from a database, and had already been stored in this format. In Windows XP this faulty file paths didn’t cause a problem, the images still opened OK in Internet Explorer which had been configured to be default viewer for TIF files.

Without write access to the DB, and software developer unable to make a patch I worked in a simple patch. This time instead of developing the patch in MSIL I created a C# Class Library (DLL) with the following code:


using System; using System.Collections.Generic; using System.Text; using System.Text.RegularExpressions; namespace DotNetPatches { public static class FilePaths { public static string Fix(string path) { try { return Regex.Replace(path, @"(?!^)\\\\", @"\"); } catch { return path; } } } }

Now we decompile our broken EXE with ILDASM and open the IL file for editing. At beginning of .IL file we add the reference to our DLL

.assembly extern DotNetPatches { .ver 1:0:0:0 }

Using .NET reflector we had identified get_IMAGEPATH as the method responsible for retrieving our faulty file path, so we patch it to fix the value it returns by inserting a call to our Fix function.

.method public hidebysig specialname instance string get_IMAGEPATH() cil managed { // Code size 12 (0xc) .maxstack 8 IL_0000: ldarg.0 IL_0001: ldfld class [System.Windows.Forms]System.Windows.Forms.TextBox StreamlineUI.MainForm::txtImageURI IL_0006: callvirt instance string [System.Windows.Forms]System.Windows.Forms.Control::get_Text() call string [DotNetPatches]DotNetPatches.FilePaths::Fix(string) IL_000B: ret } // end of method MainForm::get_IMAGEPATH

After recompiling with ilasm this patched application now works fine in Windows 8.1

About chentiangemalc

specializes in end-user computing technologies. disclaimer 1) use at your own risk. test any solution in your environment. if you do not understand the impact/consequences of what you're doing please stop, and ask advice from somebody who does. 2) views are my own at the time of posting and do not necessarily represent my current view or the view of my employer and family members/relatives. 3) over the years Microsoft/Citrix/VMWare have given me a few free shirts, pens, paper notebooks/etc. despite these gifts i will try to remain unbiased.
This entry was posted in .NET, AppCompat, Patching and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s