1

I have a VSTO add in for Outlook written in C# that has a button to display a chm help file that has been working fine for a couple of years, and suddenly stopped working. When I click the button that runs the following code, nothing happens,

try
{
    string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase), "ema.chm");

    // Show the help.
    Help.ShowHelp(null, path);
}
catch (System.Exception ex)
{
    MessageBox.Show(ex.Message);
} 

Does anyone have any ideas what may cause a problem like that?

Russ Clark
  • 13,260
  • 16
  • 56
  • 81
  • 1
    does the line containing `ShowHelp()` function get hit when debugging? – Scott Solmer Jun 17 '14 at 19:04
  • Maybe there was a change in the environment? Missing CHM file? Different assembly location? – user2864740 Jun 17 '14 at 19:05
  • 1
    Has the path of the helpfile moved perhaps? – Matthijs Jun 17 '14 at 19:05
  • No, I checked to see if the chm file is there, and it is, and nothing has changed with regard to the assembly location. – Russ Clark Jun 17 '14 at 19:13
  • Use Assembly.Location, not CodeBase. – Hans Passant Jun 17 '14 at 19:20
  • @Okuma.Scott - Yes, when I run it in debug the line with the ShowHelp() call does get executed. Actually, I'm running in debug on a Win 7 machine that has Visual Studio 2010 installed on it (VSTO isn't supported in Visual Studio 2013) and it works fine on that machine. It doesn't work on my Windows 8 machine, and to complicate matters further, I know of at least one user that is having this problem on his Windows 7 machine. – Russ Clark Jun 17 '14 at 20:13
  • So it was working on Windows 8, but now it's not? Or it never worked on Windows 8? – Jim Mischel Jun 17 '14 at 20:58

2 Answers2

1

I see two potential problems.

1) The way you are building path is not reliable.
There are many ways to get a path, and they are not all created equal. For example, GetCallingAssembly is susceptible to JIT inlining which may produce varying results.
But I believe the real issue was hinted at by Hans already.
Try using a different way to build your path. For example, this way.

Here is an example of the way I usually get the path of a file in the assembly directory using a property:

    private string myXMLFile()
    {
        string ExecutingPath = AppDomain.CurrentDomain.BaseDirectory;
        return ExecutingPath + "MyFile.XML";
    }

Then it's easy to use it like this:

if (File.Exists(myXMLFile) == false) { CreateNewXMLFile(); }
XDocument Xdoc = XDocument.Load(myXMLFile);
...
Xdoc.Save(myXMLFile);

2) .CHM format may be blocked by Windows for "security" reasons.
It can be unblocked however, which leads to it working on some systems but not on others.
See Windows 8 64bit can't open chm files

Community
  • 1
  • 1
Scott Solmer
  • 3,871
  • 6
  • 44
  • 72
  • #Okuma.Scott - It turned out that the problem was caused by a change we had incorporated a while back to install the dll's in the GAC. Out code was broken since the chm file was not in the GAC. I switched the code to use your "AppDomain.CurrentDomain.BaseDirectory: code above to get the directory for the program in Program Files, and it's working fine now. I'm marking you answer as the solution. – Russ Clark Jun 24 '14 at 15:41
0

If it's really true nothing changed and working for years hh.dat may cause a error.

The hh.dat file stores user-specific information on all the HTMLHelp files (*.CHM) on your system (position, favourite topics, search history, etc.), and may cause a error if it has somehow been corrupted.

Delete or rename the file hh.dat to reset all (!) CHM windows on your system to their default settings. Windows will create a new version of hh.dat when you next open any .chm file. You should find hh.dat at:

Windows XP: \Documents and Settings\%username%\Application Data\Microsoft\HTML Help

Windows 7: \Users\%username%\AppData\Roaming\Microsoft\HTML Help

help-info.de
  • 6,695
  • 16
  • 39
  • 41