adding a maui class library to maui project - fails to find reference to a method when compiling

Ryan Lee 20 Reputation points
2025-01-18T14:09:25.53+00:00

Hi,

I am using VS 2022, net 9.0

I have a Maui App project with a reference to Maui Class Library project.

The reference is loaded correctly and I can reference the method in MauiProgram.cs, ( can do right click and go to implementation)

I have set the target framework of the Maui App Project as net9.0-android;net9.0;net9.0-ios

Every time compile the Project, it comes up with a message saying

IServiceCollection' does not contain a definition for 'RegisterBaseClient' and no accessible extension method 'RegisterBaseClient' accepting a first argument of type 'IServiceCollection' could be found (are you missing a using directive or an assembly reference?)

I have files are being generated inside the Maui Class Library Project's bin folder without any issues.

I see .pdb file and .dll files under all 3 platforms.

RegisterBaseClient is a extension method in the Class Library.

public static IServiceCollection RegisterBaseClient(this IServiceCollection services, Action<ApiClientOptions> clientOptions)

{

ApiClientOptions options = new();

clientOptions.Invoke(options);

services.AddSingleton(options);

services.RegisterApiServices();

return services;

}

And this is how I use in Mauiprogram.cs

builder.Services.RegisterBaseClient(opt =>

{

opt.Authority = "https://10.0.2.2:5001";

opt.BaseUrl = "https://10.0.2.2:6001";

opt.ClientId = "com.companyname.mauiapp5";

opt.RedirectUri = "maui://authcallback";

opt.Scope = "openid profile api1";

});

Is there anything extra that I have to do to make this work?

Please advise you if need more info and thank you very much in advance!

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,834 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 69,501 Reputation points
    2025-01-18T17:20:35.08+00:00

    Be sure there is a using statement for the namespace of the extension method.

    0 comments No comments

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.