APSIMInitiative / ApsimX

ApsimX is the next generation of APSIM
http://www.apsim.info
Other
134 stars 162 forks source link

[Irrigation].Irrigated and Report frequency #4254

Closed sno036 closed 4 years ago

sno036 commented 4 years ago

Have added this as a question in case this is not a bug. I was putting in a couple of different events for Reporting Frequency and this one generated the error below. Is this intended or a bug? Thanks, Val

System.Exception: ERROR in file: C:\Users\snowv\OneDrive - AgResearch\apsimXSource\Examples\Report.apsimx Simulation name: SimpleReportingSim System.ArgumentException: Object of type 'System.EventHandler' cannot be converted to type 'System.EventHandler1[Models.Soils.IrrigationApplicationType]'. at System.RuntimeType.TryChangeType(Object value, Binder binder, CultureInfo culture, Boolean needsSpecialCast) at System.Reflection.MethodBase.CheckArguments(Object[] parameters, Binder binder, BindingFlags invokeAttr, CultureInfo culture, Signature sig) at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.EventInfo.AddEventHandler(Object target, Delegate handler) at Models.Core.Events.Subscribe(String eventNameAndPath, EventHandler handler) in C:\Users\snowv\OneDrive - AgResearch\apsimXSource\Models\Core\Events.cs:line 78 at Models.Report.Report.OnCommencing(Object sender, EventArgs e) in C:\Users\snowv\OneDrive - AgResearch\apsimXSource\Models\Report\Report.cs:line 126 at System.EventHandler.Invoke(Object sender, EventArgs e) at Models.Clock.OnDoCommence(Object sender, CommenceArgs e) in C:\Users\snowv\OneDrive - AgResearch\apsimXSource\Models\Clock.cs:line 275 at Models.Core.Simulation.Run(CancellationTokenSource cancelToken) in C:\Users\snowv\OneDrive - AgResearch\apsimXSource\Models\Core\Simulation.cs:line 237 ---> System.ArgumentException: Object of type 'System.EventHandler' cannot be converted to type 'System.EventHandler1[Models.Soils.IrrigationApplicationType]'. at System.RuntimeType.TryChangeType(Object value, Binder binder, CultureInfo culture, Boolean needsSpecialCast) at System.Reflection.MethodBase.CheckArguments(Object[] parameters, Binder binder, BindingFlags invokeAttr, CultureInfo culture, Signature sig) at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.EventInfo.AddEventHandler(Object target, Delegate handler) at Models.Core.Events.Subscribe(String eventNameAndPath, EventHandler handler) in C:\Users\snowv\OneDrive - AgResearch\apsimXSource\Models\Core\Events.cs:line 78 at Models.Report.Report.OnCommencing(Object sender, EventArgs e) in C:\Users\snowv\OneDrive - AgResearch\apsimXSource\Models\Report\Report.cs:line 126 at System.EventHandler.Invoke(Object sender, EventArgs e) at Models.Clock.OnDoCommence(Object sender, CommenceArgs e) in C:\Users\snowv\OneDrive - AgResearch\apsimXSource\Models\Clock.cs:line 275 at Models.Core.Simulation.Run(CancellationTokenSource cancelToken) in C:\Users\snowv\OneDrive - AgResearch\apsimXSource\Models\Core\Simulation.cs:line 237 --- End of inner exception stack trace --- at Models.Core.Simulation.Run(CancellationTokenSource cancelToken) in C:\Users\snowv\OneDrive - AgResearch\apsimXSource\Models\Core\Simulation.cs:line 249 at Models.Core.Run.SimulationDescription.Run(CancellationTokenSource cancelToken) in C:\Users\snowv\OneDrive - AgResearch\apsimXSource\Models\Core\Run\SimulationDescription.cs:line 100 at APSIM.Shared.JobRunning.JobRunner.RunActualJob(IRunnable job, IJobManager jobManager) in C:\Users\snowv\OneDrive - AgResearch\apsimXSource\APSIM.Shared\JobRunning\JobRunner.cs:line 161

hol430 commented 4 years ago

I would say it's not intended but it is a bug. I expect you would get the same error if you tried to use the [Phenology].PhaseChanged event as well. The problem is the Irrigation.Irrigated event doesn't use an EventHandler delegate type - it uses the IrrigationApplicationType delegate which allows us to pass info abou the irrigation application such as amount, depth, etc. Will see if there's an easy fix - it seems strange to me that the problem only occurs when we try to subscribe to the event via reflection.