I wish to use LogParser.DLL
assembly, so I test it over normal console application, it worked, then I put it into a server, send to win 2003 for testing(i have no more free space to install services like database), ...
it always returned FileNotFoundException Error in eventViewer logs...
I tried to use stack trace to see what really happen, and I see the DLL does not import at all, afte some searching at Google I find an answer in this web site, which told to use .Net command prompt, and then use import assembly command, if I'm write it was tblimp "file name" /out "new file"
I made my assembly, it was .net 4 so I went to my older VS, and done same to provide a .net 2.0.x compatible DLL, I use it and it worked, but...
New Error Apeared:
Error Msg: Retrieving the COM class factory for component with CLSID {8CFEBA94-3FC2-45CA-B9A5-9EDACF704F66} failed due to the following error: 80040154. StackTrace: at FileEventReaderService.EventReader.ReadEventsAndStoreInDatabase(String startDate, String endDate)
ILogRecordset rs = null;
try
{
((DebugLogger) _logProviderDebugMode).Log("T1-2", "Debug-EventReaderClass",
EventLogEntryType.Information);
LogQueryClass qry = new LogQueryClass();
COMEventLogInputContextClass eventLogFormat = new COMEventLogInputContextClassClass();
((DebugLogger) _logProviderDebugMode).Log("T1-3", "Debug-EventReaderClass",
EventLogEntryType.Information);
string query = "select * from security WHERE TimeGenerated >= '" + startDate +
"' and TimeGenerated <'" + endDate +
"' and (eventid=560 or eventid=540)";
rs = qry.Execute(query, eventLogFormat);
((DebugLogger) _logProviderDebugMode).Log("T1-4", "Debug-EventReaderClass",
EventLogEntryType.Information);
for (; !rs.atEnd(); rs.moveNext())
{
//Processes
}
}
catch(Exception ex)
{
((DebugLogger)_logProviderDebugMode).Log(
"T1-5\nError Msg: " + ex.Message + "\nStackTrace: " + ex.StackTrace
, "Debug-EventReaderClass",
EventLogEntryType.Error);
}
finally
{
((DebugLogger)_logProviderDebugMode).Log("T1-6", "Debug-EventReaderClass",
EventLogEntryType.Information);
if (rs != null)
rs.close();
}
I tried to catch the exception and see if any data is imported, but it seem rs return nothing, also without the if(rs!=null) in "finally" block again it's it self an error which mean rs is null
Event Type: Information Event Source: EventLoggerService Event Category: None Event ID: 0 Date: 8/5/2012 Time: 2:47:20 AM User: N/A Computer: HF-SERVER-PC Description: Debug-EventReaderClass: T1-2
Class Variable Information:
---------------------------
_logProvider: FileEventReaderService.Services.Logger.EventLogger
_logProviderDebugMode: FileEventReaderService.Services.Logger.DebugLogger
_licenceState: OK
_dataBase: deadManN
_interval: 5
_timeGap: 1
_previousReadTime: 8/5/2012 2:40:19 AM
_lastReadTime: 8/5/2012 2:46:20 AM
_parserLock: System.Object
_subtleTime: TimerLib.SubtleTime
_parserService: FileEventReaderService.Services.Util.ParserService5
_connectionStringBuilder: FileEventReaderService.Services.Util.ConnectionStringBuilder
_lastTime: 18
_minutes: 18
For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.
the above log, is last log I did before the error, and then it show the log which is logged in "catch" block, so error can be here:
LogQueryClass qry = new LogQueryClass();
COMEventLogInputContextClass eventLogFormat = new COMEventLogInputContextClassClass();
so I again start searching for my error msg, and found some things which I was not able to handle alone,
for example, I see some one said to you need to register the DLL manually or using dllregisterservice or things about putting application to be compile only for 86X CPU type, but I don't wanna do this... cause I don't write this for single user with known hardware and software...
How do I deal with the DLL registering while setup application or any thing else which may help about the matter? of Interop.MSUtil.dll
library?
It's so important for me, and still there's too much of time I need, about months after this to just check for logical bugs, not compile ones
I was about to write a service application and I completed some of it. I encountered the bugs we talked about in question and also comments. Its been some time that has passed, so I can't tell you every thing that happened, but I'll give you the answer which put me out of this:
First thing first, I needed to work through DLL and my own application not some one else application and not running for example log parser with hidden command and with the query as argument through diagosing process...
so I take the DLL,
the DLL alone worked in win application which I provide for test, in the O/S vs was in it, it may was for certificate reason.. but it didn't worked in my other server OS, ... also inside the service application it come up with a log which told me I have an I/O: FileNotFoundException so I put try catch block and then print the stack trace, the exception told me that once assembly is missing... so I start to search and find that I should import DLL in kinda way, So Step 1:
logparser.dll
file in a reachable place like c:\temp\
tlbimp "c:\temp\logparser.dll" /out:"c:\temp\Interop.MSUtil.dll"
Interop.MSUtil.dll
is the assembly name that application looking for, but you cant directly rename logparser.dll
to itlogparser.dll
to Interop.MSUtil.dll
(it's becasue name spaces are different)till here I fixed some error, but it's not like service work successfully, new error appeared while running log parser, and caused that class instances return Nulls,.. the error is here:
Error Msg: Retrieving the COM class factory for component with CLSID {8CFEBA94-3FC2-45CA-B9A5-9EDACF704F66} failed due to the following error: 80040154. StackTrace: at FileEventReaderService.EventReader.ReadEventsAndStoreInDatabase(String startDate, String endDate)
This Step may Cause nothing, but since I experience changes in error msg I put it here
since I wanted to package my application for many users, it wasn't like I tell all of them to run commands, so I searched even more, some people said about registering the DLL, but you can't put logparser.dll
in the global assembly catch folder of setup, also later I find out that the registration we do is different than putting assembly in GAC...
also I find out if we want put a DLL into GAC first we can't put logparser cause it exported, but the Introp.MSUtil.dll
also the setup returned error for putting Interop.MSUtil.dll
in the GAC folder
The error was about assembly naming, and after some search I find out that the error is for something different, and it happen where assembly is not signed with a pair key...
you can create pair key through cmd, each OS you install have a random key that it generate, and also you can export and import these keys for special certificate matter, naturally these commands have their network engineering user, but we software also use it here... So Step 2:
Read this section if you experience 8007007E / 8007007F errors... they are naturally for the reason of registration of assembly and I don't know but maybe also the shared key which DLL is signed with also one more thing you can perform before doing these is test regsvr32 "[dll file address]" which register a DLL, and if application doesn't directly use and search for DLL you can put it in any folder before registering for example in our project we point to
Introp.MSUtil.dll
notlogparser.dll
though we also need it for registration, and then we run regsvr32 command onlogparser.dll
(this command is just for testing, and have no use in setup and deploying your application, also you can use /u switch to unregister the DLL for further testing)
sn -k [file name]
it create the file in the address you are insidetlbimp "[logparser.dll address]" /out:"[address]\Interop.MSUtil.dll" /pr imary /keyfile:"[pair key file address]"
there was also error exist... so i find out that GAC (Global Assembly Catch) wont work alone, and after fixed all bug, i noticed that i can, but i don't need to put Interop.MSUtil.dll in GAC folder of my setup... but this registering matter, the regsvr32, was it the problem? ah yes, it was, though I hear this is same to putting assembly into GAC, but it wasn't right, the registration of DLL as Global Assembly was different than using regsvr32 to register it... if you want to know your DLL is already registered, i think you need to now the namespace or the main assembly inside of it, so you can go through following step to see if it is registered:
ok, let back to the subject, we need to register the DLL, and it cause some errors which I don't remember... cause classes dont work well and return nulls
if you register logparser.dll
using the command and it worked, for packaging your setup you need to do following things So Step 3:
logparser.dll
assembly (which setup know it as file not assembly)
in the reachable folder, like Application Folder of your setup project..._vsdrfCOMSelfReg_
from the list, notice that some option like this one is not provided for some assembly like the one we create (Introp.MSUtil.dll
) so we cant register it, you also cant register that DLL with regsvr32... other option wont register the DLL as I testPS: notice that the logparser.dll and the Interop.MSUtil.dll wont detect by project automatically, and you have to add them manually to your Setup and MSI project... you also need both DLL as I explained
With many thanks to @Andrii Kalytiiuk