2
votes

I've been following a tutorial on how to resize images using ImageResizer listening to blob storage triggers in Azure Functions. However, i'm getting the following error message:

error CS0246: The type or namespace name 'ImageResizer' could not be found (are you missing a using directive or an assembly reference?)

error CS0246: The type or namespace name 'ImageResizer' could not be found (are you missing a using directive or an assembly reference?)

error CS0103: The name 'ImageResizer' does not exist in the current context

My project.json config has been set up as follows:

{
"frameworks": {
  "net46":{
    "dependencies": {
      "ImageResizer": "4.0.5"
    }
  }
 }
}

and my run code is:

#r "System.Drawing"
#r "System.Web"

using ImageResizer;
using System.Drawing;
using System.Drawing.Imaging;

public static void Run(Stream inputImage, string imageName, Stream outputImage, TraceWriter log)
{
    log.Info($"C# Blob trigger function Processed blob\n Name:{imageName} \n Size: {inputImage.Length} Bytes");

    var settings = new ImageResizer.ResizeSettings{
        MaxWidth = 400,
        Format = "jpg"
    };

    ImageResizer.ImageBuilder.Current.Build(inputImage, outputImage, settings);

}
3
Has this been resolved by following the recommendations below? - Fabio Cavalcante
Nope, although i managed (by a stroke of luck), to find the cause of the issue. I'll answer the question below. - Gavin5511
Can you please share the link to the tutorial that you were following? Did you get it all working in the end? - Stephen Anderson

3 Answers

4
votes

I managed to resolve the issue in the end. The problem was, that i had actually called the name of my function 'ImageReizer', which creates a folder with that name in the App Service Plan in the back-end. The problem was, that because it had the same name as the NugetPackage 'ImageResizer', it was getting confused and looking in the project folder instead of the package folder of the same name.

I rebuilt the function with a different name (ImageManipulation) and everything now works as expected.

1
votes

It looks like for some reason your nuget package restore hasn't happened properly. Using the exact same code as yours above, I'm able to compile this function successfully.

You can force the package restore to happen again by "touching" your project.json file. Just make an edit and save it, and you should see the restore happen. On the Develop page for your function, select "View Files", select the project.json file and edit/save. In your log window you should see the restore happen again.

0
votes

If you are using Azure function in version 2.x you need to do this in a different way.

Create a new file and name it function.proj instead of project.json. Here is an example importing ImageResizer:

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
    <PackageReference Include="ImageResizer" Version="4.2.5" />
</ItemGroup>

You can check which runtime version is being used at Azure Portal by clicking on the function name, under Overview tab choose "Function app settings". Runtime version can be ~1 or ~2.