Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

System.InvalidCastException problem

Status
Not open for further replies.

klunde

IS-IT--Management
Dec 15, 2004
63
SE
Hi

I have a C# program that I haven't written my self, but I have it running on a server here. Now I've opened the source on my computer (and upgraded the project without error to VS 2008). Then I've changed two small lines in the code and re-compiled it (again without error). But when I run the new exe file on my server I get the following error:

(System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'ADBInterfaceDLL.ArticleDataBase'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{81B80D72-77C9-4C70-A7C2-20A80BDB83BC}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

The file ADBInterfaceDLL is located in my project and is only 4096 bytes large. I have the same version on my computer as on the server.

Any idea why I get this error?

</Morten>
 
Is the com-dll properly registered on your machine? It seems that you only have the com interop dll, but the actual com-dll is not yet registered.
 
No it wasn't. I finally found the component under COM+ applications on my server. I exported it and installed it into COM+ on my dev. machine. Then I removed the components (adbinterfacedll and adodb.dll) from my project and added them again from the COM page on the references in VS.

Now my new problem is that when re-compiling it now uses interop.adodb.dll instead of adodb.dll as it used to. This again gives me a new error message:

System.Runtime.InteropServices.COMException (0x800A0BBC): Write to file failed.
at ADBInterfaceDLL._ArticleDataBase.GetData(Int32& lngExtKey, String& strSupplierName, String& strArticleFormat, Recordset& rsRecordset, String& strErrorMessage)
at WebClip2.PDFWorker.DownloadPDF(Int64 ArticleID, String FileName) in C:\Data\Source\WebClip\WebClip.2.3.0.5\PDFWorker.cs:line 59\n)

And I can't really see why. I haven't changed the code part here.


</Morten>
 
It looks like its able to consume the COM object now, but you're getting what seems to be an i/o exception, like a write permission or file integrity problem. you must have missed something else required by your project, check the com's docs if any.
 
If only there where some docs....

Here is the code part where I get the error. I can't really understand why I get a "write to file" error when I'm actually trying to read data.

Code:
try 
{
	ADBInterfaceDLL.ArticleDataBase ADB = (ADBInterfaceDLL.ArticleDataBase)obj;
	ADODB.Recordset RS = new ADODB.RecordsetClass();
	ADODB.Stream st = new ADODB.StreamClass();
				
	string sSupplierName = "Native";
	string sArticleFormat = "PDF_WholeArticle";
	int lIdentifier =  Convert.ToInt32(ArticleID);
	string sDestination = FileName;

//The next line is #59 and the one that failes according to the error message
	ADB.GetData(ref lIdentifier, ref sSupplierName, ref sArticleFormat, ref RS, ref sErrorMessage);
	if(sErrorMessage != "" && sErrorMessage !="Default")
		return sErrorMessage;

	st.Type = ADODB.StreamTypeEnum.adTypeBinary;
	st.Open(Type.Missing, ADODB.ConnectModeEnum.adModeUnknown, ADODB.StreamOpenOptionsEnum.adOpenStreamUnspecified, "", "");

	st.Write(RS.Fields[0].Value);

	st.SaveToFile(sDestination, ADODB.SaveOptionsEnum.adSaveCreateOverWrite);
} 
catch (Exception ex) 
{
	ExceptionManager.Publish( ex );
	return ex + @"\n" + sErrorMessage;
} 
return "OK";

</Morten>
 
Additional info:

On the server I'm running this program on I have the older compiled version of the program. This version works ok. There is no write to file errors or anything with that one, but if I start the one I have compiled I get this error.

</Morten>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top