Class Method is Not Invoking
# help-with-umbraco
j
Hi, I've been refactoring and upgrading our Umbraco website from V9 to V11, and the last piece that I'm having troubles with, has had me stuck for weeks. I'm still getting up to speed on .Net Core (7), FYI, but am pretty decent at understanding changes. The following Method just doesn't get hit during debugging. I have added a transient in the Startup for the interface and Class, and it'll hit the constructor, but when I go to call the "GetFedExRates()" method, it just doesn't do it. Do I have DI setup wrong maybe? Left off latter part of function due to character max.
Copy code
public class AjaxController : SurfaceController {

        private IShippingMethodSelector _shippingMethodSelector;
        public AjaxController(
               IUmbracoContextAccessor umbracoContextAccessor,
            IUmbracoDatabaseFactory databaseFactory,
            ServiceContext services,
            AppCaches appCaches,
            IProfilingLogger profilingLogger,
            IPublishedUrlProvider publishedUrlProvider,
            IShippingMethodSelector shppingMethodSelector)
            : base(umbracoContextAccessor, databaseFactory, services, appCaches, profilingLogger, publishedUrlProvider) {
            _shippingMethodSelector = shppingMethodSelector;
            }

 
                if (matches.Count > 0) {
            This returns null, and doesn't hit method breakpoint   ---->>     
methods = _shippingMethodSelector?.GetFedExInternationalShippingMethods(new AddressModel() { Country = countryCode, PostalCode = postalCode }, zone));
                    }
                }
...
d
Hi there! A little sanity check: are you building and debugging your app in debug mode? Or have you set it to release mode? Some breakpoints might be optimized away in release mode.
m
If it doesn't hit the method breakpoint, are you sure that _shippingMethodSelector isn't null, as you're using a null propagation check over there.
s
Also, is there a need for this to be a
SurfaceController
the method name makes me suspect this should be an Web API controller - https://docs.umbraco.com/umbraco-cms/reference/routing/umbraco-api-controllers But yes, looks like
_shippingMethodSelector
is null probably because it's not registered, you should have something like this somewhere:
Copy code
csharp
public class RegisterServices : IComposer
{
    public void Compose(IUmbracoBuilder builder)
    {
        builder.Services.AddSingleton<IShippingMethodSelector, ShippingMethodSelector>();
    }
}
j
Thanks for replies! It does hit other breakpoints, and I have it registered in using that exact RegisterServices class, and I can see it go through the constructor, as it's instantiated, but then once it gets to that line, it doesn't invoke the GetFedExInternationalShippingMethods method. I'm using a SurfaceController due to trying to get the website upgraded and ready to move to UmbracoCloud, but I'll look at the Web API docs linked.
d
Where does this
IShippingMethodSelector
service live in relation to your umbraco application? Is it in the main application or do you reference it from a dll or do you have a separate class library and a project reference? It could be that you have some old dll somewhere stuck in your bin folder. It's also worth trying to remove your bin and obj folders on all your projects inside your solution and then rebuild. If you have some old dll stuck somewhere, it can cause some very nasty unexpected behaviour
j
That makes sense because I tried to use it as a standalone project (.net standard), and decided to try and do what I needed to upgrade it for the same Umbraco project. I'll try your suggestion of removing the bin and obj folders etc. Thanks.