Reference COM component fails in Visual Studio (ResolveComReference exception)

F

ffhansix

Hi,

I am trying to reference a COM component (.dll) from Visual Studio 2005
in my windows application in C# by adding a reference to a third
party.dll file (tried .type library also), and i get this error from
the compiler when trying to compile the solution.

Does anyone know why this occurs, and how it can be resloved, i would
be very grateful indeed.

Here comes the exception thrown:
------------------------------------------
Error 2 The "ResolveComReference" task failed unexpectedly.
System.SystemException: The type library importer encountered an error
during type verification. Try importing without class members. --->
System.TypeLoadException: Method 'IXorDiscountMatrix_GetName' on type
'XOR5.CXorDiscountMatrixClass' from assembly 'Interop.XOR5,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is overriding a
method that has been overridden.
at System.Reflection.Module.InternalLoadInMemoryTypeByName(String
className)
at
System.Runtime.InteropServices.TypeLibConverter.TypeResolveHandler.ResolveEvent(Object
sender, ResolveEventArgs args)
at System.AppDomain.OnTypeResolveEvent(String typeName)
--- End of inner exception stack trace ---

Server stack trace:
at
System.Runtime.InteropServices.TypeLibConverter.nConvertTypeLibToMetadata(Object
typeLib, AssemblyBuilder asmBldr, ModuleBuilder modBldr, String
nameSpace, TypeLibImporterFlags flags, ITypeLibImporterNotifySink
notifySink, ArrayList& eventItfInfoList)
at
System.Runtime.InteropServices.TypeLibConverter.ConvertTypeLibToAssembly(Object
typeLib, String asmFileName, TypeLibImporterFlags flags,
ITypeLibImporterNotifySink notifySink, Byte[] publicKey,
StrongNameKeyPair keyPair, String asmNamespace, Version asmVersion)
at
Microsoft.Build.Tasks.TlbReference.GenerateWrapper(ComReferenceWrapperInfo&
wrapperInfo)
at
Microsoft.Build.Tasks.ResolveComReference.ResolveComReferenceTlb(ComReferenceInfo
referenceInfo, String outputDirectory, String refName, Boolean
topLevelRef, ComReferenceWrapperInfo& wrapperInfo)
at
Microsoft.Build.Tasks.ResolveComReference.ResolveComClassicReference(ComReferenceInfo
referenceInfo, String outputDirectory, String wrapperType, String
refName, Boolean topLevelRef, ComReferenceWrapperInfo& wrapperInfo)
at
Microsoft.Build.Tasks.ResolveComReference.ResolveReference(ComReferenceInfo
referenceInfo, String outputDirectory, ITaskItem& referencePathItem)
at
Microsoft.Build.Tasks.ResolveComReference.ResolveReferenceAndAddToList(ComReferenceInfo
projectRefInfo, ArrayList resolvedReferenceList, ArrayList moduleList)
at Microsoft.Build.Tasks.ResolveComReference.Execute()
at
System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr
md, Object[] args, Object server, Int32 methodPtr, Boolean
fExecuteInContext, Object[]& outArgs)
at
System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(RuntimeMethodHandle
md, Object[] args, Object server, Int32 methodPtr, Boolean
fExecuteInContext, Object[]& outArgs)
at
System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage
msg, Int32 methodPtr, Boolean fExecuteInContext)

Exception rethrown at [0]:
at
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage
reqMsg, IMessage retMsg)
at
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&
msgData, Int32 type)
at Microsoft.Build.Framework.ITask.Execute()
at Microsoft.Build.BuildEngine.TaskEngine.ExecuteTask(ExecutionMode
howToExecuteTask, Hashtable projectItemsAvailableToTask,
BuildPropertyGroup projectPropertiesAvailableToTask, Boolean&
taskClassWasFound) Control.Import.Filter


Sincerely
/Hans Sixhöj
Software Developer
 
N

