WMI events not firing.

Topics: Enterprise Library Core
Jun 28, 2007 at 10:09 PM
Hi. I'm trying to fire WMI events from my instrumented app, which uses EntLib 2.0. The code that is failing is:

if (WmiEnabled)
{
ManagementInstrumentation.Fire(new TagGenerationFailedEvent(instanceName, e.ErrorMessage, Convert.ToString(e.Exception)));
}

The error that appears is:

The code generated for the instrumented assembly failed to compile.

...at System.Management.Instrumentation.InstrumentedAssembly..ctor(Assembly assembly, SchemaNaming naming)

There errors appear on my WinXP SP2 box running the .NET Framework 2.0. Any help is greatly appreciated. Thanks!
Jun 29, 2007 at 8:09 PM
Hi Byron,

Some additional information is necessary to assist you with your problem.
  • Is this a build error or a runtime error?
  • What does your new event look like? What are its public properties, and which class does it inherit from?
  • Which WMI namespace did you use for the assembly through the Instrumented attribute?
  • What is the output of running installutil with your assembly (assuming it does build)?

Thanks,
Fernando
Jul 1, 2007 at 9:58 PM
Fernando,

Thank you for the reply. Here are answers to your questions:

  • Is this a build error or a runtime error?
The error is a runtime error.

  • What does your new event look like? What are its public properties, and which class does it inherit from?
Here's my new event:

using System;
using System.Runtime.Serialization;

namespace ADC.TagGeneration.Instrumentation
{
/// <summary>
/// Captures information about tag generation failure for WMI.
/// </summary>

Serializable
class TagGenerationFailedEvent : TagGenerationEvent
{
private string errorMessage;
private string exceptionMessage;

/// <summary>
/// Initializes a new instance of the <see cref="TagGenerationFailedEvent"/> class.
/// </summary>
/// <param name="instanceName">Name of the <see cref="TagGenerationEvent"/> instance the failure ocurred in.</param>
/// <param name="errorMessage">The message that represents the exception thrown when the configuration error was detected.</param>
/// <param name="exceptionMessage">The exception type.</param>
public TagGenerationFailedEvent(string instanceName, string errorMessage, string exceptionMessage)
: base(instanceName)
{
this.errorMessage = errorMessage;
this.exceptionMessage = exceptionMessage;
}

/// <summary>
/// Gets the message that represents the exception thrown when the configuration error was detected.
/// </summary>
public string ErrorMessage
{
get { return errorMessage; }
}

/// <summary>
/// Gets the exception thrown when the configuration error was detected.
/// </summary>
public string ExceptionMessage
{
get { return exceptionMessage; }
}
}
}


  • Which WMI namespace did you use for the assembly through the Instrumented attribute?
I didn't specify a WMI namespace. It should be something like: "assembly: Instrumented("Root/Default")", right? Where should I put this?

  • What is the output of running installutil with your assembly (assuming it does build)?
Here's the output of my installutil:

Microsoft (R) .NET Framework Installation utility Version 2.0.50727.42
Copyright (c) Microsoft Corporation. All rights reserved.


Running a transacted installation.

Beginning the Install phase of the installation.
See the contents of the log file for the C:\Documents and Settings\bking\My Documents\Visual Studio 2005\Projects\WPPTestHarness\WebAppHarness\bin\Web
AppHarness.dll assembly's progress.
The file is located at C:\Documents and Settings\bking\My Documents\Visual Studio 2005\Projects\WPPTestHarness\WebAppHarness\bin\WebAppHarness.Install
Log.
Installing assembly 'C:\Documents and Settings\bking\My Documents\Visual Studio 2005\Projects\WPPTestHarness\WebAppHarness\bin\WebAppHarness.dll'.
Affected parameters are:
logtoconsole =
assemblypath = C:\Documents and Settings\bking\My Documents\Visual Studio 2005\Projects\WPPTestHarness\WebAppHarness\bin\WebAppHarness.dll
logfile = C:\Documents and Settings\bking\My Documents\Visual Studio 2005\Projects\WPPTestHarness\WebAppHarness\bin\WebAppHarness.InstallLog
No public installers with the RunInstallerAttribute.Yes attribute could be found in the C:\Documents and Settings\bking\My Documents\Visual Studio 200
5\Projects\WPPTestHarness\WebAppHarness\bin\WebAppHarness.dll assembly.

