3

I am running into a hard to reproduce bug in production code where I am seeing GetManifestResourceStream return null at runtime.

Context: I am running a Service Stack service self hosted as a Windows Service. This service wraps 3rd party software that requires a license file. I have added the license file to the project and configured it as an Embedded Resource.

The license is loaded per request in the following way:

var license = new License();
using (var licStream = EmbeddedResourceScope.GetStream(Constants.LicenseFile))
{
    // licStream can sometimes be null at runtime
    license.SetLicense(licStream);
}

Here is the code for EmbeddedResourceScope

public static class EmbeddedResourceScope
{
    public static Stream GetStream(EmbeddedResource name)
    {
        var scope = typeof (EmbeddedResourceScope);
        var resourceAssembly = Assembly.GetAssembly(scope);
        var resourceStream = resourceAssembly.GetManifestResourceStream(scope, name);

        return resourceStream;
    }
}

Am I missing something obvious here? Maybe related to thread safety?

When the runtime issue pops up, this code fails for every request until the service is restarted.

yenta
  • 1,332
  • 2
  • 11
  • 25
  • Can you check whether the license file has been correctly added as an embedded resource? Please share what `this.GetType().Assembly.GetManifestResourceNames();` returns if called from your assembly in which the license file resides. Also please make sure that `Constants.LicenseFile` is not only the file name alone, but e.g. `MyProject.LicenseFile.txt` (note the `MyProject,` at the beginning). – Thomas Flinkow Aug 28 '18 at 11:21
  • 1
    Possible duplicate of [Why does GetManifestResourceStream returns null while the resource name exists when calling GetManifestResourceNames?](https://stackoverflow.com/questions/10726857/why-does-getmanifestresourcestream-returns-null-while-the-resource-name-exists-w) – mjwills Aug 28 '18 at 11:25

0 Answers0