-
Notifications
You must be signed in to change notification settings - Fork 15.6k
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
Fix ArgumentException in C# when any proto file with extension is imported multiple times #6954
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
@googlebot I signed it! |
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
8260d46
to
af1416f
Compare
@owt5008137 how is this fix different than #6938 (it looks like it's fixing exactly the same thing)? |
Yes these two PR fix the same problem. For example, when build This PR will remove the duplicated depened file first ( Finally, I think it's better to use a |
#6938 has been merged. If you still want to proceed with this PR, please rebase on top of freshest master and try to align your stuff with what's been done there. |
46e5f17
to
42e7d9f
Compare
I have rebase onto the newest master branch with #6938 and remove all redundant codes and tests now and just keep the code to remove repeated depended files. Could you review it? @jtattermusch |
…ded. Key: Google.Protobuf.ObjectIntPair' when using Descriptor with proto file with any proto file with extensions is imported multiple times(imported directly or imported by dependencies proto files). Distinct all depended FileDescriptor for extensions
…eep the code to remove repeated depended files.
Would be great if someone merged this finally... |
return BuildDependedFileDescriptors(dependencies).SelectMany(GetAllDependedExtensions).Distinct(ExtensionRegistry.ExtensionComparer.Instance).Concat(GetAllGeneratedExtensions(generatedInfo)); | ||
} | ||
|
||
private static IEnumerable<FileDescriptor> BuildDependedFileDescriptors(IEnumerable<FileDescriptor> dependencies) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is unclear what this method does. Does it get all the unique dependencies recursively?
@owt5008137 @MartinKosicky I might be wrong, but it looks like that the This PR would be easier to comprehend if there was a unit test added that would demonstrate the erroneous and fix behavior. |
This RP solve the same problem as #6938 .After #6938 is merged, I rebase it from master again, modify the codes, remove all the duplicated proto files and unit test codes and only left the the optimization of avoiding to build the any dependency multiple times when it's depended by more than one proto files. The origin codes and files of unit tests have the simiular codes to #6938 , so it can use the proto files of #6938 . |
Ok, so you're basically saying the #6938 is already solved and this PR doesn't fix anything that isn't already fixed. It's only an optimization of building the descriptors. |
Fix
ArgumentException: An item with the same key has already been added. Key: Google.Protobuf.ObjectIntPair
when using Descriptor with proto file with any proto file with extensions is imported multiple times(imported directly or imported by dependencies proto files).I think this PR is related to #6936 #6938 . The latest release (by now) v3.11.0 also has this problem.
Here is a simple sample to reproduction this problem:
test-a.proto
test-b.proto
test-ext.proto
Generate csharp code with
protoc -I./extensions ./extensions/test-a.proto ./extensions/test-b.proto ./extensions/test-ext.proto ./extensions/google/protobuf/descriptor.proto --csharp_out=.
Ant then run these codes below:
We will got a exception like this:
We find the problem is in the call
Google.Protobuf.Reflection.FileDescriptor.AddAllExtensions(...)
when generate extensions fortest-a.proto
.msg_description_1
is added twice fromtest-a.proto/test-ext.proto/descriptor.proto
andtest-a.proto/test-b.proto/test-ext.proto/descriptor.proto
.If
test-a.proto
importtest-b.proto
andtest-c.proto
when bothtest-b.proto
andtest-c.proto
importtest-ext.proto
with extensions in it. The same problem happens.