Henry Zhu
Henry Zhu

Reputation: 2618

Microsoft Azure C#: The type or namespace 'Cosmos' does not exist in the workspace 'Microsoft.Azure'

I am trying to read a Cosmos DB within my Azure C# v2 Function. In order to do so, I need the following import:

using Microsoft.Azure.Cosmos;

However, I receive the following error:

Using directive is unnecessary. The type or namespace 'Cosmos' does not exist in the namespace 'Microsoft.Azure' (are you missing an assembly reference)?

This seems strange, considering that I have already added the package view the dotnet CLI:

C:\Users\t-henzhu\Documents\AccessChangeMonitoring\AccessChangeMonitoring>dotnet add package Microsoft.Azure.Cosmos --version 3.11.0
Determining projects to restore...
Writing C:\Users\t-henzhu\AppData\Local\Temp\tmp529E.tmp
info : Adding PackageReference for package 'Microsoft.Azure.Cosmos' into project 'C:\Users\t-henzhu\Documents\AccessChangeMonitoring\AccessChangeMonitoring\AccessChangeMonitoring.csproj'. info : Restoring packages for C:\Users\t-henzhu\Documents\AccessChangeMonitoring\AccessChangeMonitoring\AccessChangeMonitoring.csproj... info : CACHE https://api.nuget.org/v3-flatcontainer/microsoft.azure.webjobs.host.storage/index.json warn : Microsoft.Azure.WebJobs.Extensions 3.0.5 depends on Microsoft.Azure.WebJobs.Host.Storage (>= 3.0.11) but Microsoft.Azure.WebJobs.Host.Storage 3.0.11 was not found. An approximate best match of Microsoft.Azure.WebJobs.Host.Storage 3.0.13 was resolved.
info : Package 'Microsoft.Azure.Cosmos' is compatible with all the specified frameworks in project 'C:\Users\t-henzhu\Documents\AccessChangeMonitoring\AccessChangeMonitoring\AccessChangeMonitoring.csproj'. info : PackageReference for package 'Microsoft.Azure.Cosmos' version '3.11.0' updated in file 'C:\Users\t-henzhu\Documents\AccessChangeMonitoring\AccessChangeMonitoring\AccessChangeMonitoring.csproj'. info : Committing restore...
info : Writing assets file to disk. Path: C:\Users\t-henzhu\Documents\AccessChangeMonitoring\AccessChangeMonitoring\obj\project.assets.json log : Restored C:\Users\t-henzhu\Documents\AccessChangeMonitoring\AccessChangeMonitoring\AccessChangeMonitoring.csproj (in 525 ms).

Upvotes: 0

Views: 1627

Answers (1)

Matias Quaranta
Matias Quaranta

Reputation: 15603

Is this a solution with a single project or do you have multiple projects and are using project references?

If this is the case, are you adding the package to all projects that will use it? On the SDK we have a sample Function App project that uses the V3 SDK (Microsoft.Azure.Cosmos) and works: https://github.com/Azure/azure-cosmos-dotnet-v3/tree/master/Microsoft.Azure.Cosmos.Samples/Usage/AzureFunctions

Upvotes: 1

Related Questions