There’s at least two problems there.
Double definitions of the same object
One of them is to have two Cliente
being the same object. This definition should be canonical, this will cause several problems. Most maintenance difficulties in a software are due to wrong modeling (this one in particular I had never seen). If by chance they would be different things they should never be conflicting. Fix this conceptual error which is the root of the problem and will not have the build error. Don’t try to fix it otherwise because you’ll just be changing the place error (it might even work, but it’ll still be wrong).
Abstraction of the concrete
The other mistake is to use one cast, Almost every time you do this is because you modeled it wrong (most of the exceptions are because of the legacy since .NET modeled some things wrongly in the first version). If you really need to make one cast is because you’re getting the wrong guy, so get the Cliente
and not the ICliente
. Is making a cast to access other members, so the interface you need to access is not the object, so the parameter should be the class and not the interface.
I won’t even tell you to use the namespace correct to catch the Cliente
correct for this case because it would still keep the error of having the same object defined twice in different places.
Interface
This is wrong use of interface, because interface are capabilities of an object so something that calls ICliente
is not a capacity is the definition of an object, perhaps it was the case to use an abstract class (unfortunately rarely have good answers about it here).
I strongly suggest studying further (with depth, not just the surface) what an interface is and why to use it, here are some good answers about this (others not so much, especially on the internet has a lot of bad content that desensina, I do not know why people think that everything that is on the internet is reliable and sometimes question reliable sources).
You must accept an interface when only you need to access your members when you need to access other members then: or you need another interface; or you need to access the whole object; or you need to expand what the interface has, which is even scary to say this because in this case it would probably be another error.
Note that they are compatible while you use the interface, when you decide to do the cast is that it gives problem, but the problem is lower as it is said above.
Did you notice that you only created the interface to "group" two objects that are actually one? This interface should not even exist if it had not created two classes to represent the same object.
Conceptualization
I always say that object orientation is difficult, and one of the reasons is because it’s not about mechanisms like interface use, it’s about modeling right and it’s not usually taught anywhere and without the concrete case almost always the person does wrong (you can’t follow cake recipes). That is why it is common to have "work", is fixing the modeling errors.
The model should be unique, canonical, DRY, including to facilitate maintenance. It makes no sense to have one thing in what you call "application" and another in what you call "DLL", because this DLL is part of the application. Putting penduricalho in the application will not solve the problem, just make it more complicated.
You can see that there are other misconceptions looking at just this stretch, imagine seeing all the application. No correct concepts or misses without realizing or hits by coincidence.
So there must be several other problems that do not cause errors in the build. Working is different than being right.
What exactly wasn’t clear, @Maniero?
– AlexQL
His answer shows that the question had nothing to do with what he wanted.
– Maniero
The answer (in my view) shows the conceptual error I was making when trying to reconcile two different classes. The solution to my problem was to use dependency injection (which before I had only heard of) to get the result I expected.
– AlexQL
This has nothing to do with DI, the answer doesn’t talk about your problem, and it just shows that you don’t understand the problem yet, besides your answer doesn’t help anyone, not even yourself, even if you think so.
– Maniero
Maniero, it’s already in place. I have an application that uses a DLL as a type of "data access plugin" using dependency injection to maintain. The application calls the DLL and the DLL returns the data according to the contract of the interfaces involved. In my view, this solved (and really this, because the program is here in my notebook running). Why do you think it has nothing to do with DI? Is there another more correct way to do this? If you have, give me a hint.
– AlexQL
I answer, you ignored it. You found your solution and if it is only you could say something about it, hence the question is not clear. Any posted answer may be right or wrong, no one knows what the real doubt is (maybe only you, maybe not you), I could only be sure of that after posting the answer.
– Maniero
Let’s go continue this discussion in chat.
– AlexQL