"Interface id -XXX is not implemented by object XYZ" in Service Fabric
Recently I was working on a Service Fabric project where I was using Service Remoting to communicate from one service to another by using the ServiceProxy
.
While refactoring my services I got the following exception over and over again:
Interface id -103369040 is not implemented by object Codit.MyOtherService
The exception was caused when I was running the following code:
ConditionalResult<string> possibleMyServiceUri = await _configuration.GetMyServiceUriAsync();
if(possibleMyServiceUri.HasValue == true)
{
IMyService myServiceProxy = ServiceProxy.Create<IMyService>(partitionId, possibleMyServiceUri.Value);
IEnumerable<Device> devices = await myServiceProxy.GetDevicesAsync();
}
During the refactoring I added an additional operation to IMyService
but apparently it's looking for it in my IMyOtherService
implementation. Odd.
During debugging I noticed that the problem was in the configuration of my service that was trying to initiate a call by using the proxy. The "culprit" lies in the following line:
ConditionalResult<string> possibleMyServiceUri = await _configuration.GetMyServiceUriAsync();
Do you see it? Neither did I because the problem was in the Settings.xml of the service where the configured URI I was using was fabric:/Codit.Demo/MyOtherService
instead of fabric:/Codit.Demo/MyService
. This caused the runtime to attempt to call a method on a service implementation that didn't implement IMyService
but is an implementation of IMyOtherService
instead.
While this seems like a stupid mistake -and it is- it took me a while to notice it. What I once again learned is that the key to success is in your logging - Log enough to know what's going on but don't over do it.
In my case it's a good idea to add an ETW entry to what configured endpoint I'm remoting so I can detect this misconfigured earlier in the future.
ServiceEventSource.Current.Message($"Remoting to '{possibleMyServiceUri.Value}' for IService".);
Thanks for reading,
Tom.