.net - FxCop Giving A Warning On Private Constructor CA1823 And CA1053?
Jun 8, 2012
I have a class that looks like the following:
Public Class Utilities
Public Shared Function blah(userCode As String) As String
'doing some stuff
End Function
End Class
I'm running FxCop 10 on it and it says:"Because type 'Utilities' contains only 'static' Shared' in Visual Basic) members, add a default private constructor to prevent the compiler from adding a default public constructor."
On one side, in Vb.Net when you add an event handler to an object the created method is named: <NameOfTheObject>_<NameOfTheMethod>.As I like to have consistent syntax I always follow this rule when creating event handlers by hand.On the other side when I create private variables I prefix them with m_ as this is a common thing used by the community, in C# people use to put _ at the beginning of a variable but this is no CLS compliant.
> Function LoginPass() As Boolean > Dim LogPass As New waxClass > Dim Ldt As DataTable = LogPass.LoginPass(LCase(UserName_TextBox.Text), > LCase(UserPass_TextBox.Text))
[Code]...
When I try to use the above function it gives a Warning saying:
Function 'LoginPass' doesn't return a value on all code paths. Are you missing a 'Return' statement?
I am trying to write some unit tests on a class that looks like this, using Moq [code] the parameterized constructor is private or internal one of the two methods relies on the result of the other.I want to check that when GetThisOrThat is called with a value, it actually calls GetThis. But I also want to mock GetThis so that it returns a specific well-known value.To me this is an example of Partial Mocking, where we create a Mock based on a class, passing the parameters for the constructor. The problem here is that there is no public constructor, and therefore, Moq can not call it..I tried using the Accessors generated by Visual Studio for MSTest, and use those accessors for the mocking, and this is what I came up with [code]
I don't know if this has been asked before, but we're having a discussion about it today at my job. Should private variables (that are shared/static) be instantiated when they are dimensioned/defined, or is it a better practice to do this inside of a constructor?
Public Class IpCam Private Const HOST As String = "http://test.com/url/example" Private Shared _Example As New OurClass(HOST)which one to use?
comparing C# code and VB.NET and the results between the seemingly identical code were entirely different.(Why C# is always winning over VB.NET?)The explanation given is that C# will initialize the class fields, then call the base constructor, but VB.NET does the exact opposite. Is there a technical reason for the languages to be different? At first glance, it seems that either approach is equally valid, but I can't fathom why they wouldn't have selected the SAME approach.
EDIT: As 'Jeffrey L Whitledge' has pointed out, VB6 did not have inheritance, so I don't think we can say 'to keep VB.NET and VB6 more closely related'.
Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim example1 As New ExampleClass[code]......
I have an abstract class which requires a delegate to function. I pass the delegate into the constructor. Now that I have a non default constructor I need to call the abstract class's constructors from the concrete class which means that I need to use MyBase.New(...). I have included a quick example below.
Public MustInherit Class BaseClass Public Delegate Sub WorkMethod() Private _Work As WorkMethod
[code]....
I have tried to do this but I keep getting the following error: "Implicit reference to object under construction is not valid when calling another constructor".Can I not do what I am trying to do above? I initially had the delegate setup in its own setter method. But then I am creating a deceptive API because it does require a point to a method to work properly.
what's the rationale behind this limitation: Constructor call is valid only as the first statement in an instance constructor i want to pass an argument to my constructor which validates this argument and calls mybase.new according to this argument but it doesn't let me
example:
Public Class prob Inherits System.ApplicationException Public Sub New(ByVal problem As String, ByRef inner_exception As Exception)
I have been looking at a few of our VB.NET dll's using FxCop and all of the errors relate to DLL setup (i.e. Strong Names, Culture Info) and the case of Variables methods. Looking at a few examples of FxCop examining a C# Dll, it appears to offer a lot more potential errors.
Does this mean that FxCop is more valuable on C# developments that VB.NET or have I just chosen bad examples.
I thought it was the case that FxCop worked on IL rather than the specific languages, so am I just missing rules files for VB.NET or are there more available for C#?
I'm starting a new project; trying to be more strict than previous ones. I've set warnings as errors in the build I've added FxCop to PostBuild. The one last thing on my list os require people to add inline docs for all classes/non-private methods/properties.
For example:Public Event CurrentChanged As EventHandler(Of CurrentChangedEventArgs(Of T))Shows the message "Do not nest generic types in member signatures." on CurrentChangedEvent, which is the variable that holds the delegate for the event, and VB generates it automagically.How do I suppress the rule for the item?
if for example i have two private sub I declared a local variable on private sub a... is there a way that private sub b could use the variable created on private sub a? Im asking because im in a problem in my app were using global variable is not an option to make the long story short
Is there any way to disable a specific warning. For example, in one of my classes are re-implement System.ICloneable.Clone. After doing so I now get a warning that states, "'System.ICloneable.Clone' from 'implements System.ICloneable' is already implemented by the base class 'XXX'. Re-implementation of function assumed." Is there any way to remove this warning from the Error List
explain me the difference between them? I'm new to visual basic, and I need to know the very basic things in Visual Basic allowing me to become a professional User
I'm using express edition and I am creating a direct IP connector for a game. I have figured out how to do this in the command console by going to the path of the exe e.g cd desktopgamehd2.exe -cmd -join The Ip Here -port Port Here Now I have used the command;
Code: Dim returnValue As Process returnValue = Process.Start(readValue)
to launch the game.(The readvalue is a string that reads the location from the games registry entry)Is there anything I can add on to use the direct IP conect command or is a whole diferent piece of code all together?
how do i set a default value in a recordset? i want the value in row 1 to be taken as the default, how do i do this? i have this error:
Error 1 Class 'System.Data.DataTable' cannot be indexed because it has no default property. C:Documents and Settingsmiller_aDesktopFront End FCOMOctobaseOctobasefrmFrontEnd.vb 41 25 Octobase
refering to this line of code:
booIFP_KG = Availability("KG_IFP") 'booIFP_KG is a checkbox in the datatable availability and kg_ifp is another datatable.
If you're not living on the edge, you're taking up too much room.
I'm compiling a VB.Net 2.0 app (created in VS2008) using msbuild, and now I've added a generic return type, it's giving me the following:
Warning: Type library exporter encountered a generic type instance in a signature. Generic code may not be exported to COM.
Having just spent ages removing all of the previous warnings, I don't really want to add a new one. Any idea how to get rid of it (aside from not using generics)?I don't know what details I'd put in the attribute, or what number to put in the project-level ignore list.
I have an app with a timer control, and the interval is set to 60000ms (1 min). so every min i have some event happen. thats pretty simple. however, i want to have a 15 second warning that the event is going to happen. so basically 45 seconds after my timer starts, i want a message such as "15 seconds left until event x happens".
would i have to use 2 timers? i guess im lost on the logic. i know how to use the timer control, but i have been googling all night trying to figure this one out. i have tried using 1 timer set to 45 seconds (for the warning) and another timer at 60 seconds(for the event) but they go out of synch after 1 iteration and will not consistently stay 15 seconds ahead of the other. i dont want to post any code i have, because it is all trash and i want to start over from scratch.
I wanted to know how to encrypt data.And I've found a solution at this web site.This script works if I use it as a function.Nonetheless, Visual Studio throws a warning that says the following.[code]Visual Studio underlines the second line after the equal symbol above.I have no idea what that means.Does anybody have any idea how I can resolve this warning?
I have set up my form using with the languages and I have store the texts in the resource. I have debug the project and everything seen to be fine. I found that there is a folder in the project bin folder. The folder was called zh-chs. I have changed the name from roject1.resources.dll to testdll.dll and moved to the bin folder. I have added reference in my project and I have deleted the zh-chs folder. Suddenly, I have found a warning sage.
Code:Could not resolve this reference. Could not locate the assembly "TESTDLL, Version=1.0.0.0, Culture=zh-CHS, processorArchitecture=MSIL". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get
warnings got me thinking about old issues that always goofed me up when I was writing more VB.NET code.One of them was the fact that the compiler didn't warn if you declared a Function but never did an explicit Return statement or assign to the Function name. Running Visual Studio 2008, I just made a small experimental project, and it seems as though the behavior has never been fixed.I created a Visual Basic Console application, with the following code:
Module MainModule Sub Main() Dim test As Boolean = TestWarning()[code].....
I also went into the Project Settings and turned On Option Strict and Option Explicit.I also set the Warning Configurations so that "Function/Operator with no return value" was set to Error.I compiled the project and got no warning, and no error on the TestWarning() Function. This seems like a great place to put a warning, because it will default to False, and you may have simply forgotten to do a return. C# will error without a return statement. I thought that VB.NET did the same thing with the "Function/Operator with no return value" configuration. Is this a bug, or is there something I'm missing?
Edit: Further Experimentation
Function TestWarning() As Boolean If DateTime.Now.DayOfWeek = DayOfWeek.Monday Then Return False[code].....
If, and nothing in the Else, there is also no Warning/Error. It will simply take the default, even though you likely intended (via programming style) to have an explicit return. In this case, I explicitly returned False (which is the default for Boolean), so it's likely a hidden bug that I should have returned True in the Else.
how do i programmatically change datatable and tableadaper components name property in my dataset.xsd ? this my code:
Partial Class DataSetBimeh Partial Class bimeh1DataTable Private Sub bimeh1DataTable_Initialized(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Initialized
I wrote a small VB6 program to monitor the status of a Shared Network Drive. In this case it's an external hard drive. The drive is used for backup. The program is invoked automatically when the computer is booted and runs minimized.
If the backup drive is not turned on or otherwise not functional then the program changes from minimized to a normal window and displays various statistics and a warning that the backup drive isn't working.
I want to make the warning much more prominent, like minimizing the program that happens to be running or displaying the warning window in front of the progrmam that happens to be running. I want something really noticaeble. The computers don't have speakers so I can't play an warning.wav .
This program is for advertising ads and prices are determined by which radiobutton is selected.This program uses objects created from a class . I am getting a waring message that Variable 'ad' is used before it has been assigned a value. A null reference exception could result at runtime. the warning is at ad.size = 225.So how do I get the variable filled before used if it depends on which radiobutton is checked? [code]