Warning 1684 CA2214 : Microsoft.Usage : 'RandomShade..ctor(Int32, Int32, Int32, Int32, Int32)' conta

S

steve bull

RandomShade..ctor(Int32, Int32, Int32, Int32, Int32)
RandomShade.SetRandomShade(Int32, Int32, Int32, Int32, Int32):Void
ColorRange.PickColor():Color C:\Development\Graphics2D\RandomShade.cs 124 Graphics2DWarning 1684 CA2214 :
Microsoft.Usage : 'RandomShade..ctor(Int32, Int32, Int32, Int32, Int32)' contains a call chain that results in a call to a virtual
method defined by the class. Review the following call stack for unintended consequences:

RandomShade..ctor(Int32, Int32, Int32, Int32, Int32)
RandomShade.SetRandomShade(Int32, Int32, Int32, Int32, Int32):Void
ColorRange.PickColor():Color C:\Development\Graphics2D\RandomShade.cs 124 Graphics2DWarning 1684 CA2214 :
Microsoft.Usage : 'RandomShade..ctor(Int32, Int32, Int32, Int32, Int32)' contains a call chain that res
Date: Wed, 06 Jul 2005 23:09:05 -0400
Message-ID: <[email protected]>
X-Agent-Group: microsoft.public.dotnet.languages.csharp
X-Agent-Format: 1 1 0 1 1 630000 0 0 1 0 "*" 0


When I try to build the following code in VS Beta 2 :

public RandomShade
(
int alphaMin, // Lower limit for alpha channel component of color
int alphaMax, // Lower limit for alpha channel component of color
int red, // Lower limit of red component of random color
int green, // Lower limit of green component of random color
int blue // Lower limit of blue component of random color
)
{
this.TrueRandom = true;
SetRandomShade(alphaMin,
alphaMax,
red,
green,
blue);

}


I get the following morning :

Warning 1684 CA2214 : Microsoft.Usage : 'RandomShade..ctor(Int32, Int32, Int32, Int32, Int32)' contains a call chain that results
in a call to a virtual method defined by the class. Review the following call stack for unintended consequences:

RandomShade..ctor(Int32, Int32, Int32, Int32, Int32)
RandomShade.SetRandomShade(Int32, Int32, Int32, Int32, Int32):Void
ColorRange.PickColor():Color C:\Development\Graphics2D\RandomShade.cs 124 Graphics2D



I get a lot of warnings just like this but I have no idea what is wrong. THe alpha and color ranges are validated.

Sorry if is the wrong place to post,

Thanks,

Steve
 
C

cody

This is no error but just a compiler warning. You shouldn't call virtual
methods from a constructor.

steve bull said:
RandomShade..ctor(Int32, Int32, Int32, Int32, Int32)
RandomShade.SetRandomShade(Int32, Int32, Int32, Int32, Int32):Void
ColorRange.PickColor():Color C:\Development\Graphics2D\RandomShade.cs 124
Graphics2DWarning 1684 CA2214 :
Microsoft.Usage : 'RandomShade..ctor(Int32, Int32, Int32, Int32, Int32)'
contains a call chain that results in a call to a virtual
method defined by the class. Review the following call stack for unintended consequences:

RandomShade..ctor(Int32, Int32, Int32, Int32, Int32)
RandomShade.SetRandomShade(Int32, Int32, Int32, Int32, Int32):Void
ColorRange.PickColor():Color C:\Development\Graphics2D\RandomShade.cs 124
Graphics2DWarning 1684 CA2214 :
Microsoft.Usage : 'RandomShade..ctor(Int32, Int32, Int32, Int32, Int32)' contains a call chain that res
Date: Wed, 06 Jul 2005 23:09:05 -0400
Message-ID: <[email protected]>
X-Agent-Group: microsoft.public.dotnet.languages.csharp
X-Agent-Format: 1 1 0 1 1 630000 0 0 1 0 "*" 0


When I try to build the following code in VS Beta 2 :

public RandomShade
(
int alphaMin, // Lower limit for alpha channel component of color
int alphaMax, // Lower limit for alpha channel component of color
int red, // Lower limit of red component of random color
int green, // Lower limit of green component of random color
int blue // Lower limit of blue component of random color
)
{
this.TrueRandom = true;
SetRandomShade(alphaMin,
alphaMax,
red,
green,
blue);

}


I get the following morning :

Warning 1684 CA2214 : Microsoft.Usage : 'RandomShade..ctor(Int32, Int32,
Int32, Int32, Int32)' contains a call chain that results
in a call to a virtual method defined by the class. Review the following
call stack for unintended consequences:
RandomShade..ctor(Int32, Int32, Int32, Int32, Int32)
RandomShade.SetRandomShade(Int32, Int32, Int32, Int32, Int32):Void
ColorRange.PickColor():Color C:\Development\Graphics2D\RandomShade.cs 124 Graphics2D



I get a lot of warnings just like this but I have no idea what is wrong.
THe alpha and color ranges are validated.
 
S

steve bull

I realize it is just a warning - but why is it not a good idea to call virtual functions from a constructor. Could it have
consequences I don't realize?

Sorry, but I am pretty new to C# and I was trying to use the Code Analysis feature to help me figure out if I was doing anything
wrong in my code.


Thanks for your help

Steve
 
C

cody

If you have class B that inherits from class A and you call a virtual method
from A's constructor and the method was overridden by B then you are
effectively calling a method from class B before its constructor in run.
Remember that a constructor first calls the contructor of the base class.


steve bull said:
I realize it is just a warning - but why is it not a good idea to call
virtual functions from a constructor. Could it have
consequences I don't realize?

Sorry, but I am pretty new to C# and I was trying to use the Code Analysis
feature to help me figure out if I was doing anything
 
S

steve bull

Thanks. I see why now.


Steve



If you have class B that inherits from class A and you call a virtual method
from A's constructor and the method was overridden by B then you are
effectively calling a method from class B before its constructor in run.
Remember that a constructor first calls the contructor of the base class.



virtual functions from a constructor. Could it have
feature to help me figure out if I was doing anything
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top