繁体   English   中英

缺少程序集引用和/或指令“找不到类型或命名空间名称”

[英]Missing assembly references and/or directives “The type or namespace name could not be found”

参考这个Azure Cosmos Db教程( https://docs.microsoft.com/en-us/azure/cosmos-db/create-mongodb-dotnet ),三个月前发布,显然已经过时了。

我按照说明操作:克隆了示例应用程序文件,更新了我的连接字符串,通过Nuget包管理器安装了MongoDB.Driver并运行了应用程序。 由于2个应用程序文件中存在多个CS0246和CS0234错误,因此构建(在Visual Studio 2017中)失败。 见截图

这里

我不是C#开发人员。 我怀疑MongoDB API已经改变或者MongoDB.Driver已经过时了。 该错误意味着缺少指令或程序集引用。

无论哪种方式,这是由微软而不是我编写的底层应用程序文件中的问题。 在此处查看截图。 有没有人对如何解决这些错误并成功运行应用程序有任何建议? 也许我需要安装较旧的MongoDB.Driver旧版本?

我从https://github.com/Azure-Samples/azure-cosmos-db-mongodb-dotnet-getting-started/archive/master.zip下载了示例应用程序,它目前确实处于不一致状态,应该是由MS修复。

问题

项目引用无法找到的dll:

在此输入图像描述

原因是要求Nuget下载MongoDB.BSon 2.6.1,但项目引用正在搜索2.3.0文件夹。

    <Reference Include="MongoDB.Driver, Version=2.3.0.157, Culture=neutral, processorArchitecture=MSIL">
      <HintPath>..\packages\MongoDB.Driver.2.3.0\lib\net45\MongoDB.Driver.dll</HintPath>
      <Private>True</Private>
    </Reference>
    <Reference Include="MongoDB.Driver.Core, Version=2.3.0.157, Culture=neutral, processorArchitecture=MSIL">
      <HintPath>..\packages\MongoDB.Driver.Core.2.3.0\lib\net45\MongoDB.Driver.Core.dll</HintPath>
      <Private>True</Private>
    </Reference>
    <Reference Include="MongoDB.Driver.Legacy, Version=2.3.0.157, Culture=neutral, processorArchitecture=MSIL">
      <HintPath>..\packages\mongocsharpdriver.2.3.0\lib\net45\MongoDB.Driver.Legacy.dll</HintPath>
      <Private>True</Private>
    </Reference>

我向MS报告了这个问题,你可以在这里跟踪它: https//github.com/MicrosoftDocs/azure-docs/issues/28204

修复

您可以等待MS修复它 - 或者自己修复损坏的引用:

  1. 删除无效的MongoDB。*程序集引用。
  2. 从nuget下载的文件夹中读取引用:
    • .. \\包\\ MongoDB.Bson.2.6.1 \\ LIB \\ net45 \\ MongoDB.Bson.dll
    • .. \\包\\ MongoDB.Driver.2.6.1 \\ LIB \\ net45 \\ MongoDB.Driver.dll
    • .. \\包\\ MongoDB.Driver.Core.2.6.1 \\ LIB \\ net45 \\ MongoDB.Driver.Core.dll
  3. 编译验证

您还可以通过打开MyTaskListApp.csproj文件并在其中进行编辑来简化上述过程:

<Reference Include="MongoDB.Bson">
  <HintPath>..\packages\MongoDB.Bson.2.6.1\lib\net45\MongoDB.Bson.dll</HintPath>
</Reference>
<Reference Include="MongoDB.Driver">
  <HintPath>..\packages\MongoDB.Driver.2.6.1\lib\net45\MongoDB.Driver.dll</HintPath>
</Reference>
<Reference Include="MongoDB.Driver.Core">
  <HintPath>..\packages\MongoDB.Driver.Core.2.6.1\lib\net45\MongoDB.Driver.Core.dll</HintPath>
</Reference>

感谢您的反馈意见。 这是csproj文件中的一个问题。 已经提出了拉取请求。 您可以参考拉取请求来检查ETA以获取此修复。

https://github.com/Azure-Samples/azure-cosmos-db-mongodb-dotnet-getting-started/pull/8

希望能帮助到你。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM