0

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

Stephen Ostermiller
  • 23,933
  • 14
  • 88
  • 109
Hassan Faghihi
  • 1,888
  • 1
  • 37
  • 55
  • Please tell, have you enabled flag **Copy Local** for the reference to LogParser.dll assembly for the service on your server? – Andrii Kalytiiuk Aug 05 '12 at 11:29
  • Copy Local? i didnt see such a thing, also i provide setup, so the installer will setup assembly... – Hassan Faghihi Aug 05 '12 at 16:33
  • BTW, when i press refresh dependency on setup project it doesnt add it automatically, and i do it manualy, the propertiy of the dll, is same to all other dll'ed which working.. – Hassan Faghihi Aug 05 '12 at 16:40
  • http://s10.postimage.org/8b5xle3p5/8_5_2012_9_17_17_PM.png – Hassan Faghihi Aug 05 '12 at 17:01
  • 1
    and i find **Copy Local** , and it was set to true like all other DLL'es – Hassan Faghihi Aug 06 '12 at 00:55
  • I also find a property in the setup project, over property of Interpop.MSUtil.dll assembly, which was named "**Register**" and i also set it in to other type option, which were 1."vsdraCOM" and 2."vsdraCOMRelativePath", But it again didnt work, and i dont know any other kinda registeration for DLL... i also find a warning over assembly which you can see in following image [link](http://s13.postimage.org/mc22shsyf/8_6_2012_5_29_08_AM.png) – Hassan Faghihi Aug 06 '12 at 01:32
  • also i find this blog, the autor talk about things i never hear of, and i dont know how :'( http://jin5.blogspot.com/2010/08/8cfeba94-3fc2-45ca-b9a5-9edacf704f66.html – Hassan Faghihi Aug 06 '12 at 01:33
  • Can it be some sort of CPU arch not matching? i.e. using a x86 assembly in a x64 program (usually set to AnyCPU and causes the problem?) – Alvin Wong Aug 06 '12 at 02:21
  • i have a part that targeted any CPU, but the assembly are in use all targeted 86x CPU, also i run on win server 2003 that is 86X – Hassan Faghihi Aug 06 '12 at 02:28
  • *Configuration resource Provider is set to 86X *File Event Reader Service (Entry Point of Project which point to the Assembly) is set to 86X *File Event Reader UI is set to 86X *Shared Storage was set to any platform, i changed the target to 86X but cant change the platform (there's only "any CPU" option available) in build setting *Time lib -> same to last one, i changed the target now, but platform is any CPU (single option) *Setup Project target platform is 86X too – Hassan Faghihi Aug 06 '12 at 02:37
  • ok, 6 min passed as service was programmed to, and again it failed... do you know about the link i just spread? i mean the registering of the DLL? and also if it can be done will installation of application :-s – Hassan Faghihi Aug 06 '12 at 02:49
  • @deadManN Please tell, have you tried [registering](http://ss64.com/nt/regsvr32.html) *LogParser.dll* manually with **regsvr32** command right after installation on server (with path where it is deployed to) - as described in answer link that you provided? If it helps - you can incorporate registration of *LogParser.dll* into your installer using [custom action](http://msdn.microsoft.com/en-us/library/d9k65z2d.aspx). – Andrii Kalytiiuk Aug 06 '12 at 04:43
  • how actually should i do this? and also is it possible that installer do it? for other users? – Hassan Faghihi Aug 06 '12 at 04:51
  • @deadManN It is possible to incorporate registering of *LogParser.dll* into installer - but at first please perform following actions, to identify that it will resolve problem. Please install your service on the server and then run there following command `regsvr32 LogParser.dll` with **cmd** (Windows *command line* tool) from directory where *LogParser.dll* file is deployed by installer (you can change directory in cmd with `cd C:\SomeDir1\SomeDir2` command - replacing *C:\SomeDir1\SomeDir2* with your path). – Andrii Kalytiiuk Aug 06 '12 at 13:27
  • 1
    I test it, but before i tell you the result let me explain my old related step and then get to the point, before i reach to this error and step, there was a problem with logparser.dll so i searched for it, and i find that i should use tblimp command in dot net framework console, to make new DLL called Interop.MSUtill.dll so the error which told me "the dependency is not exist" fixed... ----So i tried 4 ways: **1**-first i tried with Interop.MSUtil.dll which i was created.. result were: http://s10.postimage.org/97vmullft/Interop_MSUtil_Registering.png – Hassan Faghihi Aug 06 '12 at 23:43
  • 1
    **2**- next i tried using LogParser.dll which from the begining were exist in log parser 2.2 application folder and i just use it without any modification. result were like this: http://s10.postimage.org/q5ungfutl/Logparser_register.png **But** after launching the service i got the old error, when i used logparser with out modifing it to Interop.MSUtil.dll like: http://s14.postimage.org/7pwg77lo1/launch_service_with_log_parser_dll.png ** with this error text**: Error Msg: Could not load file or assembly 'Interop.MSUtil, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its depe – Hassan Faghihi Aug 06 '12 at 23:50
  • 1
    **3**- next i create a Global assembly cache folder in my setup project, as some one today told me this regsvr32 is related to GAC, i got following Error on build time with use of LogParser.dll: http://s18.postimage.org/66gc6yz0p/GAC_logparser.png **4**- and in the end i test Interop.MSUtil.dll with GAC folder in setup project, i again gain an error will building the project... here's the error: http://s9.postimage.org/3mm64aimn/GAC_Interop_MSUtil.png – Hassan Faghihi Aug 06 '12 at 23:58
  • @deadManN It looks like you need to reference *Interop.MSUtil.dll* (generated on target server machine) from your project - according to [this](http://stackoverflow.com/questions/11203245/what-is-interop-msutil-dll/11203698#11203698) answer. – Andrii Kalytiiuk Aug 07 '12 at 05:00
  • it doenst generate on target machine, i generate it on another os, because i have no space to install vs 2005..., then i move it toathis os, and tried to setup it, you say the shared key is a certificate base issue? there was a thing get certificate and put it in a file, cant i do it and then instal in my machine? if you know that? – Hassan Faghihi Aug 07 '12 at 06:19
  • and if you mean a project reference, sure i done it, as visual studio dont allow you to build applciation without adding references – Hassan Faghihi Aug 07 '12 at 06:31
  • man, look at here... i think we can create the key, if shared name is key related, ? i'm not sure any way, but if its it, look at here: http://hostpicturefree.com/images/tlbimp.png – Hassan Faghihi Aug 07 '12 at 06:50
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/14974/discussion-between-andrii-kalytiiuk-and-deadmann) – Andrii Kalytiiuk Aug 07 '12 at 06:52
  • ok, but look at here : http://support.microsoft.com/kb/324168 – Hassan Faghihi Aug 07 '12 at 07:11
  • Man i test it, it success, but not alone, there are other problem **first-** i should add the Introp.MSUtil.dll at any cost **next-** i should have LogParser.dll with me **next-** i have to register LogParser.dll with regsvr32 cause i cant put it in GAC folder of the setup, and putting the Introp.MSUtil wont help (just log parser dll) **next-** give LocalSystem Permission... **---------------------------------------------** Here's nothing matter, but the logparser.dll and the regsvr32 command, i need to do this will setup the application :| how can i do this? – Hassan Faghihi Aug 07 '12 at 10:08
  • 1
    Please consider implementing [custom action](http://msdn.microsoft.com/en-us/library/d9k65z2d.aspx) within your installer project. [This](http://stackoverflow.com/a/3866005/894174) answer describes how you can access target deployment directory from custom action. – Andrii Kalytiiuk Aug 07 '12 at 10:58
  • 1
    man tnx, also sry for late reply cause i was some kinda busy, also tired and need resting, and also beside all this every people need a part of time to have fun, to continue living ;) i saw your way, but already i fixed it... The setup and deployment of VS, know this "LogParser.dll" file not as an asembly if you add it to setup project even as an assembly, and also there's not those register type i taked image from before, there's also 2 more type available for registering, and one of them is "**vsdrfCOMSelfReg**" which is the one that register the dll, i'm – Hassan Faghihi Aug 08 '12 at 23:50
  • continue to last comment --wonder why other types dont do this, BTW that's important that this one do it ;) now if your right the full answer ? do it, then i mark as answer, cause you helped a lot, else i perform this... but please not about all step, like make an asembly using tlbimp on logparser.dll to generate Introp.MSUtil.dll which solve some error, about not existance assembly, next registering logparser.dll assembly which first we performed using regsvr32, and then setup and MSI, which solved the error contain number 80040154, and in the – Hassan Faghihi Aug 08 '12 at 23:57
  • continue to last comment --end solving last error that i dont remmeber it, contained number 7.... And also please note that both assembly should be exist, one to register, and one to use, and the refrence of project should be on Introp.MSUtil.dll – Hassan Faghihi Aug 08 '12 at 23:58

2 Answers2

3

This is an old question but I ran into this error and found the accepted answer somewhat difficult to parse.

Ultimately I had to ensure that LogParser was installed and LogParser.dll was registered on the machine where the code is being run. Else I would receive the error shown in the original question.

From my experience, Interop.MSUtil is not a replacement for LogParser.dll but a facilitator.

It's also worth mentioning that Interop.MSUtil is now available via nuget, but after installation you will have to manually add a reference to the DLL in your solution's packages folder, then right-click the reference and set Embed Interop Types to false.

ejhost
  • 171
  • 12
Wildcat Matt
  • 388
  • 4
  • 13
1

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:

  • see what kinda DLL you need, I mean .net version for example I needed .net 2.x based for more support in older OS, but VS 2010 gived me a .net 4.x based DLL, so I refer to Visual studio 2005 in program file
  • open visual studio folder from all program menu of Start menu, the go to "visual studio tools" folder, and in the end run "visual studio command prompt"
  • next put your logparser.dll file in a reachable place like c:\temp\
  • run this command: tlbimp "c:\temp\logparser.dll" /out:"c:\temp\Interop.MSUtil.dll"
  • Notice the Interop.MSUtil.dll is the assembly name that application looking for, but you cant directly rename logparser.dll to it
  • put this into your project, and switch all references from logparser.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 not logparser.dll though we also need it for registration, and then we run regsvr32 command on logparser.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)

  • create a pair key file using CMD with following command: sn -k [file name] it create the file in the address you are inside
  • next again go to step one, but instead of the old command use this new command which also mix key pair to generate the DLL tlbimp "[logparser.dll address]" /out:"[address]\Interop.MSUtil.dll" /pr imary /keyfile:"[pair key file address]"
  • now use new signed dll instead of the one we create before ... ( Interop.MSUtil.dll )

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:

  • go to start menu and open up "run" tools
  • type dcomcnfg and press "enter" to open Component Service tools
  • lead to this directory: Console Root->Component Services->Computers->My Computer->DCOM Config
  • now for example for seeing if log parser.dll is registered, look for names like "Interop.Msutil" or "MSUtil"
  • if it is exist, the dll is registered, else it's not

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:

  • put logparser.dll assembly (which setup know it as file not assembly) in the reachable folder, like Application Folder of your setup project...
  • right click over the file inside Solution Explorer and select Properties
  • click over register section, and over drop down button to see all the available option...
  • select _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 test

PS: 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

Stephen Ostermiller
  • 23,933
  • 14
  • 88
  • 109
Hassan Faghihi
  • 1,888
  • 1
  • 37
  • 55