c# - 配置生成器 - 无法加载程序集 - .Net Framework

我在我的 .Net Framework WebAPI 中使用基于文件的用户 secret ,并且一切都与 web.configAppSettings 部分一起正常工作,如下所示

<configuration>
  <configSections>
    <section name="configBuilders" type="System.Configuration.ConfigurationBuildersSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" restartOnExternalChanges="false" requirePermission="false" />
  </configSections>
  <configBuilders>
    <builders>
      <add name="Secrets" userSecretsFile="MySecretsFile.xml" type="Microsoft.Configuration.ConfigurationBuilders.UserSecretsConfigBuilder, Microsoft.Configuration.ConfigurationBuilders.UserSecrets, Version=1.0.0.0, Culture=neutral" />
    </builders>
  </configBuilders>
  <appSettings  configBuilders="Secrets">
    <add key="mysetting1" value="(default)" />
    <add key="mysetting2" value="(default)" />
  </appSettings>
</configuration>

但是,我现在需要为 EF 连接的 connectionStrings 添加相同的内容,以下条目位于下面的 web.config

<connectionStrings configBuilders="Secrets">
  <add name="Entities" connectionString="A" providerName="System.Data.EntityClient" />
</connectionStrings>

当我运行该应用程序(在 Visual Studio 中)时,我收到以下错误,表明 ConfigurationBuilders 在查找某些内容时遇到问题....但我不知道...事情是什么,所有 appSettingsconfigurationStrings 都按预期加载。

如果我删除 configBuilders="Secrets",则不会显示错误。

那么我错过了什么,我怎样才能找到它试图加载但找不到的内容。

最佳答案

它确实说明了您在加载哪个程序集时遇到问题。您是否已验证您的项目确实正确引用了 Microsoft.Configuration.ConfigurationBuilders.UserSecrets?验证版本号,是否为 1.0.0.0。通过直接在代码中引用该程序集的类型,最容易验证。如果编译器接受这一点,那么运行时也可能接受。

如果明显的检查没有帮助,则解决通常的程序集加载故障排除。即fuslogvw.exe/The Assembly Binding Log Viewer:

The Assembly Binding Log Viewer displays details for assembly binds. This information helps you diagnose why the .NET Framework cannot locate an assembly at run time. These failures are usually the result of an assembly deployed to the wrong location, a native image that is no longer valid, or a mismatch in version numbers or cultures. The common language runtime's failure to locate an assembly typically shows up as a TypeLoadException in your application.

( documentation )

https://stackoverflow.com/questions/58094359/

相关文章:

visual-studio-code - 如何使用 Visual Studio Code + VSC

azure - 作为 Azure DevOps 发布管道的一部分从应​​用服务中删除文件

reactjs - 如何使用带有反应最终形式的自定义 radio 组件?

python - Airflow 外部任务传感器卡​​住

jwt - 将 on_premise_sam_account 属性添加到 Azure 广告的 JWT

react-native - 在 native react 中使用相机捕获方框内的区域

microsoft-graph-api - 更新和删除日历事件而不向与会者发送通知

java - 尝试通过运行 `mvn test` 来运行测试时 JVM 崩溃

php - 未定义的方法 Laravel\Lumen\Application::booted()

ruby-on-rails - 仅导入主文件时,SASS 变量不起作用