Getting "Access violation" error when trying to collect weapon

My requirement is, when my character overlaps with the weapons, That weapon should get attached to the socket of character.
Character - MainPlayer.cpp
Weapon code- void AWeapons::OnBeginOverLap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)

if (OtherActor)
	AMainPlayer* m = Cast<AMainPlayer>(OtherActor);
    const USkeletalMeshSocket* RightHandSocket = m->GetMesh()->GetSocketByName("WeaponHolder");
	RightHandSocket->AttachActor(this, m->GetMesh());


so, here when ever character is overlapping with the weapon, i am getting an exception saying " Access violation’ and game breaks. Have i done wrong casting? please help. Thanks.

No need to make a reference to skeletal mesh socket.

this->AttachToComponent(m->GetMesh(), /*FAttachmentTransformRules*/, SocketName)