Page 1 of 1

C# WiringPi - unable to load

Posted: Mon Mar 19, 2018 11:29 am
by boybanyas
This may be a simple problem, it's giving me headache for days already. Hope you could help out.
I have a working C# program using WiringPi last year. I'm using Visual Studio 2015.

Now I want to use it again, but it produces this error:
"Unable to load DLL ''.

I'm using danriches
Please see attach image file.
Thank you.

Re: C# WiringPi - unable to load

Posted: Thu Mar 22, 2018 3:44 am
by Patm
First question - did you install wiringpi?

Re: C# WiringPi - unable to load

Posted: Thu Mar 22, 2018 7:12 am
by boybanyas
Hi Patm,

Thanks for your response.
I followed ... ts-with-c/
I build WiringPi wrapper class in Visual Studio, then add WiringPi.dll in references of my form.

If in case I miss something, can you please guide me. I forgot how I made it work last year.
What should be done to install in Visual Studio 2017?

Re: C# WiringPi - unable to load

Posted: Fri Mar 23, 2018 11:57 pm
by Patm
Well I was just trying it out. The default package doesn't seem to even have a libwiringPi.o so I removed it and cloned wiringPi's git repository according to their instructions at

From there I went into the wiringPi directory and found all the .o files and, cc'd as per instructions (just the first one - the other two are no longer necessary apparently).

From there I compiled the solution and copied the .exe and .dll to the pi and it didn't complain.

Re: C# WiringPi - unable to load

Posted: Sat Mar 24, 2018 12:44 pm
by Patm
Just had a thought, are you running the program locally on your PC or from the command line on your Pi?

Re: C# WiringPi - unable to load

Posted: Sat Mar 24, 2018 11:34 pm
by boybanyas
I'm currently developing the program from my PC (windows 10) using Visual Studio 2017.
Once I'm done, i will transfer the compiled exe program to the Raspberry pi.

I'm still on the first stage, I can't compile on VS because it cannot locate
I will clone wiringPi's git repository using Raspberry Pi, get the and transfer (using filezilla) it to the /WiringPi/bin/debug folder on my PC.
Is this procedure correct?

Re: C# WiringPi - unable to load

Posted: Sun Mar 25, 2018 1:38 am
by boybanyas
On raspberry, I did "cc -shared wiringPi.o -o" to create the
Then transfer the created to C:windows/system32 folder.
No more unable to load error, but System.BadImageFormatException occurred. An attempt was made to load a program with an incorrect format.

Re: C# WiringPi - unable to load

Posted: Sun Mar 25, 2018 2:47 pm
by Patm
I don't have wiringPi on the PC, don't think it exists except as a fake that gives you the ability to compile but the functions would be all empty.

What I did was create a samba share on the Pi and put the project there. I only load the project from the Pi. I can then use build (running doesn't work on the PC even if there's no errors since it doesn't have the devices) and run the binary with "mono my.exe:.

I then downloaded MonoRemoteDebugger and unzipped it to my Pi home directory and run that from a second CLI. Next get the MonoRemoteDebugger plugin for VS (2015 or 2017) and install that.

From there I can just choose the MonoRemoteDebugger->Debug Remote and it'll run on the Pi while reporting debug information on the PC. Just keep in mind you won't see build errors so run build from the PC (though the project you've got loaded is on the Pi) and once that's good do a Remote Debug.

Oh and if you mono my.exe it'll dump a stack trace into the CLI too - sometimes the debug information getting to the PC doesn't tell you enough.

Re: C# WiringPi - unable to load

Posted: Tue Mar 27, 2018 3:50 pm
by boybanyas
Thanks Patm for the suggestions.
I remember before that I program directly on Visual Studio C#, then transfer the Release folder to the Raspberry Pi wherein I will execute it using Mono.
Maybe there are plugins I'm missing or need tweaks on the updated wiringPi.

Re: C# WiringPi - unable to load

Posted: Mon Mar 11, 2019 3:27 pm
by marcc70
Hi There boybanyas,

Did you resolve this problem?
Because at the moment I am stuck with exactly the same problem as yours.

Would appreciate it if you have time to response.

Thanks and regards,


Re: C# WiringPi - unable to load

Posted: Fri Mar 15, 2019 10:00 am
by dobova86
I'm working in C# too, but on NetCore 2.2 and I find Unosquare wrapper around the wiringPi lib working very nice.

Re: C# WiringPi - unable to load

Posted: Sat Mar 23, 2019 10:03 pm
by pdavis68
I'm confused. Is the OP talking about developing a C# .NET Framework app for Raspberry Pi? I don't think that'll work. You can do .NET Core, but you can't do .NET Framework.

Furthermore, if you're linking to, you won't be able to build in windows. BadImageFormat because .so files aren't a recognized windows image format. Unfortunately, as far as I can tell, you can't actually build for arm in VS2017.

You'll need to switch to .net core (2.2 is just dandy) and you'll need to actually build on the Pi.

To make things easier, you can create your initial project and do the development in and copy it over with some minor changes. I haven't run into your issue because I'm not linking external libraries, so I can develop and compile in Windows and then just copy to the pi to rebuild.

You can download the sdk and runtime here: ... 2-binaries ... 2-binaries
(both from this page: