webForumDet fria alternativet

Windows service kompileras med varningar

.NET

3 svar · 1 230 visningar · startad av ironhead

Medlem sedan mars 20011 346 inlägg
Frågan#1

Hej alla glada människor!

Jag har skrivit en windows service där jag lagt till en "ServiceProcessInstaller" så att jag kan använda "Installutil" för att installera den på servern.

Problemet är att om jag kör "Code Analysis" (VS.NET 2010) så får jag två varningar som ser ut som nedan:

Warning	2	CA2214 : Microsoft.Usage : 'ProjectInstaller.New()' 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: 

ProjectInstaller..ctor()
ProjectInstaller.InitializeComponent():Void
ProjectInstaller.get_ServiceProcessInstaller1():ServiceProcessInstaller

Kan man göra något för att slippa få varningar från denna? Eller ska man bara acceptera detta?

Medlem sedan mars 20011 346 inlägg
#2

Hrmm...Jag hade en refererat en dll som var för v4.0 och kompilerade med v2.0 :-\

Edit:
Nope! Var tydligen det också...
mao Det har inte löst problemet. Var lite snabb där.

Medlem sedan aug. 20003 575 inlägg
#3

Mm, det är som det står, det är inte bra att konstruktorn anropar en virtual metod.
Eller rättare sagt det kan leda till konstigheter om man gör dumma saker i virtualmetoden.

Medlem sedan mars 20011 346 inlägg
#4

Jag körde enligt detta:

The Windows Service requires extra code to be able to be installed onto a Windows machine. 

1. Add a new item to the project of the type Installer Class. Name this class ProjectInstaller.vb.
2. Add System.ServiceProcess.ServiceInstaller and System.ServiceProcess.ServiceProcessInstaller.
 
Configure the ServiceInstaller:

Under the toolbox section Visual Basic PowerPacks, drag a ServiceInstaller into the 
ProjectInstaller.vb design window. 
Right-click on it and select Properties.
Verify that the Parent property is set to ProjectInstaller.
Change the Service Name property to what you want the service to be called within the 
list of services in Windows.
Change the StartType property using the drop-down to Automatic.

Configure the ServiceProcessInstaller:

Under the toolbox section Visual Basic PowerPacks, drag a ServiceProcessInstaller 
into the ProjectInstaller.vb design window. 
Right-click on it and select Properties.
Change the Parent property to ProjectInstaller.
Change the Account property to LocalSystem.

You can now use the InstallUtil.exe program to install your Windows Service.

Sen direkt när jag körde "Code Analysis", fick jag ovanstående fel.

260 ms totalt · 4 externa anrop · v20260731065814-full.6fe65c25
122 ms — deklarationer (db)
0 ms — hämta statistik (cache)
135 ms — hämta tråd, inlägg och bilagor (db)
120 ms — ändringar (db)