[英]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修复。
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
You could wait for MS to fix it -or- fix the broken references yourself: 您可以等待MS修复它 - 或者自己修复损坏的引用:
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.