Fair warning, I'm relatively new to using Matlab and Visual Studio.
I've been trying to create code that I can use to communicate through a USB to an arduino. I found some example code using a library called CmdMessenger, the examples provided code to load onto the Arduino and code to be built using Visual Studio. By default the examples run on command line, but I set them to create .DLL files and used NET.addAssembly to add these files to Matlab and use them. Initially this worked just fine and I was able to send a command to my arduino to toggle an LED for a period of time before sending a confirmation signal back to Matlab.
Unfortunately I needed to make changes to the example code so I added some of my own code and created a new DLL using a different piece of example code that better fit my needs. I was able to use "a = NET.addAssembly" again and use the namespace in Matlab. Then I made more changes, cleared the variable "a", and tried to use "a = NET.addAssembly" again, but this time I got an error message.
In fact, I went and tried to add the previous example DLL I'd used, and now it too gives me the same error message. I've searched and found nothing that's helped me rectify this situation.
The command I gave was: "a = NET.addAssembly('C:\DLL\SendAndReceiveArguments.dll');"
The error message I received was:
Message: Could not load file or assembly 'file:///C:\DLL\SendAndReceiveArguments.dll' or one of its dependencies. An attempt was made to
load a program with an incorrect format.
Source: mscorlib
HelpLink:
Any suggestions for troubleshooting this problem would be greatly appreciated.
5 minutes after my last post and I figured it out from another question asked on this very site. Shows how well my I did my searching up to this point.
The first answer to this question led me down the right path. All I needed to do was right-click on the project in Visual Studio and select 'Properties'. In this menu select 'Build' from the left panel and make sure that 'Platform target:' was set to 'Any CPU' (mine was set to x86 for some reason).
With this change my project loaded into Matlab without issue.
Sorry to waste anyone's time who searched for an answer I could have found myself, and thanks for your time.