yenta
yenta

Reputation: 1372

Why does GetManifestResourceStream fail at runtime?

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.

Upvotes: 3

Views: 250

Answers (0)

Related Questions