Be sure there is a using statement for the namespace of the extension method.
adding a maui class library to maui project - fails to find reference to a method when compiling
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!