缺少程序集引用 and/or 指令 "The type or namespace name could not be found"
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 已过时。该错误表示缺少指令或程序集引用。
无论哪种方式,这是由 Microsoft 而不是我编写的底层应用程序文件中的问题。请在此处查看屏幕截图。有没有人对我如何解决这些错误并成功 运行 应用程序有任何建议?也许我需要安装旧版 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 修复它 - 或者 - 自己修复损坏的引用:
- 删除无效的 MongoDB.* 程序集引用。
- 从 nuget 下载的文件夹中读取引用:
- ..\packages\MongoDB.Bson.2.6.1\lib\net45\MongoDB.Bson.dll
- ..\packages\MongoDB.Driver.2.6.1\lib\net45\MongoDB.Driver.dll
- ..\packages\MongoDB.Driver.Core.2.6.1\lib\net45\MongoDB.Driver.Core.dll
- 编译验证
您也可以通过打开 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 文件中的问题。已经提出了拉取请求。
您可以参考拉取请求以检查此修复的预计到达时间。
https://github.com/Azure-Samples/azure-cosmos-db-mongodb-dotnet-getting-started/pull/8
希望对您有所帮助。
引用此 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 已过时。该错误表示缺少指令或程序集引用。
无论哪种方式,这是由 Microsoft 而不是我编写的底层应用程序文件中的问题。请在此处查看屏幕截图。有没有人对我如何解决这些错误并成功 运行 应用程序有任何建议?也许我需要安装旧版 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 修复它 - 或者 - 自己修复损坏的引用:
- 删除无效的 MongoDB.* 程序集引用。
- 从 nuget 下载的文件夹中读取引用:
- ..\packages\MongoDB.Bson.2.6.1\lib\net45\MongoDB.Bson.dll
- ..\packages\MongoDB.Driver.2.6.1\lib\net45\MongoDB.Driver.dll
- ..\packages\MongoDB.Driver.Core.2.6.1\lib\net45\MongoDB.Driver.Core.dll
- 编译验证
您也可以通过打开 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 文件中的问题。已经提出了拉取请求。 您可以参考拉取请求以检查此修复的预计到达时间。
https://github.com/Azure-Samples/azure-cosmos-db-mongodb-dotnet-getting-started/pull/8
希望对您有所帮助。