Menu

#24 AdvancedRobot C# problem: InvalidCastException

none
open
nobody
1
2016-05-26
2016-01-04
No

I'm trying to create my first Advanced Robot in C# (.NET 4.5). It runs fine until some statements. This code:

public override void Run()
        {           
            while (true)
            {
                SetTurnRadarRightRadians(Double.PositiveInfinity);
                Execute();
            }
        }

instantly throws following exception:

System.InvalidCastException: Unable to cast object of type 'net.sf.robocode.dotnet.host.proxies.StandardRobotProxy' to type 'Robocode.RobotInterfaces.Peer.IAdvancedRobotPeer'.
at Robocode.AdvancedRobot.SetTurnRadarRightRadians(Double radians)
at SOA.MrTank.Run()
at net.sf.robocode.dotnet.host.proxies.HostingRobotProxy.CallUserCode()
at net.sf.robocode.dotnet.host.proxies.HostingRobotProxy.run()
SetAhead, TurnRadarRight statements produce the same outcome, but SetFire seems to be working fine.
I googled it for several hours and haven't found anything useful about it.
What am I doing wrong here?

Discussion

  • Flemming N. Larsen

    I will have a look at the issue tonight. It might be a bug in the .NET plugin for Robocode.
    Let's see.

     
  • Flemming N. Larsen

    I have tried to reproduce the problem using Robocode 1.9.2.5 with the .NET plugin for 1.9.2.5 installed. I have used Visual Studio Community 2015 and built SOA.MyTank using .NET Framework 3.5 and 4.5.

    I am not able to reproduce the problem you see!?

    This is the source code I have been using to test the issue you see:

    :::csharp
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    using Robocode;
    
    namespace SOA
    {
        class MrTank : AdvancedRobot
        {
            public override void Run()
            {
                while (true)
                {
                    SetTurnRadarRightRadians(Double.PositiveInfinity);
                    SetTurnGunLeft(10);
                    SetFire(0.1);
                    Execute();
                }
            }
        }
    }
    
     
  • Oleg Savchenko

    Oleg Savchenko - 2016-01-06

    Wow. It's some kind of magic, but now I can't replicate the error too! Really odd. Might had something to do with a robocode application.
    Thank you very much and sorry for your lost time!

     
  • Flemming N. Larsen

    Don't be sorry. You are right. There may be a bug in Robocode.
    Write again if you encounter this issue again and is able to reproduce it.

     

Anonymous
Anonymous

Add attachments
Cancel