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: digdug **
NAnt 0.91 (Build 0.91.3881.0; alpha2; 8/17/2010)
Copyright (C) 2001-2010 Gerry Shaw
http://nant.sourceforge.net
Buildfile: file:///D:/CADev/CI.trunk.02/Deployment/Libraries/NAnt/NAnt.Example.Tasks/testscheduledtasktest.nant
Target framework: Microsoft .NET Framework 4.0
Target(s) specified: test
test:
Hello, you have successfully run a NAnt extension task!
Attempting to create windows scheduled task
BUILD FAILED
INTERNAL ERROR
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.
at NAnt.Example.Tasks.ScheduledTaskTest.CreateTestScheduledTask()
at NAnt.Example.Tasks.ScheduledTaskTest.ExecuteTask() in d:\CADev\CI.trunk.02\Deployment\Libraries\NAnt\NAnt.Extension.Example\ScheduledTaskTest.cs:line 20
at NAnt.Core.Task.Execute()
at NAnt.Core.Target.Execute()
at NAnt.Core.Project.Execute(String targetName, Boolean forceDependencies)
at NAnt.Core.Project.Execute()
at NAnt.Core.Project.Run()
Please send bug report to nant-developers@lists.sourceforge.net.
Total time: 0 seconds.
D:\CADev\CI.trunk.02\Deployment\Libraries\NAnt\NAnt.Example.Tasks>pause
Press any key to continue . . .