当前上下文中不存在名称“xxx” [英] the name 'xxx' does not exist in the current context

查看:160
本文介绍了当前上下文中不存在名称“xxx”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在项目的\App_Code \文件夹中创建了一个类(名为PrintHelp.cs)。在.aspx.cs文件中,我尝试在PrintHelp.cs中调用一个方法,但是编译错误:当前上下文中不存在名称PrintHelp。我用Google搜索了这个错误。有人指出,可能存在具有相同名称的备份文件。我搜索并发现没有这种备份文件。在我的\ App_Code \文件夹中,还有其他几个.cs文件,如果在我的程序中调用它们,则可以很好地识别它们。怎样才能解决这个问题?如果你能提示我可能的解决方案,请提前感谢。

I created a class (named PrintHelp.cs) in my project's \App_Code\ folder. In an .aspx.cs file, I tried to call a method in the PrintHelp.cs, but got compiling error: the name 'PrintHelp' does not exist in the current context. I googled for this error. Someone points out that it could be possibly the existence of of a backup file with the same name. I searched and found no such kind of backup file. In my \App_Code\ folder, there are several other .cs files, and they can be recognized well if they are called in my program. How can this problem be solved? Thanks in advance if you can hint me the possible solution.

推荐答案

由于我找不到合适的解决方案,我将方法加载到文件中以便引用到.cs文件在本地,编译错误消失了。这绝对不是正确的解决方案,但可以帮助我避免暂时的头痛。感谢所有评论者。
Since I could not find the proper solution, I loaded the methods in the file to be referenced into the .cs file locally, the compiling error was gone. This is absolutely not proper solution, but can help me avoid the headache for the time-being. Thanks to all reviewers.


Make change your class type to static to access your static method public static void PrintWebControl(Control ctrl, string Script) 

public static class PrintHelper
{...
Because A static class can access a static method


这篇关于当前上下文中不存在名称“xxx”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