Search code examples
c#xamarinxamarin.formsfody

Namespace cannot be found for installed package after building


I'm trying to use a method interceptor so I can run a method before certain marked methods in my Xamarin app. I installed Fody from the NuGet Package Manager, then downloaded MethodBoundaryAspect.Fody.

When creating my method interceptor class, the namespaces appear and the autocomplete works:

enter image description here

As soon as I try to build the solution and run it on the emulator, it fails gives me these errors:

enter image description here

And then in my class, it says that "The type or namespace 'MethodBoundaryAspect' could not be found", even though it was fine before I tried building the app:

enter image description here

Where have I gone wrong here? I'm open to using other open source method interceptors.


Solution

  • This seems to be a bug in the weaver. We had the same issue in our project (albeit not Xamarin, but WPF with CPS) and resolved it with the workaround from the linked issue:

    Open your csproj file and change the package import from

    <PackageReference Include="MethodBoundaryAspect.Fody" Version="1.0.66">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
    </PackageReference>
    

    to just

    <PackageReference Include="MethodBoundaryAspect.Fody" Version="1.0.66" />