# CSharp HowTo 4.x throw Engine Error after Advance Time

**URL:** https://discourse.kitware.com/t/csharp-howto-4-x-throw-engine-error-after-advance-time/952
**Category:** Pulse Physiology Engine
**Created:** [December 21, 2022, 3:43am UTC](https://discourse.kitware.com/t/csharp-howto-4-x-throw-engine-error-after-advance-time/952 "2022-12-21T03:43:25Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![joezhu](https://discourse.kitware.com/letter_avatar_proxy/v4/letter/j/7ea924/32.png) [@joezhu](https://discourse.kitware.com/u/joezhu)
#### Post date: [December 21, 2022, 3:43am UTC](https://discourse.kitware.com/t/csharp-howto-4-x-throw-engine-error-after-advance-time/952/1 "2022-12-21T03:43:25Z")

</div>

Hello:  
I were trying to setup the CSharp HowTo csproject.  
Build successful. And want to try HowTo\_RunScenarios.cs  
But I always got false for “pulse.ExecuteScenario(execOpts)” and output “Error running scenario” after “Advance Time” with “Final SimTime(s)”  
There is no other information to tell me what the engine wrong, and how to resolve it.  
I am guessing if there is something wrong for creating the result cvs data?  
How can I resolve this?  
I attached the screenshot.  
I had reduce the AdvanceTime to 1 min. And removed most of DataRequest, only keep 1 data request. So that to keep the test simple

 ![csdebug](https://discourse.kitware.com/uploads/default/original/1X/59be84eac41dc229eea577ae09bac4467526ab54.png)

Thank you .

---

<div class="post-metadata">

### Author: ![abray](https://discourse.kitware.com/user_avatar/discourse.kitware.com/abray/32/12_2.png) [@abray](https://discourse.kitware.com/u/abray)
#### Post date: [December 21, 2022, 4:20am UTC](https://discourse.kitware.com/t/csharp-howto-4-x-throw-engine-error-after-advance-time/952/2 "2022-12-21T04:20:41Z")

</div>

Are you building master or 4.x?

4.x is the latest, so I would work with that.

---

<div class="post-metadata">

### Author: ![joezhu](https://discourse.kitware.com/letter_avatar_proxy/v4/letter/j/7ea924/32.png) [@joezhu](https://discourse.kitware.com/u/joezhu)
#### Post date: [December 21, 2022, 4:30am UTC](https://discourse.kitware.com/t/csharp-howto-4-x-throw-engine-error-after-advance-time/952/3 "2022-12-21T04:30:41Z")

</div>

I follow the README.md. and clone from github.  
`git clone https://gitlab.kitware.com/physiology/engine`  
I think it is master.

---

<div class="post-metadata">

### Author: ![abray](https://discourse.kitware.com/user_avatar/discourse.kitware.com/abray/32/12_2.png) [@abray](https://discourse.kitware.com/u/abray)
#### Post date: [December 21, 2022, 4:45am UTC](https://discourse.kitware.com/t/csharp-howto-4-x-throw-engine-error-after-advance-time/952/4 "2022-12-21T04:45:08Z")

</div>

There has been a good bit of scenario support added to C# for the next release  
Can you check out 4.x and give that a try?

---

<div class="post-metadata">

### Author: ![joezhu](https://discourse.kitware.com/letter_avatar_proxy/v4/letter/j/7ea924/32.png) [@joezhu](https://discourse.kitware.com/u/joezhu)
#### Post date: [December 21, 2022, 2:02pm UTC](https://discourse.kitware.com/t/csharp-howto-4-x-throw-engine-error-after-advance-time/952/5 "2022-12-21T14:02:31Z")

</div>

Thank you for your replied.  
I switched to 4.x. And working well for HowTo\_RunScenarios.cs and generated the cvs output file.  
And I noticed the master is using protobuf 3.8.4 version. the 4.x branch uses protobuf 21.4. Maybe it is casuse by it to serialize to PulseC.dll confuse. Just for guessing.  
And I met new issue for HowTo\_EngineUse.css for 4.x version.  
It throws “Engine was unable to process requrested actions” for SEHemorrhage.ExternalCompartment.RightLeg.  
Anything I missed?

 ![EngineUse](https://discourse.kitware.com/uploads/default/original/1X/d47462e4093a50cf95be26a61999909beeb50a33.png)

Thank you.

---

<div class="post-metadata">

### Author: ![abray](https://discourse.kitware.com/user_avatar/discourse.kitware.com/abray/32/12_2.png) [@abray](https://discourse.kitware.com/u/abray)
#### Post date: [December 21, 2022, 3:27pm UTC](https://discourse.kitware.com/t/csharp-howto-4-x-throw-engine-error-after-advance-time/952/6 "2022-12-21T15:27:15Z")

</div>

You are correct, the howto did have a problem.

I also replace references to pbb files with json files, as we are not auto generating pbb files in our build any longer. (We may generate those in the future, but json will always be generated, so examples should refer to those)

I also notices we were not logging/captureing the error given by ProcessAction on the C# side, so I fixed that as well, so you will see those in the cosole, and/or your LogHandler will now be given those messages

I was also missing the severity of the hemorrhage, so I set that

So this example now works!

Thanks for bringing that to our attention

If you find anything else, please let us know!

---

<div class="post-metadata">

### Author: ![abray](https://discourse.kitware.com/user_avatar/discourse.kitware.com/abray/32/12_2.png) [@abray](https://discourse.kitware.com/u/abray)
#### Post date: [December 21, 2022, 3:27pm UTC](https://discourse.kitware.com/t/csharp-howto-4-x-throw-engine-error-after-advance-time/952/7 "2022-12-21T15:27:46Z")

</div>

Note, I pushed all that to the head of 4.x

---

<div class="post-metadata">

### Author: ![joezhu](https://discourse.kitware.com/letter_avatar_proxy/v4/letter/j/7ea924/32.png) [@joezhu](https://discourse.kitware.com/u/joezhu)
#### Post date: [December 23, 2022, 3:08am UTC](https://discourse.kitware.com/t/csharp-howto-4-x-throw-engine-error-after-advance-time/952/8 "2022-12-23T03:08:07Z")

</div>

Thank you. works for head of 4.x.  
I am learning engine and reading the csharp howto and cpp exploer codes.  
There is SetAdvanceHandler in cpp engine., but couldn’t find it in CSharp engine API, Is it not implemented in CSharp interface version?  
Thank you

---

<div class="post-metadata">

### Author: ![abray](https://discourse.kitware.com/user_avatar/discourse.kitware.com/abray/32/12_2.png) [@abray](https://discourse.kitware.com/u/abray)
#### Post date: [December 23, 2022, 4:44am UTC](https://discourse.kitware.com/t/csharp-howto-4-x-throw-engine-error-after-advance-time/952/9 "2022-12-23T04:44:59Z")

</div>

No, I dont think that is in C#  
The advance handler is there to run custom code after each time step, when you don’t have control of the time step. That was put in primarily to inject writing values to our csv file after each time step as a scenario execution loop runs and processes a scenario.

Generally, I think most applications control the advance loop in their integration, and are not running static scenarios via a static execution loop.

I believe the C# just pushes a scenario over to C++ to run it when you call ExecuteScenario  
I am not sure exactly how we would get a callback from a static advance loop in C++ call C# code.  
If your in C#, you should be able to implement an advance loop and inject a callback/forwarding mechanism in it.

I guess it just depends on what you are planning to do with Pulse and what your time advancement logic needs to support. I can point you directions/combinations of classes
