Code Analysis Error: Declare types in namespaces - vb.net

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

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"

Related

VB.NET Connected SAP WSDL Preventing Solution from building

I'm trying to build a .NET Class Library that utilises a SAP generated WSDL.
In the reference.vb file that one of the WSDLs generates, I'm getting the following error in this line:
<System.Xml.Serialization.XmlElementAttribute(Form:=System.Xml.Schema.XmlSchemaForm.Unqualified, Order:=0)> _
With the error being BC30369 Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class. on System.
This only occurs within one of the generated Partial Public Classes that it generates, and not the rest.
After removing System it works:
'''
<System.Xml.Serialization.XmlElementAttribute(Form:=Xml.Schema.XmlSchemaForm.Unqualified)>
Public Property MESSAGE_V4() As String
Get
Return Me.mESSAGE_V4Field
End Get
Set
Me.mESSAGE_V4Field = Value
End Set
End Property

Webforms Error shows TWO projects although solution shows ONE project

In a VS-2019 webforms solution I get this error that shows TWO projects although the solution only has ONE project.
Severity: Error
Code Description : BC30456 'prpPageCaption' is not a member of 'MasterPage'.
Project: 7_SessionExpired.aspx, repo_TripManagement
File: C:\Users...\SessionExpired.aspx.vb
Line: 100
Suppression State: Active
It appears that the error shows TWO projects and I did not create a project named 7_SessionExpired.aspx
The vb-page "SessionExpired.aspx and .vb" was copied from a similar project in VS-2017. This is confusing to me and I don't have any way to know what this error is saying.
Here is the LINE=100 from the source VB file:
100| | Master.prpPageCaption = "Session has Expired"
Here is the property in the master-page:
Public Property prpPageCaption() As String
Get
Return Me.lblCaption.Text
End Get
Set(ByVal p_sCaption As String)
Me.lblCaption.Text = p_sCaption
Me.updpanelPageCaption.Update()
End Set
End Property
The vb-page "SessionExpired.aspx and .vb" was copied from a similar project in VS-2017. This is confusing to me and I don't have any way to know what this error is saying. I need your help. Thanks...John
Think the IDE/VS-2019 is confused and I cut ALL of the files for SessionExpired.aspx (.vb) and pasted them in a my-documents-folder.
I then added a webform-page with Master-page (WebForm1.aspx) into the project.
I then added the ASPX objects as UI for the page. I performed a "View Code" option and the / VB-code structure is shown. I only added "Option Explicit ON". Saved both modified files and closed the SOLUTION.
I then re-opened the solution and the code compiled -- even though the full VB-functionality was not coded.
From the 'Solution Explorer' I then renamed the WebForm1.aspx to "SessionExpired" and compiled again -- all ok.
Finally I added the VB-code from the saved-off original SessionExpired.vb code.
All of the errors shown above were cleared and things are working.
IMHO, bringing in an older webform brings with it the old-style of 'designer' and by starting with a VS-2019 webform-page conforms to the VS-2019 designer pattern.
I apologize to those that viewed this question.
Thanks. John.

"The object does not support this method" - Error when trying to update the subject of an email (MailItem.Subject)

I'm maintaining a C# Outlook add-in. It runs, since many years, in Outlook 2003. Today, a user reported an error I never saw before. For two mails (both from the same sender), she's getting this error message when she tries to process them:
The object does not support this method.
at Microsoft.Office.Interop.Outlook._MailItem.set_Subject(String Subject)
The exception is raised when the add-in tries to update the subject:
private static void ForceReconnectToExchangeServer(Outlook.MailItem mi)
{
mi.Subject = mi.Subject + ""; // <-- HERE
mi.Save();
}
I can see a second error message (a tooltip at the end of the line in Visual Studio):
errorCS0433: The type 'MailItem' exists in both
'Microsoft.Office.Tools.Outlook.Implementation, Version=10.0.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' and
'Microsoft.Office.Tools.Outlook, Version=10.0.0.0, Culture=neutral
(... can't see the rest of the line ....)
Any idea why this is happening? Many thanks!
Note 1: This add-in uses a recent version of Redemption.
Note 2: I'm getting the same error when I forward the message to myself (an process it), even if I delete everything in the message. If I change the mail format to Plain Text however, no error.
Note 3: this problem maybe related to this one, but nobody answered it.
Do you have both references in your project? Make sure there are no conflicts.
Also keep in mind that updating Subject will cause conversation specific properties to be be reset. Resetting the message class (IPM.Note.Dummy, then back to the original one) might be a better idea.
The Microsoft.Office.Tools.Outlook namespace contains a set of classes and interfaces that enable you to create form regions that customize Microsoft Office Outlook forms.
I'd suggest reviewing the code base and remove unused references from the project. Also make sure that the Outlook namespace points to the Microsoft.Office.Interop.Outlook one, for example:
private static void ForceReconnectToExchangeServer(Microsoft.Office.Interop.Outlook.MailItem mi)
{
mi.Subject = mi.Subject + ""; // <-- HERE
mi.Save();
}

VS: Update Service Reference creates requirement for "Global" prefixes in Reference.vb

VB 2012
WCF & EF 6.1*
I have a client and a web service. When I recompile/change the WS, I go back to my client, and 'Update Service Reference'. Works like a charm-except, the resulting Reference.vb in the client complains that any classes that were defined from the server have a Global. prefix; To be precise, the error description is:
Error 9 Type 'serverNamespace.CountryName' is not defined.
C:\...\UpdateServiceReference\Reference.vb
...where UpdateServiceReference is the client side proxy.
Public Interface IUpdateService
[...]
<System.ServiceModel.OperationContractAttribute(Action:="http://...", ReplyAction:="http://.../IUpdateService/GetClientCountriesResponse")> _
Function GetClientCountries(ByVal placeHolder As Boolean) As serverNamespace.CountryName()
[...]
End Interface
This service reference/proxy on the client only imports from system stuff and the server's namespace's entities. My only settings/imports at the top of the compiler-created Reference.vb are:
Option Strict On
Option Explicit On
Imports System
Imports System.Runtime.Serialization
But here is the really strange (well, confusing) part. In order to clear out the generated errors in the Error List:
Type 'serverNamespace.CountryName' is not defined. Change 'serverNamespace.CountryName' to
'Global.serverNamespace.CountryName'.
I need to do as the compiler suggests above, and change (in Reference.vb) any line with something like this:
Function GetClientCountries(ByVal placeHolder As Boolean) As serverNamespace.CountryName()
...to...
Function GetClientCountries(ByVal placeHolder As Boolean) As Global.serverNamespace.CountryName()
---at EVERY place in both class body & interface... And everything works!
How can I decorate my Web Service to just make it work?
I've already tried using all kinds of "Imports" in the WS code, but nothing has any effect... And just stupidly adding a Global prefix to the existing WS code won't compile...

Errors running Google API calendar example for vb.net

When I try to run this example in VBExpress 2010, I get the following intellisense errors.
scopes.Add(CalendarService.Scopes.Calendar.GetStringValue())
This line generates:
Error 7 Overload resolution failed because no accessible
'GetStringValue' is most specific for these arguments:
Extension method 'Public Function GetStringValue() As String' defined in 'Google.Apis.Util.Utilities': Not most specific.
Extension method 'Public Function GetStringValue() As String' defined in 'Google.Apis.Util.Utilities': Not most specific.
Additionally, these two lines each generate a "not defined" error.
Dim credentials As FullClientCredentials = promptingClientCredentials.EnsureFullClientCredentials()
Dim initializer As New BaseClientService.Initializer()
Error 9 Type 'BaseClientService.Initializer' is not defined.
Error 8 Type 'FullClientCredentials' is not defined.
Finally, this line:
Dim state As IAuthorizationState = AuthorizationMgr.GetCachedRefreshToken(STORAGE, KEY)
generates the error:
Error 15 'AuthorizationMgr' is not declared. It may be inaccessible
due to its protection level.
As to the first error, both google.apis.silverlight.google.apis.util.utilities and google.apis.google.apis.util.utilities has a GetStringValue(system.enum) as String method.
Any ideas about any of these errors?
UPDATE: Excluding Silverlight dll seems to resolve first error ("Not most specific")
We just published a new sample using VB.NET and OAuth2.
It works in VS Professional 2012. Take a look - http://samples.google-api-dotnet-client.googlecode.com/hg/Calendar.VB.ConsoleApp/README.html