views:

54

answers:

1

Is VS2010, I analyzed my code and got this error:

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 is some reference info on the error. Essentially, I tried to create a class to be used to access data in the Application object in a typed way.

The warning message said unless I put my (ApplicationVariables) class in a Namespace, that I wouldn't be able to use it. But I am using it, so what gives?

Also, here is a link to another StackOverflow article that talks about how to disable this warning in VS2008, but how would you disable it for 2010? There is no GlobalSuppressions.vb file for VS2010.

Here is the code it is complaining a bout:

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
A: 

I suspect that the code you entered is in your App_Code fodler of your web app. This code is accessible from your web code as you have deomnstrated but is not accessible from any other assembly.

You can suppress the instance of the error by right mouse clicking on the particular error and selecting "Suppress Message In Source." That'll result in code being added to your source that says "the next time you check this error-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. 

To suppress the error on all occurences, select "Suppress in Project Suppression File"

Velika