Last Reviewed: September 20, 2007
Article: DTS0197
Applies to: dtSearch Engine 6.40 and later
One of these errors occurs running an application that uses the dtSearch Engine's .NET API:
An unhandled exception of type 'System.IO.FileNotFoundException' occurred in [program name]
Additional information: File or assembly name dtSearchNetApi, or one of its dependencies, was not found
Unhandled Exception: 'System.TypeInitializationException': The type initializer for 'ApiInitializer' throw an exception. ---> System.IO.FileNotFoundException: dten600.dll.
This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem.
dtSearchNetApi.dll (or dtSearchNetApi2.dll in .NET 2.0) depends on dten600.dll. When you add a reference to dtSearchNetApi.dll in your project, Visual Studio may copy dtSearchNetApi.dll to the project folder. However, dten600.dll is not copied, and because dtSearchNetApi.dll is not in the same folder as dten600.dll, Windows may not be able to resolve the dependency on dten600.dll.
To fix the problem, do one of the following:
(1) If you have dtSearch version 7.1 or later, register dten600.dll using this command (see note below):
regsvr32 dten600.dll
dtSearchNetApi.dll does not use the COM type library that regsvr32 registers, but it uses the registry entry created by regsvr32 to determine where dten600.dll is located, which provides a simple way to ensure that dten600.dll can always be located.
(2) Copy dten600.dll to the folder where dtSearchNetAPI.dll is located. Note: In ASP.NET applications, this will not work because ASP.NET copies the application to a temporary folder to execute, and the dten600.dll file gets left behind in this process, so copying dten600.dll into the BIN folder for your application does not solve the problem. For applications other than ASP.NET applications, this is the recommended solution because it ensures that your application will run with the exact dten600.dll version that you include with the application.
(3) Copy dten600.dll to a folder that is listed on the system PATH, such as the c:\windows folder.
(4) Add the folder where dten600.dll is located to the system PATH (see "How to change the system PATH" below for instructions).
If the problem continues to occur, you may also be missing one or more of the Microsoft runtime library DLLs. For dtSearchNetApi.dll, msvcr71.dll is required.
For dtSearchNetApi2.dll the MFC 8.0 and CRT 8.0 merge modules are required. To install these components, you can use the Microsoft installers linked below. You can also use the redistributable vcredist_x86.exe included with Visual Studio .NET 2005.
Microsoft components
for 32-bit Windows versions (SP1):
http://www.microsoft.com/downloads/details.aspx?FamilyID=200b2fd9-ae1a-4a14-984d-389c36f85647&displaylang=en
Microsoft components for 64-bit Windows versions (SP1):
http://www.microsoft.com/downloads/details.aspx?FamilyID=eb4ebe2d-33c0-4a47-9dd4-b9a6d7bd44da&DisplayLang=en
"An attempt was made to load a program with an incorrect format" means that you are trying to load a DLL that is mismatched with the platform. Specifically, there is a 32-bit vs. 64-bit issue.
Under 64-bit platforms, .NET can try to load dtSearchNetApi2.dll as a 64-bit component instead of a 32-bit component.
dtSearchNetApi2.dll and dten600.dll are 32-bit components, so they cannot be loaded in a 64-bit process. Unfortunately, an assembly built in .NET will run by default as 64-bit under a 64-bit OS. Therefore, when you build your assembly to run in 64-bit Windows, you need to set some flags in the .exe to let .NET know to run the assembly as 32-bit and not 64-bit. (Alternatively, you can reference the 64-bit version of the dtSearch .NET API, in C:\Program Files\dtSearch Developer\bin64\dtSearchNetApi2.dll.)
One way to do this is to use corflags.exe (a utility included with the .NET SDK) to set ILONLY- and 32BIT+ on your assembly.
For documentation on working with corflags, see:
CorFlags Conversion Tool
http://msdn2.microsoft.com/en-us/library/ms164699(VS.80).aspx
Setting options in the IDE is not sufficient to make a .NET executable that must run in 32-bit mode. (Selecting 32-bit instead of AnyCPU in the target drop-down will not change all of the flags that must be changed to force 32-bit execution.)
For ASP.NET applications, this article explains how to configure 64-bit IIS to run 32-bit processes:
If the ASP.NET application is called as a 32-bit process, ASP.NET should build it as a 32-bit executable, and then dten600.dll and dtSearchNetApi2.dll will load correctly.
This error occurs intermittently running an application that uses the dtSearch Engine's .NET API:
Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: Access is denied: 'dtSearchNetAPI'.
Resolution
This can occur when a program that scans folders automatically prevents ASP.NET from having exclusive access to the Temporary ASP.NET Files folder. The problem affects .NET components generally and is not particular to dtSearch.
Examples of types of programs that can cause this error include: automatic content indexing by software such as Microsoft Index Server, on-access virus scanners, and backup software. For more information, see:
http://support.microsoft.com/default.aspx?scid=kb;en-us;329065
To prevent the problem from affecting dtSearch and other .NET applications, the Temporary ASP.NET Files folder should be excluded from content indexing and backup. Depending on the anti-virus software used, it may also be necessary to disable on-access virus scanning in this folder as well, but this should not be done unless the problem continues after disabling content indexing and backup.
This can occur if you use SearchJob.ExecuteInThread or IndexJob.ExecuteInThread in an ASP.NET application, because ASP.NET does not recognize that the newly-created thread is part of the same AppDomain as the main application.
The .NET API in dtSearch 7.1 and later use the ASP.NET thread pool to implement ExecuteInThread, so upgrading to version 7.1 or later should make this error disappear.
However, we still do not recommend using ExecuteInThread in ASP.NET applications. ExecuteInThread was added for VB6 developers who had previously developed applications using the dtSearch Engine's COM interface, which had an IndexJob.ExecuteInThread method. For developers using the old COM interface, ExecuteInThread provided a way to provide some basic benefits of multi-threading, such as a responsive GUI in Windows applications, while still using VB6.
In a .NET application that runs as a service, there is no benefit at all to using ExecuteInThread instead of Execute. Execute gives you the ability to monitor progress through the IIndexStatusHandler interface (see: http://support.dtsearch.com/webhelp/dtSearchNetApi/dtSearch.Engine.IIndexStatusHandler.html), or ISearchStatusHandler without the overhead of thread polling.
Another use of ExecuteInThread that can cause problems is to call ExecuteInThread and to assume that the .NET runtime will allow the thread to complete and clean it up when it is done. In fact, the .NET runtime will simply terminate a background thread in some cases. According to the MSDN documentation:
A managed thread is either a background thread or a foreground thread. Background threads are identical to foreground threads with one exception: a background thread will not keep the managed execution environment alive. Once all foreground threads have been stopped in a managed process (where the .exe file is a managed assembly), the system stops all background threads and shuts down.
--Foreground and Background Threads, .NET Framework Developer's Guide
See also:
The PATH is a list of folder names that Windows uses to locate executables. The following steps will add the dtSearch program folder to the system PATH.
(1) Click Start > Settings > Control Panel
(2) Click System
(3) Click the Advanced tab.
(4) Click the Environment Variables button
(5) Under System variables, locate the "Path" variable and click on it
(6) Click the Edit button
(7) Add this to the end of the current value (assuming you installed dtSearch to the default location):
;c:\Program Files\dtSearch Developer\bin
The semicolon is needed to separate the dtSearch directory name from the last item listed in the existing PATH.
A reboot may be necessary for some programs to recognize the change to the PATH.
For more information on Windows environment variables, see:
How To Manage Environment Variables in Windows XP
http://support.microsoft.com/default.aspx?scid=kb;en-us;310519&sd=tech