2010-05-04 44 views
0

是VS2010,我分析我的代码,并得到这个错误:代码分析错误:声明类型的命名空间

Warning 64 CA1050 : Microsoft.Design : 'ApplicationVariables' should be declared inside a namespace. C:\My\Code\BESI\BESI\App_Code\ApplicationVariables.vb 10 C:\...\BESI\ 

Here是错误一些参考信息。本质上,我尝试创建一个类,用于以类型化的方式访问Application对象中的数据。

警告消息说,除非我把我的(ApplicationVariables)类放在名称空间中,我无法使用它。但我正在使用它,所以给了什么?

此外,here是另一个StackOverflow文章的链接,它介绍了如何在VS2008中禁用此警告,但是如何禁用它在2010年? VS2010没有GlobalSuppressions.vb文件。

这里是它抱怨一个回合代码:

Public Class ApplicationVariables 

    'Shared Sub New() 

    'End Sub 'New 

    Public Shared Property PaymentMethods() As PaymentMethods 
     Get 
      Return CType(HttpContext.Current.Application.Item("PaymentMethods"), PaymentMethods) 
     End Get 
     Set(ByVal value As PaymentMethods) 
      HttpContext.Current.Application.Item("PaymentMethods") = value 
     End Set 
    End Property 
    'Etc, Etc... 

End Class 

回答

0

我怀疑你输入的代码是在你的web应用程序的App_Code文件fodler。此代码可以从您的Web代码访问,因为您已经进行了移除,但无法从任何其他程序集访问该代码。

您可以通过右键单击特定错误并选择“抑制源中的消息”来抑制错误的实例。这会导致代码被添加到您的源代码中,并显示“下一次您检查此错误-fuggedabodit!”

When to Suppress Warnings 
-------------------------------------------------------------------------------- 

While it is never necessary to suppress a warning from this rule, it is safe to do this when the assembly will never be used with other assemblies. 

取消错误上所有出现,选择“禁止在禁止项目文件”