Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrading to 1.0.1 CLI tools and SDK starts breaking things #1783

Closed
leolorenzoluis opened this issue Aug 12, 2017 · 12 comments
Closed

Upgrading to 1.0.1 CLI tools and SDK starts breaking things #1783

leolorenzoluis opened this issue Aug 12, 2017 · 12 comments

Comments

@leolorenzoluis
Copy link

leolorenzoluis commented Aug 12, 2017

After upgrading to 1.0.1 CLI tools without any code changes, I suddenly started to get the following error:

ResizeImage: Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.ResizeImage'. Microsoft.Azure.WebJobs.Extensions.DocumentDB: 'Id' is required when binding to a DocumentClient property.

The following code:

 [FunctionName(nameof(ResizeImage))]
        public static async Task RunAsync([BlobTrigger("profile-pictures/{name}")] CloudBlockBlob myBlob, string name, [DocumentDB(databaseName: "x", collectionName: "UserProfile", CreateIfNotExists = true)] DocumentClient client, [Blob("profile-pictures/resized-{name}", FileAccess.ReadWrite)] CloudBlockBlob resizedBlob, TraceWriter log)

I thought Id is optional? At least that's what the docs says.

According to the docs:

The properties id and sqlQuery cannot both be specified. If neither id nor sqlQuery is set, the entire collection is retrieved.

The generated json:

{
  "bindings": [
    {
      "type": "blobTrigger",
      "path": "profile-pictures/{name}",
      "direction": "in",
      "name": "myBlob"
    },
    {
      "type": "documentDB",
      "databaseName": "x",
      "collectionName": "UserProfile",
      "createIfNotExists": true,
      "direction": "out",
      "name": "client"
    },
    {
      "type": "blob",
      "path": "profile-pictures/resized-{name}",
      "direction": "inout",
      "name": "resizedBlob"
    }
  ],
  "disabled": false,
  "scriptFile": "..\\X.Functions.dll",
  "entryPoint": "X.Functions.ResizeImage.RunAsync"
}

I'm using 1.0.0 SDK

@leolorenzoluis leolorenzoluis changed the title [CLI] - Upgrading to 1.0.1 starts breaking things Upgrading to 1.0.1 CLI tools and SDK starts breaking things Aug 12, 2017
@christopheranderson christopheranderson added this to the Active Questions milestone Aug 14, 2017
@brettsam
Copy link
Member

What version of DocumentDB are you referencing? It's possible that you moved up to a version that we don't support and it's resulting in a bad error message.

@leolorenzoluis
Copy link
Author

leolorenzoluis commented Aug 14, 2017

Originally I had the following:

<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.0-alpha6" />

I upgraded now to

<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.0" />

For the DocumentDB I didn't upgrade anything,

<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.DocumentDB" Version="1.0.0" />

This is just my complete .csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net461</TargetFramework>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <LangVersion>7.1</LangVersion>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Azure.WebJobs" Version="2.1.0-beta1" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions" Version="2.1.0-beta1" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.DocumentDB" Version="1.0.0" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Http" Version="1.0.0-beta1" />
    <PackageReference Include="Microsoft.Azure.WebJobs.ServiceBus" Version="2.1.0-beta1" />
    <PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.0" />
  </ItemGroup>
  <ItemGroup>
    <Reference Include="Microsoft.CSharp" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="ResizeImage\function.json">
      <CopyToOutputDirectory>Never</CopyToOutputDirectory>
    </None>
    <None Update="visionapi.key">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
  </ItemGroup>
</Project>

Only thing I changed was the Sdk.

@brettsam
Copy link
Member

brettsam commented Aug 14, 2017

Actually -- you may be hitting some of the 'improved' signature error detection that's been added fairly recently. Can you change the attribute to just be [DocumentDB]? None of the other properties are needed for the DocumentClient parameter type. If that's the case, we must be checking the parameter type in the wrong order -- which I'll fix.

@brettsam
Copy link
Member

Also -- do you see this error when you run locally? or just when you deploy to Azure?

@leolorenzoluis
Copy link
Author

leolorenzoluis commented Aug 14, 2017

Hmm? If I change it to just [DocumentDb] then the generated package.json is wrong.

This is running local environment.

{
  "generatedBy": "Microsoft.NET.Sdk.Functions-1.0.0.0",
  "configurationSource": "attributes",
  "bindings": [
    {
      "type": "blobTrigger",
      "path": "profile-pictures/{name}",
      "name": "myBlob"
    }
  ],
  "disabled": false,
  "scriptFile": "..\\bin\\X.Functions.dll",
  "entryPoint": "X.Functions.ResizeImage.RunAsync"
}

Nevertheless, I still get the same error when I remove all the properties in the attribute [DocumentDb].

@brettsam
Copy link
Member

Thanks for all the details -- I see this locally as well. I'm going to confer with some tooling experts and see if we can figure out what's going on.

@brettsam
Copy link
Member

I found the issue and filed Azure/azure-functions-core-tools#206. The easiest workaround until we have an update:

  1. Go to C:\Users\{user}\appdata\local\Azure.Functions.Cli\1.0.0.
  2. Open func.exe.config in notepad.
  3. Find this:
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Azure.Documents.Client" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.11.0.0" newVersion="1.11.0.0" />
      </dependentAssembly>
  1. In both places, replace 1.11.0.0 with 1.13.0.0 so you end up with:
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Azure.Documents.Client" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.13.0.0" newVersion="1.13.0.0" />
      </dependentAssembly>
  1. Save and retry.

@leolorenzoluis
Copy link
Author

That fixes it. Thank you!

@ThorstenHans
Copy link

If anyone is also having this issue, verify that you executed the Functions project at least on time locally. Otherwise you won't be able to find the Azure.Functions.Cli folder underneath appdata\local once you've started the functions project locally, follow the steps described by @brettsam

@ThorstenHans
Copy link

ThorstenHans commented Sep 20, 2017

@brettsam followed all the instructions, but still ending up without having a binding defined for [DocumentDB].

so the function definition looks like this

   public static HttpResponseMessage Run(
            [HttpTrigger(AuthorizationLevel.Function, "post")]HttpRequestMessage req,
            [DocumentDB("db", "col", CreateIfNotExists = true, ConnectionStringSetting = "AzureWebJobsDocumentDBConnectionString")] out dynamic document,
            TraceWriter log)
        {
         // removed content .. should not matter
        }

the function.json is generated like this

{
  "generatedBy": "Microsoft.NET.Sdk.Functions-1.0.0.0",
  "configurationSource": "attributes",
  "bindings": [
    {
      "type": "httpTrigger",
      "methods": [
        "post"
      ],
      "authLevel": "function",
      "name": "req"
    }
  ],
  "disabled": false,
  "scriptFile": "..\\bin\\Sample.Fn.dll",
  "entryPoint": "Samaple.Fn.CreateItem.Run"
}

Wondering if anyone gets this up and running. It's a clean windows 10 VM with latest VS2017 and all updates installed

@ThorstenHans
Copy link

Investigated a bit more time here, it seems like there is no binding required for [DocumentDB] items are being created as expected without having the binding being defined.

I think docs should point to that

@brettsam
Copy link
Member

Were you expecting to see the binding in your function.json? When using the VS tools, all of that metadata comes from the attributes themselves so you won't see that -- we use the "configurationSource": "attributes" for that. You're right that this topic could probably have a callout note that explains that this is happening so it doesn't confuse people.

@Azure Azure locked as resolved and limited conversation to collaborators Jan 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants