Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The type or namespace MongoServer could not be found

Tags:

c#

mongodb

azure

Referencing this Azure Tutorial, https://azure.microsoft.com/en-us/documentation/articles/web-sites-dotnet-store-data-mongodb-vm/, released three months ago and already apparently out of date.

I followed the instructions, copied the code but am unable to build the application with this error: CS0246 the type or namespace MongoServer could not be found Dal.cs line 13.

Azure support responds "If a type or namespace is not available, it’s generally because of a missing assembly or DLL.". Agreed, but there is no missing assembly or dll. I suspect the API has changed but can find no documentation in support of this suspicion. I am therefore unable to resolve the issue.

enter image description here

I've included a screenshot showing the relevant assembly is installed.

I originally suspected the MongoDb.driver API had changed. The example uses version 2.0.1 and I had installed the latest, 2.2.4. However, after uninstalling the latest version and installing version 2.0.1 I get three errors, the original plus two others. I'm left wondering, how was this code originally built?

like image 799
lynnjwalker Avatar asked Jun 08 '16 23:06

lynnjwalker


3 Answers

I learned through the MSDN Forums that I need to use the MongoDb.Driver.Legacy version, which can be installed through the Nuget Management Console with this command:

Install-Package mongocsharpdriver

The project now builds without error.

like image 159
lynnjwalker Avatar answered Oct 25 '22 02:10

lynnjwalker


This is because you have installed an older version. Please go to Nuget Package console manager and reinstall the Mongocsharp Driver.

Install-Package mongocsharpdriver

After installing build the solution.

like image 20
Debendra Dash Avatar answered Oct 25 '22 03:10

Debendra Dash


Just update the class to MongoClient and it is solved :)

http://mongodb.github.io/mongo-csharp-driver/2.3/getting_started/quick_tour/

like image 44
Henrik Andersen Avatar answered Oct 25 '22 02:10

Henrik Andersen