Exception thrown during editing script

Posts: 6
Not sure what I'm doing wrong - but during editing a script in ATVO I do get sometimes an exception. Looks to me that the code is already executed in the background although I did not save/compile the code before.

Here is the script-code at the point of time were ATVO crashed. Script should do nothing except writing a trace-file to better understand when function execute is called and (as a next step) what data is provided via the parameters.

By the way I do use for the path 2x "\" but somehow copy/pasting the into the forum editor it changes it 1x"\".

using System;
using System.Media;
using ATVO.ThemesSDK;
using ATVO.ThemeEditor.ThemeModels;
using ATVO.ThemeEditor.Scripting.DotNET;
using ATVO.ThemesSDK.Data.Entity;
using System.IO;

namespace Scripts
{
public class SimpleTracer : IScript
{

        //private filestream logfile = new filestream("c:\temp\aorlogfile.txt", filemode.append, fileaccess.write);; 
        //private streamwriter writer = new streamwriter(logfile);
        //private datetime now;
        static private string logFile = "c:\temp\aorlogfile.txt";
        static private FileStream logFileStream = new FileStream(logFile, FileMode.Append, FileAccess.ReadWrite);
        static private StreamWriter logFileWriter = new StreamWriter(logFileStream);


        public SimpleTracer()
        {
            logEvent("Class constructor called");
        }

        public void logEvent(string text)
        {
       
            logFileWriter.WriteLine( DateTime.Now.ToString("hh:mm:ss.fffffffff") + ": " + text);
            logFileWriter.Flush();
        }

        public object Execute(ThemeContentItem item, object value, string parameter, ISimulation sim)
{
// do nothing except writing a time-stamp and some basic information
logEvent( "Scripts.AORClasses.Methode Execute called");
logEvent( "Content of object is: " + value.ToString());
return value;
}

}
}

Edited (3 times)
Posts: 785
Is there a crash log which you can post? I don't see anything obviously wrong.

By the way, you can log stuff like this perhaps easier by just using "Console.WriteLine(...)". This should print the output to the ATVO Event Log window which is available in both the Theme Editor and while running ATVO.
Posts: 6
Please find attached the logfiles - seems that I can reproduce the failure.

Path to failure ist simple open the Theme-Editor and either wait or select some widgets (w/o changing anything).

P.S.: Not sure what causes the exception in the script and why / when the Theme Editor calls the script at all, but it seems that neither my script (which is the case for sure) nor the Theme editor app is doing proper exception handling.



Download logfile
Error: 6/20/2019 2:55:22 PM (UTC)
Unhandled exception
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.TypeInitializationException: The type initializer for 'Scripts.SimpleTracer' threw an exception. ---> System.ArgumentException: Append access can be requested only in write-only mode.
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access)
at Scripts.SimpleTracer..cctor()
--- End of inner exception stack trace ---
at Scripts.SimpleTracer..ctor()
--- End of inner exception stack trace ---
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)

Download logfile
Error: 6/20/2019 2:56:44 PM (UTC)
Unhandled exception
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.TypeInitializationException: The type initializer for 'Scripts.SimpleTracer' threw an exception. ---> System.ArgumentException: Append access can be requested only in write-only mode.
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access)
at Scripts.SimpleTracer..cctor()
--- End of inner exception stack trace ---
at Scripts.SimpleTracer..ctor()
--- End of inner exception stack trace ---
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
Edited (1 time)
Posts: 785
The script is compiled when you save the theme (or when something triggers an automatic backup).

During compilation a new script instance is created. This calls your script constructor code.

In that code an exception is thrown and the issue is this:
System.ArgumentException: Append access can be requested only in write-only mode.

This error is being handled and logged, ATVO should not be crashing but merely showing that the error happened.