The Install phase completed successfully, and the Commit phase is beginning.
See the contents of the log file for the C:\Documents and Settings\bking\My Documents\Visual Studio 2005\Projects\WPPTestHarness\WebAppHarness\bin\Web
AppHarness.dll assembly's progress.
The file is located at C:\Documents and Settings\bking\My Documents\Visual Studio 2005\Projects\WPPTestHarness\WebAppHarness\bin\WebAppHarness.Install
Log.
Committing assembly 'C:\Documents and Settings\bking\My Documents\Visual Studio 2005\Projects\WPPTestHarness\WebAppHarness\bin\WebAppHarness.dll'.
Affected parameters are:
logtoconsole =
assemblypath = C:\Documents and Settings\bking\My Documents\Visual Studio 2005\Projects\WPPTestHarness\WebAppHarness\bin\WebAppHarness.dll
logfile = C:\Documents and Settings\bking\My Documents\Visual Studio 2005\Projects\WPPTestHarness\WebAppHarness\bin\WebAppHarness.InstallLog
No public installers with the RunInstallerAttribute.Yes attribute could be found in the C:\Documents and Settings\bking\My Documents\Visual Studio 200
5\Projects\WPPTestHarness\WebAppHarness\bin\WebAppHarness.dll assembly.
Remove InstallState file because there are no installers.

The Commit phase completed successfully.

The transacted install has completed.

I hope this isn't too much too look at. I REALLY appreciate the help.

Jul 2, 2007 at 2:21 PM
Hi Byron,

Your class should be public.
About the Instrumented attribute, you should add it to the AssemblyInfo.cs file. You can take a look at the AssemblyInfo.cs files from the Enterprise Library source for samples.

Hope this helps,
Fernando


