net_automatic_interface icon indicating copy to clipboard operation
net_automatic_interface copied to clipboard

Some automatically generated interfaces cannot reference other automatically generated interfaces

Open AustinGrey opened this issue 9 months ago • 5 comments

Thanks for the amazing package. Saves me so much time.

Some interfaces though I cannot use it on, as it causes other automatically generated interfaces to produce invalid code. Here you can see in a service (which has an autogenerated interface) that I'm trying to reference IProjectDeployment , which is also an autogenerated interface.

Image

If I inspect the interface of the service, you can see it didn't give a full path to the IProjectDeployment interface

Image

If I try to manually specify the global::Path.To.NameSpace etc in front of it, that doesn't change anything. If I change the service method to reference the class ProjectDeployment directly, no issues. And if I manually create the interface in the same file as the class, also no issues.

Is it possible because it's used as a generic argument?

Tried on the latest 5.1.3

AustinGrey avatar Mar 05 '25 15:03 AustinGrey

Can you show your code structure?

Gesendet von Outlook für Androidhttps://aka.ms/AAb9ysg


From: AustinGrey @.> Sent: Wednesday, March 5, 2025 4:51:39 PM To: codecentric/net_automatic_interface @.> Cc: Subscribed @.***> Subject: [codecentric/net_automatic_interface] Some automatically generated interfaces cannot reference other automatically generated interfaces (Issue #73)

Thanks for the amazing package. Saves me so much time.

Some interfaces though I cannot use it on, as it causes other automatically generated interfaces to produce invalid code. Here you can see in a service (which has an autogenerated interface) that I'm trying to reference IProjectDeployment , which is also an autogenerated interface.

image.png (view on web)https://github.com/user-attachments/assets/2270e565-5b1e-4604-b2f8-403181070c94

If I inspect the interface of the service, you can see it didn't give a full path to the IProjectDeployment interface

image.png (view on web)https://github.com/user-attachments/assets/dc2b825b-7944-4384-8c3e-505f104e1f1a

If I try to manually specify the global::Path.To.NameSpace etc in front of it, that doesn't change anything. If I change the service method to reference the class ProjectDeployment directly, no issues. And if I manually create the interface in the same file as the class, also no issues.

Is it possible because it's used as a generic argument?

Tried on the latest 5.1.3

— Reply to this email directly, view it on GitHubhttps://github.com/codecentric/net_automatic_interface/issues/73, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABXKCSONKMTFEQ6ZP3MAYB32S4MQXAVCNFSM6AAAAABYMOCL3OVHI2DSMVQWIX3LMV43ASLTON2WKOZSHA4TONZRHA3DCNA. You are receiving this because you are subscribed to this thread.Message ID: @.***>

[AustinGrey]AustinGrey created an issue (codecentric/net_automatic_interface#73)https://github.com/codecentric/net_automatic_interface/issues/73

Thanks for the amazing package. Saves me so much time.

Some interfaces though I cannot use it on, as it causes other automatically generated interfaces to produce invalid code. Here you can see in a service (which has an autogenerated interface) that I'm trying to reference IProjectDeployment , which is also an autogenerated interface.

image.png (view on web)https://github.com/user-attachments/assets/2270e565-5b1e-4604-b2f8-403181070c94

If I inspect the interface of the service, you can see it didn't give a full path to the IProjectDeployment interface

image.png (view on web)https://github.com/user-attachments/assets/dc2b825b-7944-4384-8c3e-505f104e1f1a

If I try to manually specify the global::Path.To.NameSpace etc in front of it, that doesn't change anything. If I change the service method to reference the class ProjectDeployment directly, no issues. And if I manually create the interface in the same file as the class, also no issues.

Is it possible because it's used as a generic argument?

Tried on the latest 5.1.3

— Reply to this email directly, view it on GitHubhttps://github.com/codecentric/net_automatic_interface/issues/73, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABXKCSONKMTFEQ6ZP3MAYB32S4MQXAVCNFSM6AAAAABYMOCL3OVHI2DSMVQWIX3LMV43ASLTON2WKOZSHA4TONZRHA3DCNA. You are receiving this because you are subscribed to this thread.Message ID: @.***>

ChristianSauer avatar Mar 05 '25 16:03 ChristianSauer

I can't provide the entire project, but here is the structure for the two relevant files?

This is the folder structure on the left, one is in the models folder, and that file contains a this single class with the [GenerateAutomaticInterface] attribute on it.

Image

The service is the DeploymentService, and contains several methods, but only the one referencing the IProjectDeployment is the one that is failing

Image

It might be worth mentioning that the model in question is an EFCore model. So perhaps it's a conflict with EFCore? We do have some other EFCore models being generated from just fine, but this isn't the only model where adding this causes the generated code to be incorrect. There doesn't seem to be a pattern.

AustinGrey avatar Mar 06 '25 19:03 AustinGrey

I try to take a look tomorrow

ChristianSauer avatar Mar 13 '25 14:03 ChristianSauer

Ok, I looked into this and if I see this correctly, you are using multiple Source Generators at the same time?

I think that's the culprit - atm SGs cannot see code from other SGs, so there will be conflicts.

see: https://github.com/dotnet/roslyn/discussions/48358

As a workaround: Put all stuff which uses SG A into a Project, then reference that from a second project which uses SG B.

ChristianSauer avatar May 02 '25 10:05 ChristianSauer

I have had good luck getting around issues like this with a partial interface.

Image

public partial interface IProjectDeployment;

[GenerateAutomaticInterface]
public sealed class ProjectDeployment : IProjectDeployment
{
    public int ProjectId { get; set; }

ChaseFlorell avatar May 11 '25 16:05 ChaseFlorell