I'm having a Certificate under root folder of the project. The Project name is SingleSignOn, but I can't able to read the method using the GetManifestResourceStream build-in method.
The Source Code is
namespace SingleSignOn
{
public class Program
{
static void Main(string[] args)
{
var assembly = typeof(Program).Assembly;
var super = assembly.GetManifestResourceNames();
using (var stream = assembly.GetManifestResourceStream("SingleSignOn.idsrv3test.pfx"))
{
}
}
}
}
Snap shot of Solution Explorer

I'm getting NULL from the said built-in method GetManifestResourceStream

I don't know what I missed in this. The URL of the said Certificate is https://github.com/IdentityServer/IdentityServer3.Samples/blob/master/source/Certificates/idsrv3test.pfx
Kindly assist me how to read the Certificate.
Try this:
var resourceName = "SingleSignOn.idsrv3test.pfx";
using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
{
TextReader tr = new StreamReader(stream);
string fileContents = tr.ReadToEnd();
}
Note: Put the file as an embedded resource. file > right click > properties > build action > select embedded resource.
Solution 2
Step 1: Change properties of .PFX file
idsrv3test.pfx properties, set Build action as Embedded Resource.
Step 2: Code change:
var resourceName = "SingleSignOn.idsrv3test.pfx";
using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
{
TextReader tr = new StreamReader(stream);
string fileContents = tr.ReadToEnd();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With