Serializable
class TagGenerationFailedEvent : TagGenerationEvent
{

Jul 10, 2007 at 2:10 PM
Fernando,

I found the correct attribute to go into the AssemblyInfo.cs file and added an installer class to each of my instrumented projects in the solution:

RunInstaller(true)
public class WmiSchemaInstaller : DefaultManagementProjectInstaller
{
/// <summary>
/// Represents the installer for the instrumentation events. Not intended for direct use.
/// </summary>
public WmiSchemaInstaller()
{
Installers.Add(new ReflectionInstaller<PerformanceCounterInstallerBuilder>());
}
}

Now, when I run installutil over one of my assemblies, I get the following error:

An exception occurred during the Install phase.
System.ArgumentException: The member 'Exception' has a declaration that is not supported. Use the IgnoreMember attribute.
Parameter name: Exception

Any ideas?

Regards,

byronfromwes92
Jul 10, 2007 at 6:11 PM
Hi Byron,

This is not the same event class you posted before, isn't it? It looks like you have a public property of type Exception, and that type is not a valid type for the CLI -> WMI mapping (you can learn more about this from http://msdn2.microsoft.com/en-us/library/aa719697(VS.71).aspx). You can either ignore the offending property using the suggested IgnoreMember attribute or just remove it. You can see EntLib's events don't have properties with exceptions themselves, but have properties with the exception messages.

Regards,
Fernando
Jul 10, 2007 at 8:44 PM

Fernando,

Sorry - I used another class; I didn't realize until too late that it was different.

Your info is spot-on, as usual. I did two things: used the IgnoreMember attribute in some classes and changed to exception message strings in others.

I'm one step further, but I'm having yet another problem. When I test my app on Windows XP SP2, I can fire the WMI events and see then from the WMI Event Viewer. When I attempt the same thing on Server 2003 SP1, the event does not fire and I see the following in the wbemess.log file:

(Tue Jul 10 16:30:35 2007.1752708250) : ESS unable to load consumer provider EventViewerConsumer from provider subsystem: 0x80041013
(Tue Jul 10 16:30:35 2007.1752708250) : Failed the first attempt to retrieve the sink to deliver an event to event consumer EventViewerConsumer="WPP Tag Generation Events" with error code 80041013.
WMI will reload and retry.
(Tue Jul 10 16:30:35 2007.1752708281) : ESS unable to load consumer provider EventViewerConsumer from provider subsystem: 0x80041013
(Tue Jul 10 16:30:35 2007.1752708281) : Failed the second attempt to deliver an event to event consumer EventViewerConsumer="WPP Tag Generation Events" with error code 80041013.
This event is dropped for this consumer.
(Tue Jul 10 16:30:35 2007.1752708281) : Dropping event destined for event consumer EventViewerConsumer="WPP Tag Generation Events" in namespace //./ROOT/webPublisherPortal

Any ideas what this is? Thanks.

fsimonazzi wrote:
Hi Byron,

This is not the same event class you posted before, isn't it? It looks like you have a public property of type Exception, and that type is not a valid type for the CLI -> WMI mapping (you can learn more about this from http://msdn2.microsoft.com/en-us/library/aa719697(VS.71).aspx). You can either ignore the offending property using the suggested IgnoreMember attribute or just remove it. You can see EntLib's events don't have properties with exceptions themselves, but have properties with the exception messages.

Regards,
Fernando

Jul 10, 2007 at 9:20 PM
Hi Byron,

I have not seen this message before. Do other WMI events (like EntLib's) work in that server? I'm not sure this is related to entlib at all.
Do you get an exception in your app?

Regards,
Fernando
Jul 12, 2007 at 6:23 PM
Fernando,

Thanks for the reply. I am not seeing any errors in my app. The line of code that fires the event is executed, but nothing seems to happen. What I discovered is that even though these errors appear in the wbemess.log file, I can pick up the events in MOM. Getting the events in MOM was the primary goal, so I can live with "error-like" log messages.

The last issue I'm dealing with is the message I observer when I run InstallUtil over an assembly:

No public installers with the RunInstallerAttribute.Yes attribute could be found in the...

I don't get this message with every assembly I have, but I haven't figured out how to get around it.

Cheers,

byronfromwes92


fsimonazzi wrote:
Hi Byron,

I have not seen this message before. Do other WMI events (like EntLib's) work in that server? I'm not sure this is related to entlib at all.
Do you get an exception in your app?

Regards,
Fernando

Jul 12, 2007 at 6:32 PM
Hi Byron,

The message you get from installutil is the expected behavior for assemblies that don't have installers with the required attribute, and which very likely do not require installing. You shouldn't need to run installutil on those assemblies; the batch file to install EntLib's assemblies only runs installutil on the ones with installers.

Fernando
Jul 12, 2007 at 7:13 PM
Fernando,

I'm not sure I understand what you mean. I am running InstallUtil over instrumented assemblies that should have the required attribute. Could I be wrong there? I'm doing something like this:

Z:\>installutil "C:\development\Web Publisher Portal\Advertising.Web\bin\Debug\Advertising.Web.dll"
Microsoft (R) .NET Framework Installation utility Version 2.0.50727.42
Copyright (c) Microsoft Corporation. All rights reserved.


Running a transacted installation.

Beginning the Install phase of the installation.
See the contents of the log file for the C:\development\Web Publisher Portal\Advertising.Web\bin\Debug\Advertising.Web.dll assembly's progress.
The file is located at C:\development\Web Publisher Portal\Advertising.Web\bin\Debug\Advertising.Web.InstallLog.
Installing assembly 'C:\development\Web Publisher Portal\Advertising.Web\bin\Debug\Advertising.Web.dll'.
Affected parameters are:
logtoconsole =
assemblypath = C:\development\Web Publisher Portal\Advertising.Web\bin\Debug\Advertising.Web.dll
logfile = C:\development\Web Publisher Portal\Advertising.Web\bin\Debug\Advertising.Web.InstallLog
No public installers with the RunInstallerAttribute.Yes attribute could be found in the C:\development\Web Publisher Portal\Advertising.Web\bin\Debug\Advertising.Web
.dll assembly.

The Install phase completed successfully, and the Commit phase is beginning.
See the contents of the log file for the C:\development\Web Publisher Portal\Advertising.Web\bin\Debug\Advertising.Web.dll assembly's progress.
The file is located at C:\development\Web Publisher Portal\Advertising.Web\bin\Debug\Advertising.Web.InstallLog.
Committing assembly 'C:\development\Web Publisher Portal\Advertising.Web\bin\Debug\Advertising.Web.dll'.
Affected parameters are:
logtoconsole =
assemblypath = C:\development\Web Publisher Portal\Advertising.Web\bin\Debug\Advertising.Web.dll
logfile = C:\development\Web Publisher Portal\Advertising.Web\bin\Debug\Advertising.Web.InstallLog
No public installers with the RunInstallerAttribute.Yes attribute could be found in the C:\development\Web Publisher Portal\Advertising.Web\bin\Debug\Advertising.Web
.dll assembly.
Remove InstallState file because there are no installers.

The Commit phase completed successfully.

The transacted install has completed.

When I run the same command over other assemblies, I get output like:

Z:\>installutil "C:\development\Web Publisher Portal\Advertising.Web.PublisherPortal.Security\bin\Debug\Advertising.Web.PublisherPortal.Security.dll"
Microsoft (R) .NET Framework Installation utility Version 2.0.50727.42
Copyright (c) Microsoft Corporation. All rights reserved.


Running a transacted installation.

Beginning the Install phase of the installation.
See the contents of the log file for the C:\development\Web Publisher Portal\Advertising.Web.PublisherPortal.Security\bin\Debug\Advertising.Web.PublisherPortal.Secur
ity.dll assembly's progress.
The file is located at C:\development\Web Publisher Portal\Advertising.Web.PublisherPortal.Security\bin\Debug\Advertising.Web.PublisherPortal.Security.InstallLog.
Installing assembly 'C:\development\Web Publisher Portal\Advertising.Web.PublisherPortal.Security\bin\Debug\Advertising.Web.PublisherPortal.Security.dll'.
Affected parameters are:
logtoconsole =
assemblypath = C:\development\Web Publisher Portal\Advertising.Web.PublisherPortal.Security\bin\Debug\Advertising.Web.PublisherPortal.Security.dll
logfile = C:\development\Web Publisher Portal\Advertising.Web.PublisherPortal.Security\bin\Debug\Advertising.Web.PublisherPortal.Security.InstallLog
Installing WMI Schema: Started
Registering assembly: Advertising.Web.PublisherPortal.SecuritySN_Version_1.0.510.4942
Ensuring that namespace exists: root\MicrosoftWmiNet
Ensuring that class exists: root\MicrosoftWmiNet:WMINET_Instrumentation
Ensuring that class exists: root\MicrosoftWmiNet:WMINET_InstrumentedNamespaces
Ensuring that class exists: root\MicrosoftWmiNet:WMINET_Naming
Ensuring that namespace exists: root\webPublisherPortal
Ensuring that class exists: root\webPublisherPortal:WMINET_Instrumentation
Ensuring that class exists: root\webPublisherPortal:WMINET_InstrumentedAssembly
Ensuring that class exists: root\webPublisherPortal:MSFT_DecoupledProvider
Ensuring that class exists: root\webPublisherPortal:WMINET_ManagedAssemblyProvider
Installing WMI Schema: Finished

The Install phase completed successfully, and the Commit phase is beginning.
See the contents of the log file for the C:\development\Web Publisher Portal\Advertising.Web.PublisherPortal.Security\bin\Debug\Advertising.Web.PublisherPortal.Secur
ity.dll assembly's progress.
The file is located at C:\development\Web Publisher Portal\Advertising.Web.PublisherPortal.Security\bin\Debug\Advertising.Web.PublisherPortal.Security.InstallLog.
Committing assembly 'C:\development\Web Publisher Portal\Advertising.Web.PublisherPortal.Security\bin\Debug\Advertising.Web.PublisherPortal.Security.dll'.
Affected parameters are:
logtoconsole =
assemblypath = C:\development\Web Publisher Portal\Advertising.Web.PublisherPortal.Security\bin\Debug\Advertising.Web.PublisherPortal.Security.dll
logfile = C:\development\Web Publisher Portal\Advertising.Web.PublisherPortal.Security\bin\Debug\Advertising.Web.PublisherPortal.Security.InstallLog

The Commit phase completed successfully.

The transacted install has completed.
Jul 12, 2007 at 7:40 PM
Hi Byron,

InstallUtil.exe will scan the assembly looking for public classes that inherit from class System.Configuration.Install.Installer and have the RunInstaller attribute on them. The Instrumented attribute is used by a specific installer, the ManagementInstaller, to determine which WMI namespace to use.
You can get further information about installutil from http://msdn2.microsoft.com/en-us/library/50614e95(vs.80).aspx.

In your case, the failing assemblies do not have such a public installer class with the RunInstaller attribute, so you need to add one. If you're only dealing with WMI classes, adding a class that inherits from System.Management.Instrumentation.DefaultManagementProjectInstaller and has the RunInstaller attribute should be enough.

Regards,
Fernando
Jul 12, 2007 at 9:48 PM
Fernando,

That's great information. My public installer class looks like this:

/// <summary>
/// Installer to register the WMI class and event in the WMI repository when the assembly
/// is first loaded.
/// </summary>
RunInstaller(true)
public partial class WmiSchemaInstaller : DefaultManagementProjectInstaller
{
/// <summary>
/// Represents the installer for the instrumentation events. Not intended for direct use.
/// </summary>
public WmiSchemaInstaller()
{
InitializeComponent();
Installers.Add(new ReflectionInstaller<PerformanceCounterInstallerBuilder>());
}
}

I have one for each instrumented project in the solution. I can run InstallUtil over some of my assemblies and they work beautifully with MOM. For others, I get a message like the following :

The code generated for the instrumented assembly failed to compile

This exception pops up when I attempt to fire an event:

if (WmiEnabled)
System.Management.Instrumentation.Instrumentation.Fire(new AuthenticationFailedEvent(instanceName, e.ErrorMessage, e.Exception));

Thanks again for all the help.
Jul 12, 2007 at 11:32 PM
Byron,

If I understand this right now all your instrumented assemblies can be successfully installed, and you get this error at runtime. This looks like the same error that originated this thread; could it originated by the same cause?

Regards,
Fernando
Jul 13, 2007 at 2:45 AM
Fernando,

You are correct in that the error is not new. Unfortunately, I do not remember if I ever came up with a solution for that error, other than creating the installer class. I slightly deeper look at the exception reveals:

" at System.Management.Instrumentation.InstrumentedAssembly..ctor(Assembly assembly, SchemaNaming naming)\r\n at System.Management.Instrumentation.Instrumentation.Initialize(Assembly assembly)\r\n at System.Management.Instrumentation.Instrumentation.GetInstrumentedAssembly(Assembly assembly)\r\n at System.Management.Instrumentation.Instrumentation.Fire(Object eventData)\r\n at ADC.Web.Instrumentation.WPPInstrumentationListener.AccountUpdateFailedEventHandler(Object sender, WPPEventArgs e) in C:\\development\\Web Publisher Portal\\Advertising.Web\\Instrumentation\\WPPInstrumentationListener.cs:line 105\r\n at ADC.Web.Instrumentation.WPPInstrumentationProvider.FireAccountUpdateFailedEvent(String errorMessage, Exception exception) in C:\\development\\Web Publisher Portal\\Advertising.Web\\Instrumentation\\WPPInstrumentationProvider.cs:line 119\r\n at ADC.Web.Instrumentation.WPPInstrumentation.FireAccountUpdateFailedInstrumentedEvent(AccountManagementException wppccountException) in C:\\development\\Web Publisher Portal\\Advertising.Web\\Instrumentation\\WPPInstrumentation.cs:line 30\r\n at WindowsAppHarness.Form1.ThrowInstrumentationException() in C:\\Documents and Settings\\bking\\My Documents\\Visual Studio 2005\\Projects\\WPPTestHarness\\WindowsAppHarness\\Form1.cs:line 76\r\n at WindowsAppHarness.Form1..ctor() in C:\\Documents and Settings\\bking\\My Documents\\Visual Studio 2005\\Projects\\WPPTestHarness\\WindowsAppHarness\\Form1.cs:line 54\r\n at WindowsAppHarness.Program.Main() in C:\\Documents and Settings\\bking\\My Documents\\Visual Studio 2005\\Projects\\WPPTestHarness\\WindowsAppHarness\\Program.cs:line 17\r\n at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)\r\n at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)\r\n at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()\r\n at System.Threading.ThreadHelper.ThreadStart_Context(Object state)\r\n at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)\r\n at System.Threading.ThreadHelper.ThreadStart()"

I got around the problem somehow, but I have no idea how. Thanks again.
Jul 13, 2007 at 1:49 PM

byronfromwes92 wrote:
Fernando,

You are correct in that the error is not new. Unfortunately, I do not remember if I ever came up with a solution for that error, other than creating the installer class.



Wasn't the problem solved by making your WMI event classes public?

Fernando
Jul 13, 2007 at 3:15 PM
Fernando,

Unfortunately, changing the accessibility of the WMI event classes to public did not solve the problem. :-(

Regards,

Byron