Namespaces don't stop class name conflicts?

Users who are viewing this thread

I just ran a tiny test copy pasting a class from the default packages - in particular, the lumberjack:

Code:
using System;
using TaleWorlds.Engine;

namespace TaleWorlds.MountAndBlade
{
    // Token: 0x020002F5 RID: 757
    public class Lumberjack : ScriptComponentBehaviour
    {
        // Token: 0x060024EC RID: 9452 RVA: 0x00085C44 File Offset: 0x00083E44
        protected internal override void OnTick(float dt)
        {
            base.OnTick(dt);
            if (!this._initialized)
            {
                this._initialized = true;
                base.GameEntity.CreateSimpleSkeleton("human_skeleton");
                base.GameEntity.CopyComponentsToSkeleton();
                base.GameEntity.Skeleton.SetAnimationAtChannel("lumberjack", 0, 1f, -1f, 0f);
                MetaMesh copy = MetaMesh.GetCopy("peasent_hatchet", true, false);
                base.GameEntity.AddMultiMeshToSkeletonBone(copy, 27);
            }
        }

        // Token: 0x04000DB0 RID: 3504
        private bool _initialized;
    }
}

I changed the Namespace to the namespace of my mod, leaving the class name as Lumberjack, and got a crash-on-load:

Code:
using System;
using TaleWorlds.Engine;
using TaleWorlds.MountAndBlade;

namespace TestMod
{
    // Token: 0x020002F5 RID: 757
    public class Lumberjack : ScriptComponentBehaviour
    {
        // Token: 0x060024EC RID: 9452 RVA: 0x00085C44 File Offset: 0x00083E44
        protected override void OnTick(float dt)
        {
            base.OnTick(dt);
            if (!this._initialized)
            {
                this._initialized = true;
                base.GameEntity.CreateSimpleSkeleton("human_skeleton");
                base.GameEntity.CopyComponentsToSkeleton();
                base.GameEntity.Skeleton.SetAnimationAtChannel("lumberjack", 0, 1f, -1f, 0f);
                MetaMesh copy = MetaMesh.GetCopy("peasent_hatchet", true, false);
                base.GameEntity.AddMultiMeshToSkeletonBone(copy, 27);
            }
        }

        // Token: 0x04000DB0 RID: 3504
        private bool _initialized;
    }
}

Changing the class name to MyLumberjack (and renaming the file to match) cleared up the COL:

Code:
using System;
using TaleWorlds.Engine;
using TaleWorlds.MountAndBlade;

namespace TestMod
{
    // Token: 0x020002F5 RID: 757
    public class MyLumberjack : ScriptComponentBehaviour
    {
        // Token: 0x060024EC RID: 9452 RVA: 0x00085C44 File Offset: 0x00083E44
        protected override void OnTick(float dt)
        {
            base.OnTick(dt);
            if (!this._initialized)
            {
                this._initialized = true;
                base.GameEntity.CreateSimpleSkeleton("human_skeleton");
                base.GameEntity.CopyComponentsToSkeleton();
                base.GameEntity.Skeleton.SetAnimationAtChannel("lumberjack", 0, 1f, -1f, 0f);
                MetaMesh copy = MetaMesh.GetCopy("peasent_hatchet", true, false);
                base.GameEntity.AddMultiMeshToSkeletonBone(copy, 27);
            }
        }

        // Token: 0x04000DB0 RID: 3504
        private bool _initialized;
    }
}

Can anyone confirm? Or... is this not what namespaces do in C#? I'm a little new to it.
 
Last edited:
I'm guessing that's because there is an ambiguity with both classes.
Since you wrote `using TaleWorlds.MountAndBlade;`, you are accessing the TaleWorlds.MountAndBlade namespace.
You could use an alias instead `using MB = TaleWorlds.MountAndBlade;` if you really need to, but usually having a different class name is much nicer
 
Having a namespace same as one of the reference DLLs in your code is a big NO NO. Compiler will get confused as which one to use. There are two TaleWorlds.MountAndBlade namespaces in the current project. Try changing your namespace to something else and your issue will be resolved ^^
 
No I changed the namespace to "TestMod" so there shouldn't be a collision, but maybe Daktan is right - because I used the other namespace that may be where the collision came in. I'll have to test
 
Back
Top Bottom