ebceu4 / protobuf-csharp-port

Automatically exported from code.google.com/p/protobuf-csharp-port
0 stars 0 forks source link

Use of 'item' as a field name in a message causes AmbiguousMatchException #45

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Define a message:
  message Foo {
    optional int32 item = 1;
  }

2. Compile it using:
  ProtoGen.exe -ignore_google_protobuf=true foo.proto google/protobuf/csharp_options.proto --proto_path="./" -output_directory="generated/csharp/"

3. Call the constructor on this or any other Builder defined, you get the same 
exception.

Test method ing.Tests.Foo.Test threw exception: 
System.TypeInitializationException: The type initializer for 'Foo' threw an 
exception. ---> System.TypeInitializationException: The type initializer for 
'Protos' threw an exception. ---> System.Reflection.AmbiguousMatchException: 
Ambiguous match found.

System.RuntimeType.GetPropertyImpl(String name, BindingFlags bindingAttr, 
Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers)
System.Type.GetProperty(String name)
Google.ProtocolBuffers.FieldAccess.SinglePrimitiveAccessor`2..ctor(String name)
Google.ProtocolBuffers.FieldAccess.FieldAccessorTable`2.CreateAccessor(FieldDesc
riptor field, String name)
Google.ProtocolBuffers.FieldAccess.FieldAccessorTable`2..ctor(MessageDescriptor 
descriptor, String[] propertyNames)
Protos.<.cctor>b__0(FileDescriptor root) in C:\local 
source\Test\generated\csharp\Protos.cs: line 127
Google.ProtocolBuffers.Descriptors.FileDescriptor.InternalBuildGeneratedFileFrom
(Byte[] descriptorData, FileDescriptor[] dependencies, 
InternalDescriptorAssigner descriptorAssigner)
Protos..cctor() in C:\local source\Test\generated\csharp\Protos.cs: line 144
Protos.get_Descriptor()
Protos.Foo..cctor() in C:\local source\Test\generated\csharp\Protos.cs: line 
1787
Protos.Foo.get_DefaultInstance()
Protos.Foo.Builder..ctor() in C:\local source\Test\generated\csharp\Protos.cs: 
line 1124

What version of the product are you using? On what operating system?
ProtoGen 2.4.1.473
Windows Server 2008 R2 x64 (tried Windows 7 x64 as well)
Visual Studio 2010 Professional
.Net Framework 4.0 Class Library project

Please provide any additional information below.

Changing the field name from "item" to "bar" causes the issue to go away.  The 
type of the field does not matter, nor does it's optional-ness.

Note that this issue causes all messages defined within the umbrella class to 
break in the same way.  It does not show up at compile time, only when the 
constructor is actually called.

Original issue reported on code.google.com by brandon....@trms.com on 31 May 2012 at 6:14

GoogleCodeExporter commented 9 years ago
Humbug. I suspect this is due to an indexer being called Item as well. Should 
be fixable though - will take a look. It won't be in the next week though I'm 
afraid, as I'm going to be away.

If anyone else wants to fix it, I suspect it's just a case of changing the call 
to GetProperty to make sure we only match "true" properties, not indexers.

Original comment by jonathan.skeet on 31 May 2012 at 7:09

GoogleCodeExporter commented 9 years ago
Fixed in revision 132a1094a3c4, then merged in revision 69bf0fe9e8ee.

(Not in a distribution build yet.)

Original comment by jonathan.skeet on 4 Jun 2012 at 9:54

GoogleCodeExporter commented 9 years ago
is this fix available in latest revision(head)

Original comment by waghmare...@gmail.com on 21 Oct 2013 at 1:42

GoogleCodeExporter commented 9 years ago
Yes, as far as I can tell, it should be fine in head. Did you have problems?

Original comment by jonathan.skeet on 21 Oct 2013 at 8:45

GoogleCodeExporter commented 9 years ago
yeah, i am still getting the error mentioned in the original post, and i also 
cant see the code changes latest revision 83bc9fb7fb05

Original comment by waghmare...@gmail.com on 22 Oct 2013 at 6:30

GoogleCodeExporter commented 9 years ago
its seems that it never got merged to main branch

132a1094a3c4 Fixed  
69bf0fe9e8ee Merged 
d2b41ee25a49 Merged 
3c02ffab3fb8 Merged, and never got back to original branch

Original comment by waghmare...@gmail.com on 22 Oct 2013 at 6:35

GoogleCodeExporter commented 9 years ago
I'll have another look tomorrow night (I can't look tonight I'm afraid), but on 
the default branch I can see the unit test for a message with a field called 
"item", and the code which is in revision 132a1094a3c4 does seem to be merged 
in...

Original comment by jonathan.skeet on 22 Oct 2013 at 6:42

GoogleCodeExporter commented 9 years ago
Nope, I can't reproduce this using the latest code. Steps I took:

- Define a message as per the top of this issue
- Build with just "protogen foo.proto"
- Create a test class:

    class Test
    {
        static void Main()
        {
            var builder = new Foo.Builder();
        }
    }

- Compile with "csc Test.cs Foo.cs /r:Google.ProtocolBuffers.dll"
- Run test.exe

No exceptions. Please could you try these steps yourself? If they work but 
you're still getting the problem in your real code, we need to look more 
closely at what you're doing to reproduce the problem in a short example.

Original comment by jonathan.skeet on 22 Oct 2013 at 7:01

GoogleCodeExporter commented 9 years ago
Jon i have created a new issue, please see 69 for more details about how to 
repro

Original comment by waghmare...@gmail.com on 22 Oct 2013 at 7:04