Solved

Guid and ServicedComponent not recognized as valid identifiers?

Posted on 2004-04-14
24
408 Views
Last Modified: 2012-08-14
When I compile my code I get these errors:

N:\ClientDevelopment\NEO\BuyersFund\ExchangeEventSinkClassLibrary\AssemblyInfo.cs(31): The type or namespace name 'Guid' could not be found (are you missing a using directive or an assembly reference?)

N:\ClientDevelopment\NEO\BuyersFund\ExchangeEventSinkClassLibrary\ExchEventSink.cs(11): The type or namespace name 'ServicedComponent' could not be found (are you missing a using directive or an assembly reference?)


I am trying to follow the Exchange Server Event Sink tutorial at this location:


http://www.codeproject.com/csharp/CsManagedEventSinksHooks.asp



Here is my current Class Library and AssemblyInfo code:


using System;
using CDO;
using ADODB;


namespace ExchangeEventSinkClassLibrary
{
      /// <summary>
      /// Summary description for Class1.
      /// </summary>
      public class ExchEventSink: ServicedComponent , IExStoreAsyncEvents
      {
            //public string ClassID = "F92EFC3A-FDD8-4225-B0055-13FD3D5D54D1";
            //public string InterfaceId = "704A413F-F8FE-476B-9206-69AB6300D752";
            //public string EventsId = "DCC71BD5-6627-4FBF-BB5A-DB8FEA1EB177";

            public string ClassID = "cf63289d-18d1-43af-ba90-9e41cac93ee6";
            public string InterfaceId = "323733b0-3c0d-47d4-86fa-fd67d651cf81";
            public string EventsId = "3721271c-65f0-441a-91d6-6a86d1c75846";

            public ExchEventSink()
            {
                  //
                  // TODO: Add constructor logic here
                  //

            }

            public void OnSave(IExStoreEventInfo pEventInfo,
                  string bstrURLItem, int lFlags)

            {
                  try
                  {
                        if(System.Convert.ToBoolean(lFlags))
                        {
                              CDO.Message iMessage=new
                                    CDO.MessageClass();
 
                              string sFrom; string sDate;
                              try
                              {
                                    iMessage.DataSource.Open(bstrURLItem,null,
                                          ADODB.ConnectModeEnum.adModeRead,
                                          ADODB.RecordCreateOptionsEnum.adFailIfNotExists,
                                          ADODB.RecordOpenOptionsEnum.adOpenSource,"","");
                                    FileStream fs = new FileStream(
                                          @"c:\temp\MyEventSink.log",FileMode.OpenOrCreate);
                                    fs.Write(Encoding.ASCII.GetBytes(bstrURLItem),0,
                                          bstrURLItem.Length);
                                    sFrom = iMessage.From;
                                    sDate = iMessage.ReceivedTime.ToString();
                                    fs.Write(Encoding.ASCII.GetBytes(sFrom),0,sFrom.Length);
                                    fs.Write(Encoding.ASCII.GetBytes(sDate),0,sDate.Length);
                                    fs.Close();
                              }
                              catch (Exception ex)
                              {
                                    throw (ex);
                              }
                        }
                  }
                  catch (Exception ex)
                  {
                        throw (ex);
                  }
            }
 
            public void OnDelete(IExStoreEventInfo pEventInfo,
                  string bstrURLItem, int lFlags)
            {
                  try
                  { }
                  catch(Exception ex)
                  {throw (ex);}
            }
 

      }
}




And the Assembly code:



using System.Reflection;
using System.Runtime.CompilerServices;
using System.Globalization;

//
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
//
[assembly: AssemblyTitle("MyEventSink")]
[assembly: AssemblyDescription("My Event Sink")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]            

//
// Version information for an assembly consists of the following four values:
//
//      Major Version
//      Minor Version
//      Build Number
//      Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:

[assembly: AssemblyVersion("1.0.*")]
[assembly:  Guid("2a910565-736c-48d3-a9bb-f64afcb70a83")]

