Reputation: 303
Visual Studio 2017 v15.9.25.
Azure function v2.
Here's my run function:
public static async Task Run(
[TimerTrigger("0 */2 * * *")]TimerInfo myTimer,
ILogger log,
[Blob("BlobContainer/blob.json", FileAccess.ReadWrite, Connection = "AzureWebJobsStorage")] CloudBlockBlob stateStore,
ExecutionContext context)
{
When I build the function locally in VS, the function.json
doesn't have the binding to the blob storage.
So, when I try to run it locally, it gives the following error:
The 'AzureFunctionApp' function is in error:
Microsoft.Azure.WebJobs.Host: Error indexing method 'AzureFunctionApp'.
Microsoft.Azure.WebJobs.Host: Can't bind Blob to type 'Microsoft.Azure.Storage.Blob.CloudBlockBlob'.
This is the host.json
:
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingExcludedTypes": "Request",
"samplingSettings": {
"isEnabled": true
}
}
}
}
Here are the dependencies:
I've tried the following:
func host json
as well as debugging in VS17.I've read other 6 similar questions but didn't find the solution helpful.
Kindly help me fix it.
Upvotes: 1
Views: 1563
Reputation: 15734
For this problem, I went through some similar questions. Most of them are created in VS2017 and with the package WindowsAzure.Storage
. According to the screenshot you provided, I know you didn't install this package, but I suggest you to update your Visual Studio from 2017 to 2019 because VS2019 is more suitable for us to develop azure function (and maybe there are some difference in "Storage Emulator" between VS2017 and VS2019).
After update the Visual Studio to 2019, please create a new function app without any other packages in it. I noticed there are some other packages such as "azure keyvault" in your screenshot. Then copy the code above to your new function and install the packages one by one.
Below provide details of my function for your reference. I created it in VS2019 and it works fine.
Function code and installed packages:
local.settings.json
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet"
}
}
csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<AzureFunctionsVersion>v2</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="4.0.2" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.31" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
By the way, my function.json
also doesn't contain binding about blob storage. So I think it has nothing to do with your problem.
function.json
{
"generatedBy": "Microsoft.NET.Sdk.Functions-1.0.31",
"configurationSource": "attributes",
"bindings": [
{
"type": "timerTrigger",
"schedule": "*/30 * * * * *",
"useMonitor": true,
"runOnStartup": false,
"name": "myTimer"
}
],
"disabled": false,
"scriptFile": "../bin/FunctionAppV2.dll",
"entryPoint": "FunctionAppV2.Function1.Run"
}
==============================Update========================
I reproduced your problem, it may caused by using wrong packages.
Although there isn't a package WindowsAzure.Storage
in the screenshot of your installed packages. But this package doesn't need to be installed, it can be using directly in function.
In my function code, if I using Microsoft.WindowsAzure.Storage.Blob
as the screenshot shown below, it will show the same error message as yours. So please using Microsoft.Azure.Storage.Blob
for CloudBlockBlob
.
Upvotes: 2