Hej! Har postat varianter av detta inlägg (nedan) på www.asp.net och msdn.microsoft.com utan att få några svar. Gör ett försök här igen. Vore intressant med någon form av respons, förstår till exempel någon vad mitt problem är eller ska jag beskriva det mer? Kanske detta kan hjälpa dig lite? Tack för svaret. Tyvärr så hjälpte det mig inte. Min klass ärver från ISupportErrorInfo och implementerar InterfaceSupportsErrorInfo. COM objektet kastar exception med funktionen Error("Min felsträng"). Så som jag uppfattat det ska detta räcka för att .NET ska wrappa HRESULT exceptions till .NET exceptions. Nytt försök - Exception interop issue
Mycket tacksam för svar... /Marcus
---------------------------------------------------------------------------------
I try to use a component (written in C++ and throws HRESULTS) as a regular class in .NET. I have added the component as a COM reference and everything works just fine. Except one thing. The exceptions. When the component throws an exception the message property of the exception object sais "Exception occured" when it should say "My own exception info thrown from COM+ object". But when I create a object in the old way it works.
This works:
Try
Dim obj
obj = CreateObject("myCOM.Component.1")
obj.Functionthatthrows("parameters")
Catch ex As Exception
ex.Message ' Tells me: My own exception info thrown from COM+ object
This doesn't works:
Try
Dim obj As myCOM.IComponent
obj = New myCOM.ComponentClass
obj.Functionthatthrows("parameters")
Catch ex As Exception
ex.Message ' Tells me: Exception occured
I've also tried to do the same thing in C# code but with the same result. Why doesn't .NET wrap my HRESULTS with the extended error info? What have I missed?
Would be grateful for any help!!!
/Marcus Sv: Nytt försök - Exception interop issue
To retrieve extended error information, the managed client must examine the fields of the exception object that was generated. For the exception object to provide useful information about an error, the COM object must implement the IErrorInfo interface. The runtime uses the information provided by IErrorInfo to initialize the exception object.
If the COM object does not support IErrorInfo, the runtime initializes an exception object with default values.
When the runtime encounters an unfamiliar HRESULT (an HRESULT that lacks a specific, corresponding exception), it throws an instance of the COMException class.
/Fredrik NSv: Nytt försök - Exception interop issue
Fler tips mottages tacksamt!!! /Marcus