daver32/InterfaceGenerator

Help needed: how can get the errors from the analyzer

Closed this issue · 6 comments

edtro commented

Hi,
Possibly I have overlooked something, but I need some help getting started to start using this project (because I think the concept is really great).

I have added the Nuget package to a NET6 class library project and added the GenerateAutoInterface attribute to my class, but VS cannot find any reference.

Within the readme an other project net_automatic_interface is mentioned, There you need to add the code for the attribute manually.

Do you also need to do this for this project?

Or is NET6 not supported?

Kr
Edward

edtro commented

Hi,
I have managed to get the basics.
But I want to apply this to a generated partial class (generated by Swashbuckle).

So this is the setup:

  • a generated file called client.designer.cs with MyRestApiClient defined within this file as partial (with all the source code).
  • a manually created file called client.cs with also MyRestApiClient defined as partial, but with no code,
    (this works with the refactoring > extract interface... but I want to automate this process)

To the last file I want to add the GenerateAutoInterface attribute.... strange thing is, when I add the line using InterfaceGenerator before anything else, it detects the reference. Within the analyzer I can see the generated attribute.

But after adding the attribute, it breaks,

Within the analyzer I just see a message that it does not generates any code.

So I have adjusted my question... how can get the errors from the analyzer?

Kr
Edward

Hey,

I don't know of a general way to extract an exception from the generator, except for running dotnet build which doesn't output a stack trace. I've released a new version which should output the exception as a diagnostic error. Can you get a stack trace if you upgrade to 1.0.10?

edtro commented

Hi,
This has brought me a couple steps further.

Now I can add the attribute, the interface is generated and I can reference the interface.

But after a (re)build of the project, I am getting the following error:

InterfaceGenerator.CriticalError : System.ArgumentException The hintName 'MyClient_AutoInterface.cs' of the added source file must be unique within a generator.

I have googled the error message, and found this: dotnet/roslyn#42628. So I have already tried to set the env variable MSBUILDDISABLENODEREUSE=1 but did not do solve the problem.

Kr
Edward

Hey, thanks for the PR!

What's confusing is that I can't even reproduce your original issue. In the latest version I've added a test to try and get an error using partial classes, but it generates an interface just fine. If your layout is somehow different from the one in the test, please let me know so I can add a test case for it. Anyway, your PR solves another corner case where 2 different classes are named exactly the same, but are still valid because they exist in different namespaces, so thank you!

edtro commented

Hi,
Will try it tomorrow morning :-)

edtro commented

I have re-tested it with the new package version, and it is working :-)