I have the error "System.Runtime.InteropServices.SEHException Additional Information External Component has thrown an Exception.
The Problem occurs when I try To instantiate an object which is contained in the header file that came with the 3rd party .dll I am using. The header for the file looks like this:
#ifdef QUANTUM_EXPORTS
#define QUANTUM_API __declspec(dllexport)
#else
#define
QUANTUM_API __declspec(dllimport)#endif
///////////////////////////////////////////////////////////////////////////////////////////////////
class CQUANTUM{
public
:QUANTUM_API CQUANTUM(
void);QUANTUM_API ~CQUANTUM(
void);QUANTUM_API bool SetDataPath(int MNum);
.........................
And In my code I call CQUANTUM QuantumObj; The error occurs, however this error only occurs when I turn on the /clr tag.
I have tried to use
catch
(System::InteropServices::SEHException *ex){
System::Exception *e;
e = ex->GetBaseException();
}
but I find that e is the same as ex;
Anyone got any idea why the external DLL is not working in managed code or why I cannot get the base error it is throwing
thanks,
Jen

SEHException from External Component Error
Andrea43086
One way you get this exception is if unmanaged code does an win32 RaiseException() or causes a fault. If that exception is propagated up the stack to managed code, it will map to a managed Structured Exception Handler(SEH). For example, STATUS_NO_MEMORY maps to OutOfMemoryException and STATUS_ACCESS_VIOLATION maps to NullReferenceException.
For all the exception codes that don’t have a predefined mapping, will be wrapped into System.Runtime.InteropServices.SEHException. The SEHException class also responds to the HRESULT E_FAIL, which has the value 0x80004005 (Unknown error). In my experience E_FAIL is usually thrown for some security reason, but this is not a rule.
Check the ErrorCode field of the SEHException for the actual HRESULT thrown. See http://msdn2.microsoft.com/en-us/library/9ztbc5s1(VS.80).aspx for a HRESULT to Managed Exception map.
If the InnerException property is null on any exception, the GetBaseException method will always return the current exception. The ErrorCode is your best bet to find out whats wrong. But an E_FAIL or 0x80004005 is usually of not much help. Try calling the COM component from unmanaged code (VB/VC/VBScript).
janekw
Any Ideas
Am I using the correct method to get the Exception that the DLL may have thrown
jen
Yashraj
-2147467259 base10 = 0x80004005 base16. == Unknown error/E_FAIL.
// Store integer -2147467259
int decValue = -2147467259;
// Convert integer -2147467259 as a hex in a string variable
string hexValue = decValue.ToString("X");
// Convert the hex string back to the number
int decAgain = int.Parse(hexValue, System.Globalization.NumberStyles.HexNumber);
Ah.. the hex values arent listed for each HRESULT. Maybe this would help.
AccessException
COR_E_MEMBERACCESS (0x8013151A)
AmbiguousMatchException
COR_E_AMBIGUOUSMATCH (0X80138000211D)
appdomainUnloadedException
MSEE_E_APPDOMAINUNLOADED (0x80131015)
ApplicationException
COR_E_APPLICATION (0x80131600)
ArgumentException
COR_E_ARGUMENT (0x80070057 )
ArgumentNullException
E_POINTER (0x80004003)
ArgumentOutOfRangeException
COR_E_ARGUMENTOUTOFRANGE (0x80131502)
ArithmeticException
COR_E_ARITHMETIC (0x80070216)
ArrayTypeMismatchException
COR_E_ARRAYTYPEMISMATCH (0x80131503)
BadImageFormatException
COR_E_BADIMAGEFORMAT (0x8007000B)
CannotUnloadappdomainException
COR_E_CANNOTUNLOADAPPDOMAIN (0x80131015)
COMException
Any other hrESULT defaults to this .Net Exception
ContextMarshalException
COR_E_CONTEXTMARSHAL (0x80090020)
CryptographicException
NTE_FAIL (0x80004001)
CryptographicUnexpectedOperationException
CORSEC_E_CRYPTO_UNEX_OPER (0x80131431)
CustomAttributeFormatException
COR_E_FORMAT (0x80131537)
DirectoryNotFoundException
COR_E_DIRECTORYNOTFOUND (0x80070003) STG_E_PATHNOTFOUND (0x80030003)
DivideByZeroException
COR_E_DIVIDEBYZERO (0x80020012)
DllNotFoundException
COR_E_DLLNOTFOUND (0x80131524)
DuplicateWaitObjectException
COR_E_DUPLICATEWAITOBJECT (0x80131529)
EndOfStreamException
COR_E_ENDOFSTREAM (0x801338)
EntryPointNotFoundException
COR_E_TYPELOAD (0x80131522)
Exception
COR_E_EXCEPTION (0x80131500)
ExecutionEngineException
COR_E_EXECUTIONENGINE (0x80131506)
ExternalException
E_FAIL (0x80004005)
FieldAccessException
COR_E_FIELDACCESS (0x80131507)
FileLoadException
COR_E_FILELOAD (0x80131621 or 0x80131018)
FileNotFoundException
COR_E_FILENOTFOUND (0x80070002)
FormatException
COR_E_FORMAT (0x80131537)
IndexOutOfRangeException
COR_E_INDEXOUTOFRANGE (0x80131508)
InvalidCastException
COR_E_INVALIDCAST (0x80004002)
InvalidComObjectException
COR_E_INVALIDCOMOBJECT (0x80131527)
InvalidFilterCriteriaException
COR_E_INVALIDFILTERCRITERIA (0x80131601)
InvalidOleVariantTypeException
COR_E_INVALIDOLEVARIANTTYPE (0x80131531)
InvalidOperationException
COR_E_INVALIDOPERATION (0x80131509)
InvalidProgramException
COR_E_INVALIDPROGRAM (0x8013153A)
IOException
COR_E_IO (0x80131620)
IsolatedStorageException
ISS_E_ISOSTORE (0x80131450)
MarshalDirectiveException
COR_E_MARSHALDIRECTIVE (0x80131535)
MethodAccessException
COR_E_METHODACCESS (0x80131510)
MissingFieldException
COR_E_MISSINGFIELD (0x80131511)
MissingManifestResourceException
COR_E_MISSINGMANIFESTRESOURCE (0x80131532)
MissingMemberException
COR_E_MISSINGMEMBER (0x80131512)
MissingMethodException
COR_E_MISSINGMETHOD (0x80131513)
MulticastNotSupportedException
COR_E_MULTICASTNOTSUPPORTED (0x80131514)
NotFiniteNumberException
COR_E_NOTFINITENUMBER (0x80131528)
NotImplementedException
E_NOTIMPL (0x80004001)
NotSupportedException
COR_E_NOTSUPPORTED (0x80131515)
NullReferenceException
COR_E_NULLREFERENCE (0x80004003)
OutOfMemoryException
COR_E_OUTOFMEMORY (0x8007000E)
OverflowException
COR_E_OVERFLOW (0x80131516)
PathTooLongException
COR_E_PATHTOOLONG (0x8013206)
PlatformNotSupportedException
COR_E_PLATFORMNOTSUPPORTED (0x80131539)
PolicyException
CORSEC_E_POLICY_EXCEPTION
RankException
COR_E_RANK (0x80131517)
ReflectionTypeLoadException
COR_E_REFLECTIONTYPELOAD (0x80131602)
RemotingException
COR_E_REMOTING (0x8013150B)
RemotingTimeoutException
COR_E_REMOTING (0x8013150B)
SafeArrayTypeMismatchException
COR_E_SAFEARRAYTYPEMISMATCH (0x80131533)
SafeArrayRankMismatchException
COR_E_SAFEARRAYRANKMISMATCH (0x80131538)
SecurityException
COR_E_SECURITY (0x8013150A)
SEHException
E_FAIL (0x80004005)
SerializationException
COR_E_SERIALIZATION (0x8013150C)
ServerException
COR_E_SERVER (0x8013150E)
StackOverflowException
COR_E_STACKOVERFLOW (0x800703E9)
SUDSGeneratorException
COR_E_EXCEPTION (0x80131500)
SUDSParserException
COR_E_EXCEPTION (0x80131500)
SynchronizationLockException
COR_E_SYNCHRONIZATIONLOCK (0x80131518)
SystemException
COR_E_SYSTEM (0x80131501)
TargetException
COR_E_TARGET
TargetInvocationException
COR_E_TARGETINVOCATION (0x80131604)
TargetParameterCountException
COR_E_TARGETPARAMCOUNT (0x80138002)
ThreadAbortException
COR_E_THREADABORTED (0x80131530)
ThreadInterruptedException
COR_E_THREADINTERRUPTED (0x80131519)
ThreadStateException
COR_E_THREADSTATE (0x80131520)
ThreadStopException
COR_E_THREADSTOP
TypeInitializationException
COR_E_TYPEINITIALIZATION (0x80131534)
TypeLoadException
COR_E_TYPELOAD (0x80131522)
TypeUnloadedException
COR_E_TYPEUNLOADED (0x80131013)
UnauthorizedAccessException
COR_E_UNAUTHORIZEDACCESS (0x80070005)
VerificationException
COR_E_VERIFICATION
WeakReferenceException
COR_E_WEAKREFERENCE
Eric Tsai
A managed Form application that calls an unmanaged dll.
The First Function is the one that that 2003 generated the second is the one 2005 generated
JohnRM2
Jenny,
Are you writing a managed application or unmanged application
Bùi Duy Hiếu
I Haven't managed to figure out what the problem was but I replaced the entry into the program:
int
APIENTRY _tWinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)with:
int main(array<System::String ^> ^args)
and now no SEHException is thrown.
Only Problem now is that I can't get the hInstance to pass to my program
stanfordholden
The ErrorCode for The Exception is comming out as -2147467259 which doesn't seem to be right.
I do not see how I am supposed to make this map.
jen