Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Distributed Applications / October 2004

Tip: Looking for answers? Try searching our database.

Prob With Exception Management Application Block

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andy - 11 Oct 2004 14:22 GMT
Hi All,

I'm basically just trying to get started with the Exception Management
Application Block and am having some technical difficulties.  All I
want to do to begin with is create a simple Windows Application (which
I have done and named "ExceptionManagementTester") and within it
create and use a custom publisher.

The Exception Management Tester Solution contains ONE project with
these files:

Reference
App.Config
AssemblyInfo.vb
ExceptionPublisher.vb
Form1.vb
InterfaceDefinitions.vb

The contents of App.Config is shown below:

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

<configSections>
 <section name="exceptionManagement"
type="Microsoft.ApplicationBlocks.ExceptionManagement.ExceptionManagerSectionHandler,Microsoft.ApplicationBlocks.ExceptionManagement"
/>
</configSections>

<exceptionManagement mode="on">
 <publisher assembly="ExceptionManagementTester"
type="ExceptionManagementTester.ExceptionPublisher"
fileName="c:\QuickStartSamplesExceptionLog.txt" />
</exceptionManagement>

</configuration>

References are both made to ExceptionManagement and
ExceptionManagement.Interfaces.  The form has a button on it with code
behind it that just creates an exception.

The problem I have is that when execution reaches the
PublishToCustomPublisher Method with the signature shown below in the
ExceptionManager Class

     Private Shared Sub PublishToCustomPublisher(ByVal exception As
Exception, ByVal additionalInfo As NameValueCollection, ByVal
publisher As PublisherSettings)

it gives me "specified cast is not valid".  Here is the exact line of
code it "blows up"

m_Publisher = CType(Activate(publisher.AssemblyName,
publisher.TypeName), IExceptionPublisher) . . . just after calling the
activate function

Apparently, it's blowing up in trying to convert from type "Object" to
type "IExceptionPublisher" and I don't understand why exactly.

Because I have very little experience with the Exception Management
Application Block I suspect it's something simple.  I'm half wondering
if I can't do this all in ONE project for some reason.

At any rate, if anyone could shed some light on this for me it would
be greatly appreciated.

Thanks,

Andy
Jorge Matos - 20 Oct 2004 21:07 GMT
Andy,

Make sure your custom publisher implements the IExceptionPublisher interface.

> Hi All,
>
[quoted text clipped - 66 lines]
>
> Andy
Andy P - 21 Oct 2004 03:21 GMT
Hi Jorge,

Thanks for responding to my email . . . I thought I was implementing the
IExceptionPublisher Interface.  Here's the code for
ExceptionPublisher.vb

****************************************************

Imports System.Collections.Specialized
Imports System.Xml
Imports System.IO
Imports System.Text

Public Class ExceptionPublisher
   Implements IExceptionPublisher

   Private m_LogName As String = "C:\ErrorLog.txt"
   Private m_OpMail As String = ""

   ' Provide implementation of the IPublishException interface
   ' This contains the single Publish method.
   Sub Publish(ByVal e As Exception, ByVal AdditionalInfo As
NameValueCollection, ByVal ConfigSettings As NameValueCollection)
Implements IExceptionPublisher.Publish
       ' Load Config values if they are provided.
       If Not ConfigSettings Is Nothing Then
           If Not ConfigSettings("fileName") Is Nothing AndAlso
ConfigSettings("fileName").Length > 0 Then
               m_LogName = ConfigSettings("fileName")
           End If
           If Not ConfigSettings("operatorMail") Is Nothing AndAlso
ConfigSettings("operatorMail").Length > 0 Then
               m_OpMail = ConfigSettings("operatorMail")
           End If
           ' Create StringBuilder to maintain publishing information.
           Dim strInfo As StringBuilder = New StringBuilder

           'Record the contents of the AdditionalInfo collection.
           If Not AdditionalInfo Is Nothing Then
               ' Record General information.
               strInfo.AppendFormat("{0}General Information{0}",
Environment.NewLine)
               strInfo.AppendFormat("{0}Additonal Info:",
Environment.NewLine)
               Dim i As String
               For Each i In AdditionalInfo
                   strInfo.AppendFormat("{0}{1}: {2}",
Environment.NewLine, i, AdditionalInfo.Get(i))
               Next

               ' Append the exception text
               strInfo.AppendFormat("{0}{0}Exception
Information{0}{1}", Environment.NewLine, e.ToString())

               ' Write the entry to the log file.
               Dim fs As FileStream = File.Open(m_LogName,
FileMode.Create, FileAccess.ReadWrite)
               Dim sw As New StreamWriter(fs)

               sw.Write(strInfo.ToString())

               sw.Close()
               fs.Close()

               ' send notification email if operatorMail attribute was
provided
               'If m_OpMail.Length > 0 Then
               '    Dim subject As String = "Exception Notification"
               '    Dim body As String = strInfo.ToString()

               '    SmtpMail.Send("CustomPublisher@mycompany.com",
m_OpMail, subject, body)
               'End If

           End If

       End If

   End Sub

End Class

********************************

Your feedback is appreciated . . . Thanks Andy!!!
Jorge Matos - 21 Oct 2004 14:11 GMT
Andy,

You can put all the projects in the same solution - including the EMAB as
well since the source is available.  I suspect that the ExceptionPublisher
might be loading the wrong dll or an incorrect version of your custom
publisher.

I would use the debugger and see exactly what assembly and type the
"Activate()" function is trying to instantiate. Make sure your solution
includes the following projects:

Microsoft.ApplicationBlocks.ExceptionManagement
Microsoft.ApplicationBlocks.ExceptionManagement.Interfaces
YourWindowsProject

HTH
Jorge

> Hi Jorge,
>
[quoted text clipped - 81 lines]
>
> Your feedback is appreciated . . . Thanks Andy!!!
Andy - 22 Oct 2004 02:37 GMT
Hey Jorge,

Thanks again for your feedback . . .

I was actually trying to "cut some corners" with what I was doing so I
scrapped that approach, created another solution, followed your advice
and now everything is working as it should.

Once again I appreciate your help . . .

Thanks so much,

Andy

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.