升级 Microsoft.NET.Sdk.Functions 后,“Mono.Cecil.TypeReference”类型的对象无法转换为“System.Type”类型

问题描述 投票:0回答:1

在 dotnet 8 Azure Function 项目中,由于存在漏洞,我必须升级包

Microsoft.NET.Sdk.Functions
,从
4.0.0
4.5.0

升级这个包会导致一个奇怪的错误,其要点是:

Object of type 'Mono.Cecil.TypeReference' cannot be converted to type 'System.Type'

这是包含所有详细信息的完整错误消息:

Error (active)      System.ArgumentException: Object of type 'Mono.Cecil.TypeReference' cannot be converted to type 'System.Type'.
   at System.RuntimeType.TryChangeType(Object value, Binder binder, CultureInfo culture, Boolean needsSpecialCast)
   at System.RuntimeType.CheckValue(Object value, Binder binder, CultureInfo culture, BindingFlags invokeAttr)
   at System.Reflection.MethodBase.CheckArguments(StackAllocedArguments& stackArgs, ReadOnlySpan`1 parameters, Binder binder, BindingFlags invokeAttr, CultureInfo culture, Signature sig)
   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at MakeFunctionJson.TypeUtility.ToReflection(CustomAttribute customAttribute) in /_/src/Microsoft.NET.Sdk.Functions.Generator/TypeUtility.cs:line 106
   at MakeFunctionJson.TypeUtility.GetResolvedAttribute(ParameterDefinition parameter, CustomAttribute customAttribute) in /_/src/Microsoft.NET.Sdk.Functions.Generator/TypeUtility.cs:line 67
   at MakeFunctionJson.ParameterInfoExtensions.<>c__DisplayClass1_0.<ToFunctionJsonBindings>b__1(CustomAttribute a) in /_/src/Microsoft.NET.Sdk.Functions.Generator/ParameterInfoExtensions.cs:line 32
   at System.Linq.Utilities.<>c__DisplayClass2_0`3.<CombineSelectors>b__0(TSource x)
   at System.Linq.Utilities.<>c__DisplayClass2_0`3.<CombineSelectors>b__0(TSource x)
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.ToList()
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at MakeFunctionJson.ParameterInfoExtensions.ToFunctionJsonBindings(ParameterDefinition parameterInfo) in /_/src/Microsoft.NET.Sdk.Functions.Generator/ParameterInfoExtensions.cs:line 29
   at MakeFunctionJson.MethodInfoExtensions.<>c.<ToFunctionJson>b__6_0(ParameterDefinition p) in /_/src/Microsoft.NET.Sdk.Functions.Generator/MethodInfoExtensions.cs:line 66
   at System.Linq.Enumerable.SelectIListIterator`2.MoveNext()
   at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
   at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items)
   at System.Collections.Generic.SparseArrayBuilder`1.ReserveOrAdd(IEnumerable`1 items)
   at System.Linq.Enumerable.Concat2Iterator`1.ToArray()
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at MakeFunctionJson.MethodInfoExtensions.ToFunctionJson(MethodDefinition method, String assemblyPath) in /_/src/Microsoft.NET.Sdk.Functions.Generator/MethodInfoExtensions.cs:line 65
   at MakeFunctionJson.FunctionJsonConverter.GenerateFunctions(IEnumerable`1 types)+MoveNext() in /_/src/Microsoft.NET.Sdk.Functions.Generator/FunctionJsonConverter.cs:line 140
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at MakeFunctionJson.FunctionJsonConverter.TryGenerateFunctionJsons() in /_/src/Microsoft.NET.Sdk.Functions.Generator/FunctionJsonConverter.cs:line 194
   at MakeFunctionJson.FunctionJsonConverter.TryRun() in /_/src/Microsoft.NET.Sdk.Functions.Generator/FunctionJsonConverter.cs:line 87
Error generating functions metadata
    Teleclaim.API   C:\Users\bd57031\.nuget\packages\microsoft.net.sdk.functions\4.5.0\build\Microsoft.NET.Sdk.Functions.Build.targets  32 

此外,单击 Visual Studio 中的错误消息,将光标移至以下部分:

[UserFolder]\.nuget\packages\microsoft.net.sdk.functions\4.5.0\build\Microsoft.NET.Sdk.Functions.Build.targets
:

<GenerateFunctions
  TargetPath="$(TargetDir)bin\$(TargetFileName)"
  OutputPath="$(TargetDir)"
  UserProvidedFunctionJsonFiles="@(UserProvidedFunctionJsonFiles)"
  FunctionsInDependencies="$(FunctionsInDependencies)"
  TaskAssemblyDirectory="$(_FunctionsTasksDir)"/>

我想知道是否有人有类似的升级此软件包并克服此问题的经历?

.net azure-functions microsoft.net.sdk.functions
1个回答
0
投票

该问题可能是由于软件包版本、SDK 和功能核心工具之间的版本兼容性问题,或者由于您正在安装的软件包版本中生成或处理元数据的方式发生了变化,请参阅类似问题

如果进程内模型项目使用 4.5.0 版本的

Microsoft.NET.Sdk.Functions
,应使用 4.0.6517 或更高版本的 Function Core Tools。

卸载现有版本的Function core工具并安装最新版本。

安装核心工具的命令:

npm i -g azure-functions-core-tools@4 --unsafe-perm true

删除

%LocalAppData%\AzureFunctionsTools
文件夹并重新启动 Visual Studio。

  • 清理并重建项目。

我创建了一个 .NET 8.0 Azure 函数。 在 local.settings.json 中添加

"FUNCTIONS_INPROC_NET8_ENABLED": "1",

local.settings.json:

{
    "IsEncrypted": false,
    "Values": {
        "AzureWebJobsStorage": "UseDevelopmentStorage=true",
        "FUNCTIONS_INPROC_NET8_ENABLED": "1",
        "FUNCTIONS_WORKER_RUNTIME": "dotnet"
    }
}

.csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.5.0" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>
© www.soinside.com 2019 - 2024. All rights reserved.