ebekker / ACMESharp

An ACME client library and PowerShell client for the .NET platform (Let's Encrypt)
https://pkisharp.github.io/ACMESharp-docs/
1.21k stars 185 forks source link

ACMESharp in asp.net mvc #196

Open bpetersen1 opened 7 years ago

bpetersen1 commented 7 years ago

Is it possible to to add this lib into a mvc project ? I keep getting this error:

Could not load file or assembly 'ManagedOpenSsl64' or one of its dependencies. An attempt was made to load a program with an incorrect format.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.BadImageFormatException: Could not load file or assembly 'ManagedOpenSsl64' or one of its dependencies. An attempt was made to load a program with an incorrect format.

Any idea's ? I Tried running it in x64 & x86 but still no luck.

bseddon commented 7 years ago

I saw a similar message opening the ACMESharp source in VS2013. The problem does not exist for me in VS 2015. Maybe you have a similar problem.

bpetersen1 commented 7 years ago

Thanks for the reply. I am however using VS 2015 CE. Any Idea's ?

bseddon commented 7 years ago

When you download and open the ACMESharp source in VS 2015 do you see the same message? If not it may be an opportunity to compare the project file of the ACMESharp project and the project file of your MVC project to see if there are any obvious differences.

As well as the managed assembly, did you include the OpenSsl x64 folder. This contains the libeay32.dll and ssleay32.dll from the Open SSL project. Could these be the dependencies that are missing?

bpetersen1 commented 7 years ago

I can see those x86 and x64 folders in my solution, I even tried referencing them but no luck. still getting the following error:

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.BadImageFormatException: Could not load file or assembly 'ManagedOpenSsl64' or one of its dependencies. An attempt was made to load a program with an incorrect format.

bseddon commented 7 years ago

You didn't mention if you are able to compile and execute the ACMESharp source OK. It's hard to help without a case that can be reproduced. I'm not having problems compiling and running the source. However, I don't have an MVC project. Maybe it's when you call a specific function? Can you provide a VS project containing just enough code to demonstrate the issue?

bpetersen1 commented 7 years ago

Sorry, yes i forgot to mention, i managed to pull down the ACMESharp project, the only part of the project that wouldnt compile was the unit test's. kept complaining about not referencing OpenSSL lib. But the Acmesharp lib complies.

bpetersen1 commented 7 years ago

i will upload my project later

ebekker commented 7 years ago

Are you running this under IIS? Sometimes, IIS app pools are setup as 32-bit even when they're running on a 64-bit machine. The PKI Provider for OpenSSL in ACMESharp tries to detect the correct host architecture and uses that to load up the correct version of the native OpenSSL library, but if you're running a 32-bit app on 64-bit OS then it will get confused. You may want to have both versions of the OpenSSL native libs accessible.

ebekker commented 7 years ago

Another option is to use the PKI Provider that's based on Bouncy Castle, which is found here. This is a pure managed library (no native components) so it shouldn't suffer from this issue.

It hasn't been published to NuGet yet, so you'll have to get it and build it from the GitHub repo for now (at least another week or two), but I've had good luck with this provider and am planning to switch to it as the default provider once 0.8.2 is released.