//
// In order to sign your assembly you must specify a key to use. Refer to the
// Microsoft .NET Framework documentation for more information on assembly signing.
//
// Use the attributes below to control which key is used for signing.
//
// Notes:
//   (*) If no key is specified, the assembly is not signed.
//   (*) KeyName refers to a key that has been installed in the Crypto Service
//       Provider (CSP) on your machine. KeyFile refers to a file which contains
//       a key.
//   (*) If the KeyFile and the KeyName values are both specified, the
//       following processing occurs:
//       (1) If the KeyName can be found in the CSP, that key is used.
//       (2) If the KeyName does not exist and the KeyFile does exist, the key
//           in the KeyFile is installed into the CSP and used.
//   (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility.
//       When specifying the KeyFile, the location of the KeyFile should be
//       relative to the project output directory which is
//       %Project Directory%\obj\<configuration>. For example, if your KeyFile is
//       located in the project directory, you would specify the AssemblyKeyFile
//       attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]
//   (*) Delay Signing is an advanced option - see the Microsoft .NET Framework
//       documentation for more information on this.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("MyEventSink.key")]
[assembly: AssemblyKeyName("MyEventSink")]
0
Comment
Question by:knowlton
  • 16
  • 8
24 Comments
 
LVL 12

Expert Comment

by:dfiala13
ID: 10829438
Tom,

Believe you need to add

using System;

to the Assembly Code (Guid is a member of System)

and

using System.EnterpriseServices;

to the sink code.
0
 
LVL 5

Author Comment

by:knowlton
ID: 10834110
Guid   does not show up under System when I type:

using System.[Guid is not listed]
0
 
LVL 5

Author Comment

by:knowlton
ID: 10834388
This got rid of the GUID error in AssemblyInfo.cs:

using System.Runtime.InteropServices;
0
 
LVL 5

Author Comment

by:knowlton
ID: 10834639
This link shows what is and is not available as far as namspaces under each OS:

According to the table (about halfway down?)

System.EnterpriseServices.ServicedComponent is available?

http://www.msdnaa.net/content/?ID=2317



Someone please help me make sense of this.
0
 
LVL 12

Expert Comment

by:dfiala13
ID: 10835010
Is available for 2000, XP + 2003,
Not available for NT, 98

>>Guid   does not show up under System when I type:

using System.[Guid is not listed]

It wouldn't.

Guid is a class, not a namespace.  The using declaration at the top of the class just tells it what namespaces to reference.  Guid is a class in the system namespace.

All you needed to add was
using System;
0
 
LVL 5

Author Comment

by:knowlton
ID: 10835343
dfiala13:

Here are my current using clause declarations:

using System;
using System.Runtime.InteropServices;
using System.Xml;
using CDO;
using ADODB;
using System.IO;
using System.Text;


I get the following error:

N:\ClientDevelopment\NEO\BuyersFund\ExchangeEventSinkClassLibrary\ExchEventSink.cs(15): The type or namespace name 'ServicedComponent' could not be found (are you missing a using directive or an assembly reference?)
0
 
LVL 5

Author Comment

by:knowlton
ID: 10835366
0
 
LVL 5

Author Comment

by:knowlton
ID: 10835377
Is it normal for many of the namspaces to not be listed under System?
0
 
LVL 12

Accepted Solution

by:
dfiala13 earned 500 total points
ID: 10835393
I believe so...

Add

using System.EnterpriseServices;

to the top of your sink class

and reference the
System.EnterpriseServices.dll

to your project
0
 
LVL 5

Author Comment

by:knowlton
ID: 10835413
That was it.
0
 
LVL 5

Author Comment

by:knowlton
ID: 10835442
Sorry for making such a big deal out of this, by the way.

I just sort of freaked out when System.EnterpriseServices was referenced in the tutorial I am following....and then it did not show up when I invoked code completion at design time.

I will try and remember in the future that I can just import the missing System.XXX  dll   via Add References!!!!
0
 
LVL 12

Expert Comment

by:dfiala13
ID: 10835467
No worries.  Glad you got it working.  Occassionally VS doesn't make the reference for you, which can be a wee bit maddening.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 5

Author Comment

by:knowlton
ID: 10835506
Agreed.

I am over my head with this "Exchange Event Sink" stuff.

I am sure I will be back in this TA with more questions soon...   :)
0
 
LVL 12

Expert Comment

by:dfiala13
ID: 10835552
The first one is the hardest.  Once you get that one working, you'll never look back.
0
 
LVL 5

Author Comment

by:knowlton
ID: 10835569
LOL.....

Programming is the most fun / scary activity I can think of.
0
 
LVL 12

Expert Comment

by:dfiala13
ID: 10835584
>>Programming is the most fun / scary activity I can think of.
You need to get out more ;)
0
 
LVL 5

Author Comment

by:knowlton
ID: 10835612
Noooooo kidding.  :)


Hey, I know that our exchange server is running on our server called PLATINUM.

Can you tell me how I would get to MY inbox....or the general Exchange inbox?????

What do I search for?
0
 
LVL 12

Expert Comment

by:dfiala13
ID: 10835644
Got me.  I haven't played around with Exchange since the early server crashing releases. There can be a web interface installed, but again, outside my box of knowledge.
0
 
LVL 5

Author Comment

by:knowlton
ID: 10836088
Okay.

Never hurts to ask.  :)
0
 
LVL 12

Expert Comment

by:dfiala13
ID: 10836177
Right on that.  Sorry I couldn't help.
0
 
LVL 5

Author Comment

by:knowlton
ID: 10836191
No worries.
0
 
LVL 5

Author Comment

by:knowlton
ID: 10904797
The tutorial at this link:

http://www.codeproject.com/csharp/CsManagedEventSinksHooks.asp


is very very good......................but it does have some flaws.

1)  You do NOT need to run RegEvent.vbs AT ALL......ignore this suggestion in the tutorial.  Instead, download and install the SDK Tools and run Exchange Explorer instead to register the Event and hook it into the EventSink code.

2)  I recommend using regsvcs /appname:YourAppName <full path to your DLL including extension>      from the command line, instead of using the Component Services GUI to register the COM DLL.  I have to do some further testing to see if the GUI works...but I know for sure the command line route using REGSVCS works well.

3)  After you have registered the COM DLL (your event sink) in Component Services......then go and register the Exchange Store Event using Exchange Explorer.   THEN go back to Component Services....right-click on your App Name and click on START.   This is what actually starts the EventSink (your C# DLL) talking to the Exchange Store.  Until you do this nothing will happen.   This was left out of the tutorial.  A small thing, but an important thing to mention.
0
 
LVL 5

Author Comment

by:knowlton
ID: 11119972
UPDATE:

Well, guess what?

I finally had a major breakthrough on this @!#$^% problem that has been driving me crazy for the last few weeks!!!!!!!


It is a very small change.

Apparently the method   MoveFirst(   ) does not work so well with Exchange.

This was the cause of my COMException:   "Interface not registered" error message this entire time.


The solution is to use    Move(1,0)     instead of MoveFirst(  ).


That's it.   Simple.

This answer came courtesy of Tom Rizzo, an author who was kind enough to correspond with me and help me figure-out finally what the problem was.:

Looking for a good book on programming Exchange, Outlook, ADSI and
SharePoint?  Check out http://www.microsoft.com/MSPress/books/5517.asp

My I also reommend:

.NET and COM: The Complete Interoperability Guide  ISBN:067232170X
http://www.amazon.ca/exec/obidos/ASIN/067232170X/componentsnot-20/701-9386310-4703553
0
 
LVL 5

Author Comment

by:knowlton
ID: 11120294
More on the MoveFirst problem I described:

http://support.microsoft.com/default.aspx?scid=kb;en-us;273791


If you are getting into Event Sinks....I recommend the following tutorial:

http://www.codeproject.com/csharp/CsManagedEventSinksHooks.asp

Make sure and read the article questions and follow-ups at the bottom!

There are a few caveats.  E-mail me at my Profile e-mail address and we can talk about them.  :)
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now