简体   繁体   English

C#哈希表“未设置对象引用”

[英]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. 我下面有以下代码,基本上是一个将值与html文件合并并提供结果集的功能。 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();" 它在“ 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. 不同生产服务器之间的唯一区别是操作系统和正在运行的IIS。 ie. 即。 Server 2005 and IIS7 vs Server2003 and IIS6 (which is the environment that it breaks on). Server 2005和IIS7与Server2003和IIS6(这是它所处的环境)。 Both have .net framework up to 3.5 installed. 两者都安装了.net框架,最高支持3.5。 Could the older OS and ISS be the problem? 较旧的OS和ISS可能会引起问题吗? 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. 尽管这听起来有些不可思议,因为我在新生产服务器上使用的所有其他.net功能都可以正常工作。

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. 但是,我的错误发生在试图实例化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. 使用Reflector Pro进行远程调试的建议也不起作用,指出网站正在运行的虚拟服务器存在一些问题。检查日志文件显示.net框架抛出了其他错误。

The website was moved to a new virtual server using IIS7 and windows server 2008. It worked as is on the new environment. 该网站已使用IIS7和Windows Server 2008移到了新的虚拟服务器上。它在新环境中仍能正常工作。

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. 对于所有人来说,这可能都不是理想的解决方案,也许重新安装框架可以解决我们的问题,但是由于我们正处于转换到新环境的过程中(由于其他原因),因此该解决方案很适合我们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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