![](/img/trans.png)
[英]Type or namespace name could not be found (missing using directive or assembly reference?)
[英]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修復它 - 或者自己修復損壞的引用:
您還可以通過打開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.