unosquare / swan

Swan stands for Stuff We All Need. Unosquare's collection of C# extension methods and classes.
https://unosquare.github.io/swan
MIT License
262 stars 29 forks source link

Unable to load certificate, HTTPS / SSL issues #272

Open AgrYpn1a opened 2 years ago

AgrYpn1a commented 2 years ago

Hey,

We already discussed this in the previous post but it remained unresolved. I wonder if you could help. I am getting a nullptr exception here when trying to load a certificate. I've logged the certificate, and it's loaded correctly.

NullEmbedioscreenshot

svanderbeck11 commented 2 years ago

Same issue here. If you simply try and log(SwanRuntime.OS) which look to be happening in the AutoRegister setter, it results in a "TypeInitializationException: The type initializer for 'Swan.SwanRuntime' threw an exception"

rdeago commented 2 years ago

I just transferred this issue from EmbedIO, since this is evidently an issue with Swan.Lite version 3.

Looking at the source code, I can't understand where this exception comes from. All SwanRuntime does at initialization is create some apparently innocent objects. Can anyone shed some light?

geoperez commented 2 years ago

Are they trying to use HTTPS on Mac?

svanderbeck11 commented 2 years ago

In my case it was Unity on Windows 10.

cyanfish commented 6 months ago

The issue is using Assembly.GetEntryAssembly() here, which can be null in various cases (e.g. unit tests). https://github.com/unosquare/swan/blob/4b33e5f943a4513124243c0fcf8e9b9f7503b858/src/Swan.Lite/SwanRuntime.cs#L37

In my case I found I didn't actually need to use AutoRegisterCertificate, my problem was that I was trying to use WithCertificate with a certificate that didn't have a private key attached (.crt) - generating the right type of certificate file (.pfx) made it work without needing to touch the system certificate store.

AgrYpn1a commented 6 months ago

I ended up writing a C# wrapper around https://github.com/yhirose/cpp-httplib since none of the .NET solutions I've tried worked.