working with robocode and the rx framework

I'm starting on a new series of robocode posts that will show my first steps into a robocode robot and I'm treating this as an opportunity to try out some new things, one of which is the new Rx framework from Microsoft. I'm using the 3.5 framework download available from the Rx website (as I have yet to upgrade to 4.0 and VS2010).

Getting this to work with robocode was not easy though and I've had to make a few sacrifices to get this to work (see below) but this is OK for me as the robot battles are happening on my own computer. I therefore wouldn't necessarily recommend using this for a robot you want to compete with online.

When I first hooked up the Rx framework my robot was immediately banned but I couldn't see why in the message printed out on the console. Then I noticed that my offending code using Rx was sitting in a static initializer, so I pulled it into a member method instead.
This then provided me with the real problem - a security violation with "that assembly does not allow partially trusted callers".
(this may be a bug in the robocode fix where static initializer security issues are not caught/cannot be caught in the same manner upon robot creation and security exceptions are not written to the console)

I *think* it was the System.Reactive assembly that didn't allow partially trusted callers and after much wrestling with different fixes I finally got it to work. I can't say for sure that this is the definitive solution, but it works and I don't want to touch it!

I installed the System.Observable, System.CoreEx and System.Reactive 3.5 assemblies in the GAC and I introduced a post build step in my robot assembly so that it registers my assembly in the GAC (and of course I have to sign my robot assembly).
What I *think* happens is that a partially trusted call comes into my robot assembly, but because that is signed and GAC'd it can safely pass on a call to the System.Reactive assembly, fixing my issue.

This means I have had to make a few sacrifices and have the following constraints:

  • My robot assembly is installed in the GAC and I have a post build step to register it
  • I therefore have to run Visual studio as an administrator (which I normally restrict)
  • I can't debug my code through visual studio anymore as it picks up the assembly from the GAC

Now my robot works with Rx 3.5 and I'm free to proceed with my experimentation - the next post will start this new journey.



0 comments: