Building c# sample plugin

Comprehensive CAN monitor for Windows® and its add-ins: Plotter, CANdb Import, Instruments Panel, and J1939
PCANUser
Posts: 26
Joined: Fri 14. Dec 2012, 10:40

Building c# sample plugin

Post by PCANUser » Tue 4. Jun 2013, 14:30

Hello,

I am experimenting with the C# plugin sample that ships with PCAN Explorer 5.

I converted the project to Visual C# 2010 Express (just the normal convert project option built into VC#). The project built without any errors or warnings. I copied the DLL to the PCAN plugins folder but the plugin was not recognised in the Add-In Manager. I tried browsing to the DLL from the Add-In Manager and got the message that the DLL file does not contain a PCAN Explorer Addin.

Can you please shed some light on what the problem might be?

Thanks

K.Wolf
Software Development
Software Development
Posts: 141
Joined: Wed 22. Sep 2010, 15:37

Re: Building c# sample plugin

Post by K.Wolf » Tue 4. Jun 2013, 15:40

Please also copy the file Interop.PCANExplorer5.dll that was created in the project's output directory to the Addins folder and open the Add-in Manager again.

PCANUser
Posts: 26
Joined: Fri 14. Dec 2012, 10:40

Re: Building c# sample plugin

Post by PCANUser » Tue 4. Jun 2013, 17:44

Thanks for the quick response. I tried copying both AddInSample.dll and Interop.PCANExplorer5.dll to the Plugins directory with no success. I also tried using the Browse feature of the Add-In Manager and got the same message about the DLL not containing a PCAN Explorer Addin.

Do you have any other suggestions?

Just to clarify, I am using Window 7 on a 64 bit Intel platform.

Thanks

K.Wolf
Software Development
Software Development
Posts: 141
Joined: Wed 22. Sep 2010, 15:37

Re: Building c# sample plugin

Post by K.Wolf » Thu 6. Jun 2013, 11:30

After testing this under Windows 7 64-bit I got the same problem. I had to make minor adjustments to the source code to get it working:

1) Remove the stdole reference from the project
2) In Commands.cs, in the line "public interface IExampleCommands: stdole.IDispatch" remove all text behind IExampleCommands, including the colon.

Now clean the project and rebuild all, then copy both files to the Addins folder again. Make sure that you run PCAN-Explorer as Administrator, then open the Add-in Manager.

PCANUser
Posts: 26
Joined: Fri 14. Dec 2012, 10:40

Re: Building c# sample plugin

Post by PCANUser » Tue 11. Jun 2013, 10:29

I am still getting the same message.

I assume when I run the Add-In manager in administrator mode I should see the AddInSample listed? If I use Browse in the Add-In manager I get the same message about not the file not containing a PCAN plugin.

Would it be possible to post your project so I can be sure there is nothing else different?

Thanks,
Richard

P.S. Looking at the first few bytes of the file, I notice that other plugins start with MZP and contain the string "This program must be run under Win32" whereas the plugins I have built begins with MZ and contains the string "This program cannot be run in DOS mode".

To aid in debugging I have attached my project.
Attachments
PCANPlugin.zip
Original project but converted to C sharp Express with mods specified in earlier post
(22.5 KiB) Downloaded 568 times

K.Wolf
Software Development
Software Development
Posts: 141
Joined: Wed 22. Sep 2010, 15:37

Re: Building c# sample plugin

Post by K.Wolf » Thu 13. Jun 2013, 12:38

The problem is you changed the project to use .NET Framework 4 instead of v2.0. Hosting a managed .NET 4 assembly in a Win32 application is a completely different thing and is currently not supported in PCAN-Explorer. We already experimented with this, but we have not yet succeeded.
Please switch the project back to .NET 2.0 and it will work. We hope to make PCAN-Explorer compatible with .NET 4 in a future release.

PCANUser
Posts: 26
Joined: Fri 14. Dec 2012, 10:40

Re: Building c# sample plugin

Post by PCANUser » Thu 13. Jun 2013, 15:08

Thank you, it now works. After converting from C# 2008 to 2010 I didn't think to check the .Net framework version. For anybody else who is interested, I have attached the now working project for Visual C# 2010 Express.

Regards,
Richard
Attachments
PCANPlugin.zip
Working plugin sample for Visual C# 2010 Express
(22.64 KiB) Downloaded 595 times

PCANUser
Posts: 26
Joined: Fri 14. Dec 2012, 10:40

Re: Building c# sample plugin

Post by PCANUser » Tue 10. Sep 2013, 18:37

Hello,

I am almost there but not quite!

I have modified the C# plugin source code that is supplied with PCAN Explorer 5 and it all works fine on my machine. In the end I resorted to MSVC# 2008 to build and debug the plugin (you cannot debug a DLL with C# Express). However when my colleague, who has exactly the same specification of PC as me (Windows 7, 64 bit), tries to use the plugin, only a blank tab is displayed. Every time the plugin button is pressed a new empty tab is displayed. I have also built the unmodified sample with exactly the same effect.

UPDATE: I forgot the stole stuff earlier in the thread and it now works fine - not sure why it works on my machine though!

Thanks

PCANUser
Posts: 26
Joined: Fri 14. Dec 2012, 10:40

Re: Building c# sample plugin

Post by PCANUser » Fri 13. Sep 2013, 12:44

Hello,

Unfortunately there is still a problem.

Most of my users are fine but on one machine which is to all intents and purposes the same as the others, only a blank tab is displayed when the plugin is started. Based on debug statements I can see that the plugin installed correctly.

What would cause the window not to be displayed?

Thanks,
Richard

PCANUser
Posts: 26
Joined: Fri 14. Dec 2012, 10:40

Re: Building c# sample plugin

Post by PCANUser » Fri 13. Sep 2013, 15:32

Hello,

After some extensive debugging with Trace outputs it appears the problem was caused by an exception at start-up.

However this has highlighted another problem - how can I change the version of the DLL?

If I change the assembly version information, the plugin fails to work with the symptoms described previously.

Thanks,
Richard

Post Reply