Using EthernetShield2 with RC522

Hey.
I am working on a project where i would like to send the UID of a magnetcard via UDP to a project on my PC. The Connection itselfs works. I am able to send a string from my Arduino to my Software. But if I want to read out the UID and send it to the software, it doesnt work. Could anybody help me how to use the UDP and the RC522 parallel in one Sketch?
I am working with the exmplesketch (SendandReceiveString).

#include <MFRC522.h>
#include<SPI.h>
constexpr uint8_t RST_PIN = 5;     
constexpr uint8_t SS_PIN = 53;     
MFRC522 mfrc522(SS_PIN, RST_PIN);

//UDP
#include <Ethernet2.h>
#include <EthernetUdp2.h>
EthernetUDP Udp;

byte mac[] = {0x90, 0xA2, 0xDA, 0x11, 0x2E, 0x46};
IPAddress ip(192, 168, 1, 177);
unsigned int localPort = 8888;
char packetBuffer[UDP_TX_PACKET_MAX_SIZE];
char  ReplyBuffer[] = "UID should be in here afterwards.";


void setup() {
  // put your setup code here, to run once:
 Ethernet.begin(mac, ip);
  Udp.begin(localPort);
  Serial.begin(9600);
}

void loop() {
  String content;

  // if there's data available, read a packet
  int packetSize = Udp.parsePacket();
  if (packetSize)
  {
    Serial.print("Received packet of size ");
    Serial.println(packetSize);
    Serial.print("From ");
    IPAddress remote = Udp.remoteIP();
    for (int i = 0; i < 4; i++)
    {
      Serial.print(remote[i], DEC);
      if (i < 3)
      {
        Serial.print(".");
      }
    }
    Serial.print(", port ");
    Serial.println(Udp.remotePort());

    // read the packet into packetBufffer
    Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE);
    Serial.println("Contents:");
    Serial.println(packetBuffer);
    

    //------------------------------------------------------------------------
// Look for new cards
  if ( ! mfrc522.PICC_IsNewCardPresent()) {
    return;
  }

  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial()) {
    return;
  }
  //----------------------------------------------------------------------
  
  for (byte i = 0; i < mfrc522.uid.size; i++) {
    content.concat(String(mfrc522.uid.uidByte[i] <0x10 ? "0" : " "));
    content.concat(String(mfrc522.uid.uidByte[i],HEX));
    }
    content.toUpperCase();
    String UID= content.substring(1);  
    Serial.print(UID);
    // send a reply, to the IP address and port that sent us the packet we received
    Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
    Udp.write(ReplyBuffer);
    Udp.endPacket();
  }
  delay(10);
}

But if I want to read out the UID and send it to the software, it doesnt work.

I'm not even going to look at your code until you explain what it actually does, and how that differs from what you want. "It doesn't work" is just noise. We deal in facts here.

    Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
    Udp.write(ReplyBuffer);
    Udp.endPacket();

ReplyBuffer doesn't contain any useful information. UID does.

PaulS:
I'm not even going to look at your code until you explain what it actually does, and how that differs from what you want. "It doesn't work" is just noise. We deal in facts here.

    Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());

Udp.write(ReplyBuffer);
    Udp.endPacket();



ReplyBuffer doesn't contain any useful information. UID does.

Actually, If I am using both of this devices (RC522 and Ethernetshield) seperately, everything works fine. But If i stick up the Shield on the Arduino Mega and connect the RC522 also, only the RC522 module works. I found out that my Arduino is communicating with my shield over the same PINS(50-53) as my RFID-Module. May this could be the Problem?