Nicholas Paldino [.NET/C# MVP]

Run tlbimp.exe on the DLL/TLB. When you do, use the /noclassmembers
option, so that class members are not created from the implemented
interfaces. It looks like there are two interfaces with similar method
signatures which are giving you problems.

This will remove the members from the class (so all you do is use it to
create the object). It will require you to cast to the appropriate
interface to access the methods exposed by the object.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Hi,

I am trying to reference a COM component (.dll) from Visual Studio 2005
in my windows application in C# by adding a reference to a third
party.dll file (tried .type library also), and i get this error from
the compiler when trying to compile the solution.

Does anyone know why this occurs, and how it can be resloved, i would
be very grateful indeed.

Here comes the exception thrown:
------------------------------------------
Error 2 The "ResolveComReference" task failed unexpectedly.
System.SystemException: The type library importer encountered an error
during type verification. Try importing without class members. --->
System.TypeLoadException: Method 'IXorDiscountMatrix_GetName' on type
'XOR5.CXorDiscountMatrixClass' from assembly 'Interop.XOR5,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is overriding a
method that has been overridden.
at System.Reflection.Module.InternalLoadInMemoryTypeByName(String
className)
at
System.Runtime.InteropServices.TypeLibConverter.TypeResolveHandler.ResolveEvent(Object
sender, ResolveEventArgs args)
at System.AppDomain.OnTypeResolveEvent(String typeName)
--- End of inner exception stack trace ---

Server stack trace:
at
System.Runtime.InteropServices.TypeLibConverter.nConvertTypeLibToMetadata(Object
typeLib, AssemblyBuilder asmBldr, ModuleBuilder modBldr, String
nameSpace, TypeLibImporterFlags flags, ITypeLibImporterNotifySink
notifySink, ArrayList& eventItfInfoList)
at
System.Runtime.InteropServices.TypeLibConverter.ConvertTypeLibToAssembly(Object
typeLib, String asmFileName, TypeLibImporterFlags flags,
ITypeLibImporterNotifySink notifySink, Byte[] publicKey,
StrongNameKeyPair keyPair, String asmNamespace, Version asmVersion)
at
Microsoft.Build.Tasks.TlbReference.GenerateWrapper(ComReferenceWrapperInfo&
wrapperInfo)
at
Microsoft.Build.Tasks.ResolveComReference.ResolveComReferenceTlb(ComReferenceInfo
referenceInfo, String outputDirectory, String refName, Boolean
topLevelRef, ComReferenceWrapperInfo& wrapperInfo)
at
Microsoft.Build.Tasks.ResolveComReference.ResolveComClassicReference(ComReferenceInfo
referenceInfo, String outputDirectory, String wrapperType, String
refName, Boolean topLevelRef, ComReferenceWrapperInfo& wrapperInfo)
at
Microsoft.Build.Tasks.ResolveComReference.ResolveReference(ComReferenceInfo
referenceInfo, String outputDirectory, ITaskItem& referencePathItem)
at
Microsoft.Build.Tasks.ResolveComReference.ResolveReferenceAndAddToList(ComReferenceInfo
projectRefInfo, ArrayList resolvedReferenceList, ArrayList moduleList)
at Microsoft.Build.Tasks.ResolveComReference.Execute()
at
System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr
md, Object[] args, Object server, Int32 methodPtr, Boolean
fExecuteInContext, Object[]& outArgs)
at
System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(RuntimeMethodHandle
md, Object[] args, Object server, Int32 methodPtr, Boolean
fExecuteInContext, Object[]& outArgs)
at
System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage
msg, Int32 methodPtr, Boolean fExecuteInContext)

Exception rethrown at [0]:
at
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage
reqMsg, IMessage retMsg)
at
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&
msgData, Int32 type)
at Microsoft.Build.Framework.ITask.Execute()
at Microsoft.Build.BuildEngine.TaskEngine.ExecuteTask(ExecutionMode
howToExecuteTask, Hashtable projectItemsAvailableToTask,
BuildPropertyGroup projectPropertiesAvailableToTask, Boolean&
taskClassWasFound) Control.Import.Filter


Sincerely
/Hans Sixhöj
Software Developer
 
F

ffhansix

Hi,

Thanks for your fast response, it worked to create a new .dll file.

The original .dll file (in COM) belongs to a program not built by me. I
need to respond to events triggered in this application when the user
performs different actions (worked in VB) (listen to events from an
interface). Will this be possible although i have created a new .dll
file?

If not, is there a way to achive this?

Sincerely
/Hans Sixhöj
Systems Developer
 
N

Nicholas Paldino [.NET/C# MVP]

Hans,

Well, when you set a reference in Visual Studio .NET, you are still
creating your own interop DLL to use. What you are doing here is no
different, you just have more options available to you.

So yes, you should have access to all of the functionality exposed by
the object.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Hi,

Thanks for your fast response, it worked to create a new .dll file.

The original .dll file (in COM) belongs to a program not built by me. I
need to respond to events triggered in this application when the user
performs different actions (worked in VB) (listen to events from an
interface). Will this be possible although i have created a new .dll
file?

If not, is there a way to achive this?

Sincerely
/Hans Sixhöj
Systems Developer
 
F

ffhansix

Thank you for your answers.

The issue has been resolved.

Thank you very much.

Sincerely,
/Hans Sixhöj
Software Developer
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top