Nuget Package runs into namespace not found

Anush 0 Reputation points
2024-04-09T07:25:46.52+00:00

I have a .NET Android Java Binding Library which has the following specifications

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0-android</TargetFramework>
    <SupportedOSPlatformVersion>21</SupportedOSPlatformVersion>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <Configurations>Release</Configurations>
    <PackageId>CleverTap.DotNet.Android.Binding</PackageId>
    <PackageVersion>1.0.0</PackageVersion>
    <Description>The Clevertap DOTNET Android Binding for Mobile Customer Engagement and Analytics solutions</Description>
    <Authors>CleverTap</Authors>
    <PackageProjectUrl>https://github.com/CleverTap/clevertap-xamarin</PackageProjectUrl>
    <PackageReadmeFile>README.md</PackageReadmeFile>
    <PackageLicenseFile>LICENSE</PackageLicenseFile>
  </PropertyGroup>

I packed this library into a Nuget package.
When I add this package to a .NET android application with following specs, I run into namespace not found error

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0-android</TargetFramework>
    <SupportedOSPlatformVersion>21</SupportedOSPlatformVersion>
    <OutputType>Exe</OutputType>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <ApplicationId>com.companyname.androiddemo2</ApplicationId>
    <ApplicationVersion>1</ApplicationVersion>
    <ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="CleverTap.DotNet.Android.Binding" Version="2.0.0" />
  </ItemGroup>
</Project>

I then added the Clevertap android dependency as an Assembly Reference (using .dll file) which resolved the above error. Following this I removed the assembly reference and then added the Nuget package again and the issue magically went away forever. Seems like some caching issue?

Steps to reproduce

  1. Create a new .NET Android Project
  2. Add CleverTap.DotNet.Android.Binding using nuget
  3. Add using Com.Clevertap.Android.Sdk in MainActivity.cs
  4. Observe the build error

VS Studio version -> Visual Studio for MAC (17.6.10)

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,863 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.