Please help with JobDriver threw exception "Specified cast is not valid."

Started by Nikuksis, October 14, 2020, 05:00:17 AM

Previous topic - Next topic

Nikuksis

Hello everyone,

Please help on the error https://pastebin.com/Vw627zE5

When i making new classes from vanilla ones, there is an error when i call method

    private LordJob_BestowingCeremony_Patch CeremonyJob_Patch => (LordJob_BestowingCeremony_Patch) this.Bestower.GetLord().LordJob;

    this.CeremonyJob_Patch.FinishCeremony_Patch(this.pawn);

Even without any changes it wont work for me, threwing the error. Please help figure out why the same classes/methods does not work for me.

Thanks!

RawCode


Nikuksis

https://pastebin.com/jbSs378X  - JobDriver class  - error throwing on row 87. If i call the vanilla class LordJob_BestowingCeremony which has no difference with Patched there is no error.

https://pastebin.com/3YM47bah  - LordJob class

Nikuksis

Actually im trying to remove Psylink/Abilities giving on the ceremony, leaving the Title bestowing only.
Possible it will be easier to make it with harmony patch, instead class replacement.

I will apreciate if someone can help with this.

Has a workaround for it with setting max psylink level for any title =0

RawCode


LWM

You write

private LordJob_BestowingCeremony_Patch CeremonyJob_Patch => (LordJob_BestowingCeremony_Patch) this.Bestower.GetLord().LordJob;

but apparently, sometimes the Lord's LordJob is NOT a LordJob_BestowingCeremony_Patch.  You could replace it with something that does "Log.Message("Actual class is "+this.Bestower.GetLord().LordJob.GetType()); return null;"  It'll break, of course, but it'll give you a message first.

I suspect that you're mixing JobDrivers and Jobs here - they are different things in RW.  Your JD is ...I think the driver what tells the pawn they can have a job or something?  And the Job is what sets out the tasks ("toils") in the job?  Look at some vanilla classes to get a good idea here - I don't work with jobs super often!

RawCode

he does not extend any base class, LordJob_BestowingCeremony_Patch is not LordJob