简体   繁体   中英

C# Hashtable “object reference not set”

I have an interesting problem that I am trying to solve. I have the following code below which is basically a function for merging values with an html file and giving me the result set. I am using a hashtable for those purposes.

The function is as follows (Please bear in mind that I inherited this functionality and cannot be changed at present)

public static string ParseTemplate(string _FileName, int _NumberofSomething)
{
  Hashtable templateVars = new Hashtable();
  templateVars.Add("NameOfFile", _FileName);
  templateVars.Add("NumberOfSomething", _NumberofSomething);
  TemplateParser.Parser parser = 
      new TemplateParser.Parser(
          System.Web.HttpContext
            .Current.Server.MapPath("~/docs/Templatenr.htm"), templateVars);
  return parser.Parse();
}

On our dev and live servers it is working perfectly. However I am trying to deploy the app to another production server and get an "object reference not set to an instance of object". It breaks exactly on the "Hashtable templateVars = new Hashtable();" line. So I am a bit puzzled. If it was a coding problem it should not work everywhere surely?

The only differences between the different production servers are the OS and IIS that is running. ie. Server 2005 and IIS7 vs Server2003 and IIS6 (which is the environment that it breaks on). Both have .net framework up to 3.5 installed. Could the older OS and ISS be the problem? Is it a maybe permission/memory thing? though that sounds a bit implausible since all the other .net functionality I am using on the new production server is working perfectly.

All the issues regarding the hashtable that I found, relates to it not being instantiated. However my error happens on the line that is trying to instantiate a Hashtable.

Has anyone had an error like this before and if so how did you solve it? I'd even appreciate suggestions on what to look for and I'll give it a try. I'll post back the outcome too, if anyone else is experiencing this error in future.

I never really got to the bottom of this error. Suggestions for using remote debugging with Reflector Pro did not work either, pointing to some issues with the virtual server the website was running in. Checking log files showed other errors that the .net framework threw out.

The website was moved to a new virtual server using IIS7 and windows server 2008. It worked as is on the new environment.

This is maybe not the ideal solution for everybody and maybe a framework re-install could have solved our problem, but since we were in the process of changing over to a new environment (for other reasons) this solution suited us.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM