#1 2023-05-09 08:45:18

larand54
Member
Registered: 2018-12-25
Posts: 104

At client startup - Interface not found fInterfaces.FindHashed(aUri)

Suddenly my testclient crashed at start with an access violation in this call: "HttpClient.Services[DHS_LOCAL_CONTRACT].Get(fDHS_LocalService);"
Debugging showed that the function "fInterfaces.FindHashed(aUri)" returns -1.

I've just added a method to the interface, recompile both the server and client and then this happened. I also removed those changes but still the same problem.
Something else must have been changed but I can't imagine what it could be.

I need some idea of where to start looking. sad


Delphi-11, WIN10

Offline

#2 2023-05-09 09:04:47

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,655
Website

Re: At client startup - Interface not found fInterfaces.FindHashed(aUri)

The fact that the problem remains after removing the interface seems to show that the problem is not the interface name hashing, but something else.

What does fInterfaces.Count return ?
Is aUri (DHS_LOCAL_CONTRACT) part of the fInterface[] array ?

Can you try to reproduce with a RawUtf8 list of interface names, without any service process?
I doubt it is a TDynArrayHashed bug... but we have to be sure of that.

Verify that TServiceContainerClientAbstract.AddInterface is properly called in your code, before the Get(DHS_LOCAL_CONTRACT) call.

Offline

#3 2023-05-09 10:51:41

larand54
Member
Registered: 2018-12-25
Posts: 104

Re: At client startup - Interface not found fInterfaces.FindHashed(aUri)

To make a simple test client I added the following code:

procedure TForm4.FormCreate(Sender: TObject);
begin
  Model := TOrmModel.Create([],SYSTEMLocalROOT);
  HttpClient := TRestHttpClient.Create(IP_Local, HTTP_PORT, Model);
  HttpClient.ServiceDefine([IDHSLocalService], sicShared, DHS_LOCAL_CONTRACT);
  HttpClient.Services[DHS_LOCAL_CONTRACT].Get(fDHS_LocalService);
end;

In the function "TServiceContainerClientAbstract" the parameter aInterfaces contains one interface "IDHSLocalService" which is correct here. I' only use one interface so far.


The call "fHash.FindOrNew(fHash.HashOne(@Item), @Item, nil);" with Item as 'DHS_LOCAL_CONTRACT' returns -161.
This lead to that he interface pointer will be nil.
I'm not sure how to reproduce with a RawUTF8 list of interface. Where should I put the call?


Delphi-11, WIN10

Offline

#4 2023-05-09 12:04:52

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,655
Website

Re: At client startup - Interface not found fInterfaces.FindHashed(aUri)

You are making a confusion with the contract and the interface name.

It is the interface name, not the contract value, i.e. you should wreite Services['IDHSLocalServer].
But don't mess with the service name.
Just use Services.Resolve(IDHSLocalService).

Offline

#5 2023-05-09 12:05:29

larand54
Member
Registered: 2018-12-25
Posts: 104

Re: At client startup - Interface not found fInterfaces.FindHashed(aUri)

Sorry, I found the problem. It's of course my mistake. I misunderstood the usage of the parameter "ContractExpected". It looks like it should have the same name as the service without the leading 'T'. I got the impression of that this parameter is used to make it possible of same version control of the interface. So if you add a new or changed a method you could change this parameter and in that way you get a signal if you have different versions between client and server.

Strange is that I'm sure I had a different name for this parameter from the beginning without any problem.

Sorry I bothered you with this.
Best regards
Lars-G.

Last edited by larand54 (2023-05-09 12:11:37)


Delphi-11, WIN10

Offline

#6 2023-05-09 12:26:22

larand54
Member
Registered: 2018-12-25
Posts: 104

Re: At client startup - Interface not found fInterfaces.FindHashed(aUri)

Oh, I got your answer while I was writing.

Yea, I can see now!

Maybe I was not completely wrong about the parameter..?
I took the code from an example just to get a kickstart for testing.
I should be more careful.

Thank's a lot!


Delphi-11, WIN10

Offline

Board footer

Powered by FluxBB