Search code examples
c#.net.net-corenuget

Nuget package installed but cannot be imported


I am trying to add a nuget package "Azure.ResourceManager" to an existing project.

Here is the .csproj file:-

<Project Sdk="Microsoft.NET.Sdk">

  <ItemGroup>
    <PackageReference Include="Azure.Identity" Version="1.6.0" />
    <PackageReference Include="Azure.ResourceManager" Version="1.0.0" />
    <PackageReference Include="Azure.ResourceManager.Resources" Version="1.0.0" />
    ....
  </ItemGroup>

</Project>

I ran the nuget restore command on the solution, and I have checked that the package is installed through the Visual Studio Package Manager Console, using command

PM> Find-Package ResourceManager

Id                                  Versions                                 Descriptio
                                                                             n         
--                                  --------                                 ----------
Azure.ResourceManager               {1.0.0}                                  Azure m...
Azure.ResourceManager.Communication {1.0.0}                                  Azure m...
Azure.ResourceManager.Deployment... {1.0.111}                                This pr...
Azure.ResourceManager.Deployment... {1.0.111}                                This pa...

However, when I try to import this package into a class, the type cannot be resolved. enter image description here I wondered if the package and project targeted different versions, so I checked.

Target frameworks supported by package enter image description here Target framework supported by project enter image description here In summary,

As far as I can tell, both project and package support .Net Core 3.1 as a target framework.

Package is installed into project, but cannot be imported into class

Another thing I noticed is that the type "ResourceManager" is being searched for in the "Microsoft.Azure" namespace instead of "Azure"

Looking for any pointers to resolve the issue.


Solution

  • I learnt that the issue was happening because of naming conflicts within the namespace that I was trying to add the import in. There seems to have been another namespace "Azure." within the one I was adding code to. Adding a glocal prefix helped resolve the issue.

    using global::Azure.ResourceManager;