Skip to content
This repository was archived by the owner on Nov 13, 2026. It is now read-only.
This repository was archived by the owner on Nov 13, 2026. It is now read-only.

Namespace and .dll name collisions (CppCodeGen) #122

Closed

Description

@davidfowl
using System;

namespace WebApplication106
{
    public class Startup
    {
        public static void Main(string[] args)
        {
            var identity = new Func<int, int>(Identity);
        }

        private static int Identity(int arg)
        {
            return arg;
        }
    }
}

I get compilation errors in the generated Cpp

Activity

  1. changed the title [-]Delegates don't work (IL2CPP)[/-] [+]Delegates don't work (CppCodeGen)[/+] on Oct 25, 2015
  2. jkotas commented on Oct 25, 2015

    @jkotas
    Member

    What is the compilation error that you see in the generated Cpp? The small repro works fine for me.

  3. davidfowl commented on Oct 25, 2015

    @davidfowl
    MemberAuthor
    2>  repro.cpp
    2>c:\dev\git\corert\src\iltonative\repronative\repro.cpp(113): error C3083: 'WebApplication106': the symbol to the left of a '::' must be a type
    2>c:\users\davifowl\documents\visual studio 2015\projects\webapplication106\src\webapplication106\startup.cs(9): error C3083: 'WebApplication106': the symbol to the left of a '::' must be a type
    2>c:\users\davifowl\documents\visual studio 2015\projects\webapplication106\src\webapplication106\startup.cs(17): error C3083: 'WebApplication106': the symbol to the left of a '::' must be a type
    2>c:\users\davifowl\documents\visual studio 2015\projects\webapplication106\src\webapplication106\startup.cs(19): error C3083: 'WebApplication106': the symbol to the left of a '::' must be a type
    2>  main.cpp
    2>  Generating Code...
    
    namespace WebApplication106 { namespace WebApplication106 { class Startup : public System_Private_CoreLib::System::Object { public:
    static void Main(System_Private_CoreLib::System::String__Array*);
    static int32_t Identity(int32_t);
    static int32_t __DelegateShuffleThunk__Identity(WebApplication106::WebApplication106::Startup*, int32_t);
    }; }; };

    image

  4. davidfowl commented on Oct 25, 2015

    @davidfowl
    MemberAuthor

    I see the problem. It's creating a bogus namespace:

    Broken

    namespace WebApplication106 {
        namespace WebApplication106 {
            class Program : public System_Private_CoreLib::System::Object {
            public:
                static void Main(System_Private_CoreLib::System::String__Array*);
                static int32_t Identity(int32_t);
                static int32_t __DelegateShuffleThunk__Identity(WebApplication106::Program*, int32_t);
            };
        };
    };

    Fixed

    namespace WebApplication106 {
        class Program : public System_Private_CoreLib::System::Object {
        public:
            static void Main(System_Private_CoreLib::System::String__Array*);
            static int32_t Identity(int32_t);
            static int32_t __DelegateShuffleThunk__Identity(WebApplication106::WebApplication106::Program*, int32_t);
        };
    };
  5. davidfowl commented on Oct 25, 2015

    @davidfowl
    MemberAuthor

    Bah, that's not the problem. Still getting errors.

  6. davidfowl commented on Oct 25, 2015

    @davidfowl
    MemberAuthor

    So it seems it's happening all over the file. I end up with WebApplication106:: WebApplication106::Something and some things don't like that.

  7. davidfowl commented on Oct 25, 2015

    @davidfowl
    MemberAuthor

    Yep that was it. All fixed now. Will see if I can figure out where it goes wrong

  8. jkotas commented on Oct 25, 2015

    @jkotas
    Member

    The problem is that the .dll name and namespace name are the same. The name mangling is not robust enough to deal with it yet - general problem tracked by #32. You can work around it by renaming namespace WebApplication106 to something else.

  9. changed the title [-]Delegates don't work (CppCodeGen)[/-] [+]Namespace and .dll name collisions (CppCodeGen)[/+] on Oct 25, 2015
  10. added this to the milestone on Dec 11, 2015
  11. modified the milestones: Future, on Feb 5, 2016
  12. manu-st commented on Feb 5, 2016

    @manu-st

    I'm in need to get this fixed since it is quite frequent in our code to have the assembly name using the same namespace name. I'm currently testing a solution where the name mangling would prepend an _ when there is such a conflict. Is this something you have in mind? Should we always prepend an _ for assembly name, the likelihood you would have to add an extra _ would be quite reduced.

  13. jkotas commented on Feb 5, 2016

    @jkotas
    Member

    Maybe a better option is to always fully qualify the names in the generated C++ code (with :: prefix).

  14. manu-st commented on Feb 8, 2016

    @manu-st

    I've done that locally. Could you remind me where I should add a test to cover this specific scenario?

  15. jkotas commented on Feb 8, 2016

    @jkotas
    Member

    You can add a new test under tests\src\Simple with the interesting cases of name collisions that you are fixing.

    Other than that - just make sure that the few tests (hello world, etc.) that are running as part of the build still work.

  16. MichalStrehovsky commented on Feb 18, 2016

    @MichalStrehovsky
    Member

    @manu-silicon @jkotas Can we close this now?

  17. manu-st commented on Feb 18, 2016

    @manu-st

    I was not the original reporter but what I fixed seems to be exactly that scenario, so I would say we can close it now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions