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 **
I believe this is related to a change in the security model for .NET 4.0. I have added the SecurityCritical attribute to the method in your exception and have posted a .NET 4.0 build under attachments. Please check it and confirm it resolves your issue and then I'll get it added into the next release (2.3.1).