ebceu4 / protobuf-csharp-port

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

alias 'pb' not found #79

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
**What steps will reproduce the problem?**

I was not able to isolate the cause and reproduce the issue with an other 
x.proto 
But in case some else have the issue or find the cause I open the bug.

1. using monodevelop 4.2.2 (I'm on linux)
2. setup project for .Net 3.5
3. generate the .protobin

    protoc "--proto_path=$SRC_DIR" "--descriptor_set_out=x.protobin" --include_imports $SRC_DIR/x.proto

4. generate the .cs

    mono $PRJ_HOME/Google.ProtocolBuffers.2.4.1.521/tools/ProtoGen.exe -line_break=Unix x.protobin

5. add the Google.ProtocolBuffers.dll to the Références
5. add the .cs to source

**What is the expected output? What do you see instead?**

No error and no warning

Instead, I've got :
  Error CS0432: Alias `pb' not found (CS0432) (squarion_msg)
   (but not on the first class generated)

If I replace  'pb::' by 'pb.', the error become (same line) :
  Error CS0122: `Google.ProtocolBuffers' is inaccessible due to its protection level (CS0122) (squarion_msg)

**What version of the product are you using? On what operating system?**

Linux arch 3.13.5-1-ARCH #1 SMP PREEMPT Sun Feb 23 00:25:24 CET 2014 x86_64 
GNU/Linux
MonoDevelop 4.2.2
mode .Net 3.5
protobuf-csharp-port :
* from 'nuget install Google.ProtocolBuffers' : 2.4.1_521
* from download on this site : 2.4.1_521

**Please provide any additional information below.**

My workaround, I replace 'pb::' by 'global::Google.ProtocolBuffers.'

  mono $PRJ_HOME/Google.ProtocolBuffers.2.4.1.521/tools/ProtoGen.exe -line_break=Unix x.protobin
  sed -i 's/pb::/global::Google.ProtocolBuffers./g' x.cs

Original issue reported on code.google.com by david.bernard.31 on 5 Mar 2014 at 8:47

GoogleCodeExporter commented 9 years ago
Can you attach the generated file to this issue? It *should* contain using 
directives at the start, like this:

using pb = global::Google.ProtocolBuffers;
using pbc = global::Google.ProtocolBuffers.Collections;
using pbd = global::Google.ProtocolBuffers.Descriptors;
using scg = global::System.Collections.Generic;

(I copied that directly from the generated CSharpOptions at 
https://code.google.com/p/protobuf-csharp-port/source/browse/src/ProtocolBuffers
/DescriptorProtos/CSharpOptions.cs)

Original comment by jonathan.skeet on 5 Mar 2014 at 8:50

GoogleCodeExporter commented 9 years ago
Sorry, I can't share the file (need agreement from my company).

I've got the header :

// Generated by ProtoGen, Version=2.4.1.521, Culture=neutral, 
PublicKeyToken=55f7125234beb589.  DO NOT EDIT!
#pragma warning disable 1591, 0612, 3021
#region Designer generated code

using pb = global::Google.ProtocolBuffers;
using pbc = global::Google.ProtocolBuffers.Collections;
using pbd = global::Google.ProtocolBuffers.Descriptors;
using scg = global::System.Collections.Generic;
namespace squarion_msg {

  [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
  public static partial class Squarion {
...

I'm a newbe in .Net (my first week). So may be I did something wrong.

An other info, if I change the namespace (eg s/quarion/ample/g), the error 
gone. I've got some regular .cs in the same namespace (but not the same 
directory) like Encoder.cs, MessageFactory.cs

Original comment by david.bernard.31 on 5 Mar 2014 at 9:16

GoogleCodeExporter commented 9 years ago
If that's at the start of the file, you shouldn't be getting the message you're 
getting - at least not in that file.

Do you have both a class called "pb" anywhere at all? Or a class called 
squarion_msg anywhere? (It's a bad idea to give a class the same name as a 
namespace, and it's possible that could cause the problem you're seeing.)

If you can't post the *actual* proto file or generated code, can you come up 
with a sample which *does* cause the same problem? (Typically start with a copy 
of the failing version, and remove as much as you can while making sure the 
problem still occurs, then rename anything you need to for confidentiality. You 
should end up with a very small sample.)

Original comment by jonathan.skeet on 5 Mar 2014 at 9:22

GoogleCodeExporter commented 9 years ago
No classes with the name 'pb', or squarion_msg or Squarion (except the one 
generated).
No symbol 'pb' in the non-genereted .cs

I already try without success to isolate and reproduce with addressbook or with 
a copy of my .proto in another namespace.

I can send you privately the .cs, but I just try to create an empty project 
with a copy of the generated file, and there is no build error, but in the 
editor 'pb::GeneratedMessageLite' with GeneratedMessageLite in red ('Unknown 
Resolve Error').

Thanks for your time and help. Now we've got 2 workaround, search and replace 
pb or using another namespace.

Original comment by david.bernard.31 on 5 Mar 2014 at 9:38

GoogleCodeExporter commented 9 years ago
Okay - it sounds like it may be a Monodevelop issue, particularly if starting 
again doesn't even give the same build error :(

Will leave as "WontFix" at the moment as there's not a lot we can do without a 
way of reproducing, but I'll remember it for if this comes up again.

Original comment by jonathan.skeet on 5 Mar 2014 at 9:47