简体   繁体   English

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

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

Referencing this Azure Cosmos Db Tutorial ( https://docs.microsoft.com/en-us/azure/cosmos-db/create-mongodb-dotnet ), released three months ago and apparently already out of date. 参考这个Azure Cosmos Db教程( https://docs.microsoft.com/en-us/azure/cosmos-db/create-mongodb-dotnet ),三个月前发布,显然已经过时了。

I followed the instructions: cloned the sample app files, updated my connection string, installed the MongoDB.Driver through the Nuget package manager and ran the app. 我按照说明操作:克隆了示例应用程序文件,更新了我的连接字符串,通过Nuget包管理器安装了MongoDB.Driver并运行了应用程序。 The build (in Visual Studio 2017) failed due to several CS0246 & CS0234 errors in 2 of the app files. 由于2个应用程序文件中存在多个CS0246和CS0234错误,因此构建(在Visual Studio 2017中)失败。 See screenshot 见截图

这里

I'm not a C# developer. 我不是C#开发人员。 I suspect either the MongoDB API has changed or the MongoDB.Driver is out of date. 我怀疑MongoDB API已经改变或者MongoDB.Driver已经过时了。 The error implies a directive or assembly reference is missing. 该错误意味着缺少指令或程序集引用。

Either way, this is an issue in the underlying app files which were written by Microsoft and not me. 无论哪种方式,这是由微软而不是我编写的底层应用程序文件中的问题。 See screenshot here. 在此处查看截图。 Does anyone have any recommendations on how I can troubleshoot these errors and successfully run the app? 有没有人对如何解决这些错误并成功运行应用程序有任何建议? Maybe I need to install an older legacy version of MongoDB.Driver? 也许我需要安装较旧的MongoDB.Driver旧版本?

I downloaded the sample app from https://github.com/Azure-Samples/azure-cosmos-db-mongodb-dotnet-getting-started/archive/master.zip and it is currently indeed in an inconsistent state and it should be fixed by MS. 我从https://github.com/Azure-Samples/azure-cosmos-db-mongodb-dotnet-getting-started/archive/master.zip下载了示例应用程序,它目前确实处于不一致状态,应该是由MS修复。

The problem 问题

Project references dlls which cannot be found: 项目引用无法找到的dll:

在此输入图像描述

The cause is that Nuget is asked to download MongoDB.BSon 2.6.1, but project references are searching the 2.3.0 folders. 原因是要求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>

I reported the issue to MS, you can track it here: https://github.com/MicrosoftDocs/azure-docs/issues/28204 我向MS报告了这个问题,你可以在这里跟踪它: https//github.com/MicrosoftDocs/azure-docs/issues/28204

The fix 修复

You could wait for MS to fix it -or- fix the broken references yourself: 您可以等待MS修复它 - 或者自己修复损坏的引用:

  1. Remove the invalid MongoDB.* assembly references. 删除无效的MongoDB。*程序集引用。
  2. Readd the references from folders nuget has downloaded: 从nuget下载的文件夹中读取引用:
    • ..\\packages\\MongoDB.Bson.2.6.1\\lib\\net45\\MongoDB.Bson.dll .. \\包\\ MongoDB.Bson.2.6.1 \\ LIB \\ net45 \\ MongoDB.Bson.dll
    • ..\\packages\\MongoDB.Driver.2.6.1\\lib\\net45\\MongoDB.Driver.dll .. \\包\\ MongoDB.Driver.2.6.1 \\ LIB \\ net45 \\ MongoDB.Driver.dll
    • ..\\packages\\MongoDB.Driver.Core.2.6.1\\lib\\net45\\MongoDB.Driver.Core.dll .. \\包\\ MongoDB.Driver.Core.2.6.1 \\ LIB \\ net45 \\ MongoDB.Driver.Core.dll
  3. Compile to verify 编译验证

You can also simplify the above process by just opening MyTaskListApp.csproj file and making the edits there: 您还可以通过打开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>

Thanks for your feedback. 感谢您的反馈意见。 This is an issue in the csproj file. 这是csproj文件中的一个问题。 For which pull request has already been raised. 已经提出了拉取请求。 You can refer the pull request to check the ETA for this fix. 您可以参考拉取请求来检查ETA以获取此修复。

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

Hope it helps. 希望能帮助到你。

暂无
暂无

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

相关问题 找不到类型或名称空间名称(缺少使用指令或程序集引用吗?) - Type or namespace name could not be found (missing using directive or assembly reference?) 在全局名称空间中找不到类型或名称空间名称“名称空间”(您是否缺少程序集引用?) - The type or namespace name '“Namespace”' could not be found in the global namespace (are you missing an assembly reference?) 在全局命名空间中找不到类型或命名空间名称“”Namespace“(您是否缺少程序集引用?) - The type or namespace name '“Namespace”' could not be found in the global namespace (are you missing an assembly reference?) 当引用或使用指令中包含“类型或名称空间&#39;名称&#39;时丢失” - “The type or namespace 'name' is missing” when it is included in references and using directives 我收到错误消息“在全局名称空间中找不到类型或名称空间名称&#39;CS&#39;(您是否缺少程序集引用?)” - I'm getting error “The type or namespace name 'CS' could not be found in the global namespace (are you missing an assembly reference?)” 找不到类型或名称空间名称“ My_Interface_Name”(您是否缺少using指令或程序集引用?) - The type or namespace name 'My_Interface_Name' could not be found (are you missing a using directive or an assembly reference?) 找不到类型或名称空间名称“ MySql”(您是否缺少using指令或程序集引用?)c#VS 2013 - The type or namespace name 'MySql' could not be found (are you missing a using directive or an assembly reference?) c# VS 2013 如何修复“找不到类型或名称空间名称“ PlayerManager”(您是否缺少using指令或程序集引用? - how to fix 'The type or namespace name 'PlayerManager' could not be found (are you missing a using directive or an assembly reference? c#错误1找不到类型或名称空间名称”(是否缺少using指令或程序集引用?) - c# Error 1 The type or namespace name '' could not be found (are you missing a using directive or an assembly reference?) 找不到类型或名称空间名称“ PROJECTNAME”(您是否缺少using指令或程序集引用? - The type or namespace name 'PROJECTNAME' could not be found (are you missing a using directive or an assembly reference?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM