Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ProxyTypesAssemblyAttribute is generated multiple times on each entity class #408

Closed
jarvan-jiang opened this issue Apr 23, 2023 · 12 comments
Labels

Comments

@jarvan-jiang
Copy link

Tool and Version
What tool/version is it that you're reporting a bug for? i.e.
EarlyBoundGenerator V 2.2023.4.17

Describe the bug
When use generator V2, and set 'Create one file per entity' to true, the class is generated correctly, but each class file contains
[assembly: Microsoft.Xrm.Sdk.Client.ProxyTypesAssemblyAttribute()]
And this lead to compiler error CS0579.

To Reproduce
Steps to reproduce the behavior:

  1. open EarlyBoundGenerator V2
  2. set 'Create one file per entity'
  3. generate

Expected behavior
Entity class generated and able to compile success.

Screenshots
image

Additional context
Add any other context about the problem here.

@jarvan-jiang
Copy link
Author

After looking at code, seems the logic of PacModelBuilderCodeGenHack when generating code is fine, the SplitFilesByObject is set default as true so all the single class will not have proxy type attribute.
However, after that there are some paragraph seems processing merge or split, will call WriteFileWithoutCustomizations, it will re-add the proxy type attribute to all files.
If I understand correctly, we have added the proxy type attribute to service context, therefore there is no need to re-add it to any class except the service context is not provided(which you already have a section to handle that remind user to added it manually, also there seems have a small issue on that).

Based on above investigation, I think the default value of parameter writeProxyAttrib in WriteFileWithoutCustomizations should be false instead of true. I have created a PR, please kindly look at it if I misunderstand some stories.

@daryllabar
Copy link
Owner

Just looking at the code, I agree your code fix looks like a it will solve your problem. What I don't understand is why I'm not having the same problem. Any chance you can send me your builderSettings.json file? It should be in the same directory as your DLaB.EarlyBoundGenerator.Settings.xml file. I'd like to test why this is failing for, to make sure I don't break something else with your fix.

@jarvan-jiang
Copy link
Author

Sure, I removed some sensitive names and namespace, but the settings are same as I'm using.
builderSettings - Copy.zip

@daryllabar
Copy link
Owner

Thank you! I was able to determine that the issue you're experience is due to you having separate files for entities, but not for OptionSets. Fix has been pushed to nuget, will push to the XTB soon

@daryllabar
Copy link
Owner

2.2023.4.24 should be pushed

@jarvan-jiang
Copy link
Author

Appreciate your quick action!

@daryllabar
Copy link
Owner

And I appreciate getting the JSON file and for spending the time to do a PR!

@JepperJay
Copy link

Hi
I have sort of the same issue using 2.2023.4.24.
When I generate a single file for entities and a single file for optionsets, both the service context and the file with the entities contains [assembly: Microsoft.Xrm.Sdk.Client.ProxyTypesAssemblyAttribute()]

@daryllabar
Copy link
Owner

@JepperJay can you send me your builder settings Json file?

@JepperJay
Copy link

Here you go, and thanks a lot
builderSettings.zip

@daryllabar
Copy link
Owner

@jarvan-jiang You are setup to not create a service context, do you manually add your own Microsoft.Xrm.Sdk.Client.ProxyTypesAssemblyAttribute()? Or do you just not have one at all?

@jarvan-jiang
Copy link
Author

jarvan-jiang commented Aug 11, 2023

@jarvan-jiang You are setup to not create a service context, do you manually add your own Microsoft.Xrm.Sdk.Client.ProxyTypesAssemblyAttribute()? Or do you just not have one at all?

Sorry just saw it now...
I manually add it in other place, if setup to not create service context, there will no one at all.
At that time, the code logic looks like, if I'm not going to create a service context, then no attribute will be generated, instead an alert will appeared to user, says that you need add the attribute by yourself. However, the decompile code seems went wrong, the alert branch will never be hit.
That's why I try to modify it in my PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants