ItsMods
Help inheritance does not work, why? - Printable Version

+- ItsMods (https://www.itsmods.com)
+-- Forum: Archive (https://www.itsmods.com/Forum-Archive.html)
+--- Forum: Archive (https://www.itsmods.com/Forum-Archive--64.html)
+--- Thread: Help inheritance does not work, why? (/Thread-Help-inheritance-does-not-work-why.html)



inheritance does not work, why? - Nerus - 05-05-2012

Hi I created two example libraries.
A parent, after which the child class inherits.
Why such a solution does not work where I do wrong?

Parent:
PHP Code:
using System; using Addon; namespace Parent { public class parent : CPlugin { public parent(string Name) { ServerPrint("Plugin " + Name + " loaded"); } public override void OnPlayerSpawned(Addon.ServerClient Client) { ServerPrint("#1 Player: " + Client.Name + " spawned"); } } }

Child:
PHP Code:
using System; using Parent; namespace Child { public class child : parent { child() : base("Test Child Plugin") { } public override void OnPlayerSpawned(Addon.ServerClient Client) { ServerPrint("#2 Player: " + Client.Name + " spawned"); } } }



RE: inheritance does not work, why? - Pozzuh - 05-05-2012

Does it not compile at all or does it give an error?

When I inherited Cplugin in 2 different classes I got "System.MissingMethodException" for some reason.


RE: inheritance does not work, why? - Nerus - 05-05-2012

(05-05-2012, 09:35)Pozzuh Wrote: Does it not compile at all or does it give an error?

When I inherited Cplugin in 2 different classes I got "System.MissingMethodException" for some reason.

I use the inheritance to the two libraries, each class is a library.
I don't have errors, when delete Constructors from code, plugin work properly.
A strange thing.


RE: inheritance does not work, why? - Pozzuh - 05-05-2012

(05-05-2012, 09:59)Nerus Wrote:
(05-05-2012, 09:35)Pozzuh Wrote: Does it not compile at all or does it give an error?

When I inherited Cplugin in 2 different classes I got "System.MissingMethodException" for some reason.

I use the inheritance to the two libraries, each class is a library.
I don't have errors, when delete Constructors from code, plugin work properly.
A strange thing.

Is there anything in the logs?


RE: inheritance does not work, why? - Nerus - 05-05-2012

(05-05-2012, 09:35)Pozzuh Wrote: Is there anything in the logs?

OMFG

PHP Code:
[11:07:04] System.MissingMethodException: Dla tego obiektu nie zdefiniowano konstruktora bez parametrw. w System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck) w System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache) w System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache) w System.Activator.CreateInstance(Type type, Boolean nonPublic) w Addon.PluginCode.LoadAssembly(Assembly assembly) [11:07:04] System.MissingMethodException: Dla tego obiektu nie zdefiniowano konstruktora bez parametrw. w System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck) w System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache) w System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache) w System.Activator.CreateInstance(Type type, Boolean nonPublic) w Addon.PluginCode.LoadAssembly(Assembly assembly) [11:07:04] ------------------------------------------------------------ [11:07:04] Server startup [11:07:05] mw3-pc-auth.prod.demonware.net resolved to 209.170.124.209 [11:07:06] mw3-pc-lobby.prod.demonware.net resolved to 209.170.124.211 [11:07:06] mw3-stun.us.demonware.net resolved to 209.170.124.113 [11:07:06] mw3-stun.eu.demonware.net resolved to 209.170.122.204

Code:
[11:07:04] System.MissingMethodException: For this object does not define a constructor without parameters.
why ?!


RE: inheritance does not work, why? - Pozzuh - 05-05-2012

That's the same exception I get.. must be a problem with the addon or something.


RE: Inheritance does not work, why? - Nerus - 05-05-2012

(05-05-2012, 10:31)Pozzuh Wrote: That's the same exception I get.. must be a problem with the addon or something.

Yep its problem witch a Addon.

Nukem can You fix it, in next version, PLEASE ?


RE: Inheritance does not work, why? - Pozzuh - 05-05-2012

(05-05-2012, 10:40)Nerus Wrote:
(05-05-2012, 10:31)Pozzuh Wrote: That's the same exception I get.. must be a problem with the addon or something.

Yep its problem witch a Addon.

Nukem can You fix it, in next version, PLEASE ?

Already asked Nukem about this, he didn't know what was causing it.


RE: inheritance does not work, why? - Nerus - 05-05-2012

Crap, I had such a cool idea.

This is a problem :
PHP Code:
[12:20:12] System.Reflection.TargetInvocationException: Obiekt docelowy wywoania zgosi wyjtek. ---> System.AccessViolationException: Nastpia prba odczytu lub zapisu pamici chronionej. Czsto wskazuje to, e inna pami jest uszkodzona. w Server.CConsole.Printf(SByte* ) w Addon.CPlugin.ServerPrint(String Message) w TestProblem.TestProblem..ctor() w c:\users\nerus\documents\visual studio 2010\Projects\TestProblem\TestProblem\TestProblem.cs:wiersz 11 --- Koniec ladu stosu wyjtkw wewntrznych --- w System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck) w System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache) w System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache) w System.Activator.CreateInstance(Type type, Boolean nonPublic) w Addon.PluginCode.LoadAssembly(Assembly assembly) [12:20:12] ------------------------------------------------------------ [12:20:12] Server startup [12:20:13] mw3-pc-auth.prod.demonware.net resolved to 209.170.124.209 [12:20:13] mw3-pc-lobby.prod.demonware.net resolved to 209.170.124.211 [12:20:14] mw3-stun.us.demonware.net resolved to 209.170.124.113 [12:20:14] mw3-stun.eu.demonware.net resolved to 209.170.122.204

Code:
[12:20:12] System.Reflection.TargetInvocationException: the target of invocation exception. ---> System.AccessViolationException: Attempted to read or write protected memory. Often, this indicates that other memory is corrupt.

for this code

PHP Code:
using System; using Addon; namespace TestProblem { public class TestProblem : CPlugin { public TestProblem() { ServerPrint("Test Object Load !!!"); // <- this is problem, do not use CPlugin in constructor. // Always create public constructor if You use second constructor or create instances. } public override void OnServerLoad() { base.OnServerLoad(); ServerPrint("Start !!!"); } } }



RE: inheritance does not work, why? - master131 - 05-06-2012

A class that inherits CPlugin cannot have an instance constructor, it's a static class. Use the friggin OnServerLoad override or define the constructor as static. Dodgy Note that static constructors cannot accept parameters.

http://msdn.microsoft.com/en-us/library/k9x6w0hc%28v=vs.80%29.aspx

eg:
Code:
using System; using Addon; namespace TestPlugin { public class Test: CPlugin { static Test() { // Do crap here. } } }