'Can't get resourceStream from JSON file from the WebJob using the GetManifestResourceStream method

In the Visual Studio 2017 I created a WebJob. I named that WebJob 'TaxSyncWebJob'

Right inside the TaxSyncWebJob project folder I placed the JSON file called taxonomy.json to read from

I am using the following code in an attempt to access that JSON

var resourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("TaxSyncWebJob.taxonomy.json");

However, the resourceStream returns null.

That code works in a simple console project

Is there a reason why I can't get JSON contents in WebJob using the GetManifestResourceStream?



Solution 1:[1]

Maybe this helps someone else. You need to update your csproj file to include those json files, or the assembly manifest wont find them on runtime.

<ItemGroup>
    <EmbeddedResource Include="<path>\<to>\<file>\TaxSyncWebJob.taxonomy.json" />
</ItemGroup>

<ItemGroup>
    <Resource Include="<path>\<to>\<file>\TaxSyncWebJob.taxonomy.json">
        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Resource>
</ItemGroup>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Scott Murray