I'm trying to write a NAnt extension that uses this library but I get this exception on my first method that loads the taskscheduler objects.
System.TypeLoadException: Inheritance security rules violated while overriding member: 'Microsoft.Win32.TaskScheduler.TaskService.System.Runtime.Serialization.ISerializab
le.GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)'. Security accessibility of the overriding method must mat
ch the security accessibility of the method being overriden.
I'm assuming this is related to NAnt dynamically loading the extension dll but I'm not sure how to get around it. Previously we were using the taskscheduler 1.0 library via NAnt without any issues.
```
public void test()
{
using (Microsoft.Win32.TaskScheduler.TaskService ts = new Microsoft.Win32.TaskScheduler.TaskService())
{
// Create a new task definition and assign properties
Microsoft.Win32.TaskScheduler.TaskDefinition td = ts.NewTask();
td.RegistrationInfo.Description = "Does something";
// Create a trigger that will fire the task at this time every other day
td.Triggers.Add(new Microsoft.Win32.TaskScheduler.DailyTrigger { DaysInterval = 2 });
// Create an action that will launch Notepad whenever the trigger fires
td.Actions.Add(new Microsoft.Win32.TaskScheduler.ExecAction("notepad.exe", "c:\\test.log", null));
// Register the task in the root folder
ts.RootFolder.RegisterTaskDefinition(@"Test", td);
}
}
```
Comments: ** Comment from web user: dahall **
System.TypeLoadException: Inheritance security rules violated while overriding member: 'Microsoft.Win32.TaskScheduler.TaskService.System.Runtime.Serialization.ISerializab
le.GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)'. Security accessibility of the overriding method must mat
ch the security accessibility of the method being overriden.
I'm assuming this is related to NAnt dynamically loading the extension dll but I'm not sure how to get around it. Previously we were using the taskscheduler 1.0 library via NAnt without any issues.
```
public void test()
{
using (Microsoft.Win32.TaskScheduler.TaskService ts = new Microsoft.Win32.TaskScheduler.TaskService())
{
// Create a new task definition and assign properties
Microsoft.Win32.TaskScheduler.TaskDefinition td = ts.NewTask();
td.RegistrationInfo.Description = "Does something";
// Create a trigger that will fire the task at this time every other day
td.Triggers.Add(new Microsoft.Win32.TaskScheduler.DailyTrigger { DaysInterval = 2 });
// Create an action that will launch Notepad whenever the trigger fires
td.Actions.Add(new Microsoft.Win32.TaskScheduler.ExecAction("notepad.exe", "c:\\test.log", null));
// Register the task in the root folder
ts.RootFolder.RegisterTaskDefinition(@"Test", td);
}
}
```
Comments: ** Comment from web user: dahall **
After "test:", instead of getting the "Hello..." text, I get
BUILD FAILED
C:\Users\dahall\Documents\Visual Studio 2013\Projects\NAnt.Example.Tasks\testscheduledtasktest.nant(6,6):
Invalid element <testtask>. Unknown task or datatype.
Also, when I went to get the NAnt bits, I got version 0.92 and not the 0.91 from your text.