You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET Framework 4.8类库集成Google Vision API遇程序集加载失败问题

解决.NET Framework 4.8 AutoCAD插件集成Google Vision API的程序集加载问题

问题核心

AutoCAD插件作为类库项目,自身的app.config不会被AutoCAD主进程读取,导致你配置的程序集绑定重定向无法生效——这也是为什么相同代码在.NET Framework控制台应用中能正常运行的原因。

解决步骤

1. 将绑定重定向配置到AutoCAD主配置文件

AutoCAD启动时会读取安装目录下的acad.exe.config(例如C:\Program Files\Autodesk\AutoCAD 20XX路径),把Google相关程序集的绑定重定向添加到该文件的<runtime>节点内:

<runtime>
  <!-- 保留原有配置,新增以下内容 -->
  <dependentAssembly>
    <assemblyIdentity name="Google.Api.CommonProtos" publicKeyToken="你的公钥令牌" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-2.7.0.0" newVersion="2.7.0.0" />
  </dependentAssembly>
  <!-- 建议同步添加其他Google依赖的重定向,比如Google.Protobuf、Google.Apis.Core等,确保版本统一 -->
</runtime>

2. 设置依赖程序集为“复制本地”

在插件项目的引用列表中,找到所有Google相关NuGet包(如Google.Cloud.Vision.V1、Google.Api.CommonProtos等),右键点击引用→属性,将复制本地设为True。编译时这些程序集会被复制到插件输出目录,AutoCAD加载插件时能直接找到。

3. 强制加载依赖程序集(可选)

如果仍存在加载问题,可在代码中手动提前加载目标程序集:

// 提前加载指定版本的程序集
Assembly.Load("Google.Api.CommonProtos, Version=2.7.0.0, Culture=neutral, PublicKeyToken=你的公钥令牌");

var clientBuilder = new ImageAnnotatorClientBuilder()
{
    GoogleCredential = GoogleCredential.FromFile(credentialsPath)
};

4. 统一NuGet包版本

检查插件项目中所有Google相关NuGet包的版本,确保版本完全一致,避免跨版本依赖冲突。可通过NuGet包管理器统一更新到最新兼容版本。

验证方式

编译插件后,确认输出目录包含Google.Api.CommonProtos.dll(版本2.7.0.0)及其他依赖文件,再将插件加载到AutoCAD中测试。

内容的提问来源于stack exchange,提问作者TomTomTom

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 17:42:48