Click here to Skip to main content
15,881,797 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi everybody.

I have a VB6 application that uses .NET code through a COMClass to read from the serial port. For this I use the .NET SerialPort class. When the SerialPort.Datareceived event is triggered I raise an paraemterless event that my VB6 application subscribes to.

All this is working perfectly during development. It is also working when I execute my application.exe on my local machine. When I execute the application.exe on another machine I get a System.Reflection.TargetException saying "object does not match target type"

Microsoft states that the SerialPort.Datareceived event is raised on another thread and I believe this could be the problem. You can read about it here: http://msdn.microsoft.com/da-dk/library/system.io.ports.serialport.datareceived.aspx

By now Im thinking that I cannot use an event-based approach and at the same time keep a responsive UI in my VB6 application, but what alternatives are there besides polling some shared storage from my VB6 application?

Any suggestions are greatly appreciated.
Posted
Comments
Matthew Faithfull 31-Jan-13 10:04am    
I once had a response like that from Microsoft to do with using a 3rd party Socket control years ago. The answer in my case was to declare the VB6 object 'with Events'
If you've already done that then I'm sorry not to be of any help.
flodpanter 31-Jan-13 10:15am    
Hi Matthew.
Thanks for your reply. I did declare it like that and it works like a charm. But when I execute the same EXE on a different machine, it throws the exception. Also, I have tried building the EXE on a different machine with the same effect.
Matthew Faithfull 31-Jan-13 10:41am    
OK I'm out of serious suggestions I'm afraid VB6 was a loooong time ago. If it works fine from a clean reboot standalone Release build executed by an ordinary i.e. non privelleged user on your machine but not on another, with the same version of the .Net runtime and the same VB runtime then it's down to Windows drivers, serial port hardware, hyperthreading being turned on, the number of cores on the machine, a nasty performance/timitg sensative bug or just back luck. I'm afraid you'll have to take your pick and go from there unless someone else has a better idea. Sergey may be right, it might be easier to redo one half or the other of the problem if its the connection that's the issue. Can you test the low level stuff, closer to the serial port, on it's own to make sure it's working?
Sergey Alexandrovich Kryukov 31-Jan-13 10:33am    
If you already use .NET, who needs VB6?
—SA
flodpanter 1-Feb-13 2:09am    
:-) nice try, but sadly, the old mothership (VB6) is not easily replaced by a brand new .NET based application. Would probably take several years to to that.

1 solution

You're able to run the app only on the machine that builds because VS automatically registers component on build.
You can check: Project Properties - Build Tab - "Register for COM Interop" - if ti's checked then comp. is registered on every build.

To be able to run the app on other machines you need to use "regasm.exe" to manually register the component or create installer which will do that for you.
On command line use:
regasm.exe -tlb -codebase dllname.dll

regasm.exe is in your .NET install folder (usually C:\Windows\Microsoft.NET\Framework\{.NET version}
 
Share this answer
 
Comments
flodpanter 6-Feb-13 11:46am    
Hi Sjelen. In my post build event i do already use regasm to create the tlb-file. This is necessary for any VB6/.NET integration and already works.
sjelen 8-Feb-13 5:40am    
Yes and that is why your app works on dev machine - component is registered after the build.
Regasm does more than create .tlb, it also creates registry entries so Windows knows where to find your library.
If you want app to run on other machines you need to run regasm on each machine you want to use.
Or create installer to do that for you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900