1

.NET MVC Web サイトでスケジューリング機能が必要なのですが、必要なことを正確に実行できる Quartz.net ライブラリに出会いました。

問題は、ホスティング (GoDaddy) でサイトを実行していてQuartz.net 2.0.1、プロジェクトに追加したときに"that assembly does not allow partially trusted callers"例外が発生したことです。調査の結果、多くの人が同じ問題を抱えており、Quartz.net から Common.Logging ライブラリを削除することで解決した人もいることがわかりました。

いくつかのアドバイスに従い、Common.Logging への参照をすべて削除しましたが、まだ問題があります。十分ではないようで、Inheritance security rules violated while overriding member例外が発生しています。詳細:

Inheritance security rules violated while overriding member: 
Quartz.Util.DirtyFlagMap`2<TKey,TValue>.GetObjectData
(System.Runtime.Serialization.SerializationInfo, 
System.Runtime.Serialization.StreamingContext)'.
Security accessibility of the overriding method must match the 
security accessibility of the method being overriden.

それを機能させるには、Quartz.netで何かを変更する必要があるようです。

中程度の信頼で Quartz.net を実行した人はいますか? もしそうなら、何をする必要がありますか?誰かがいくつかの代替案を提案できるでしょうか?

4

2 に答える 2

4

シュタイナーの答えは私を正しい方向に導きました。中程度の信頼のホスティング環境で QuartZNet を動作させるための手順をここで共有します。

QuartzNet は当初、中程度の信頼でアクセス許可の問題に遭遇しました。問題を解決するには、次のことを行う必要がありました。

(1) github から QuartzNet コード ( 2.1.0.400 ) をダウンロードし、AssemblyInfo.cs に次の変更を加えてからビルドします。

交換済み

#if !NET_40  
   [assembly: System.Security.AllowPartiallyTrustedCallers]  
#endif  

[assembly: AllowPartiallyTrustedCallers]  
#if NET_40  
   [assembly: SecurityRules(SecurityRuleSet.Level1)]  
#endif

(2) C5 コード (v 2.1) をダウンロードし、

[assembly: AllowPartiallyTrustedCallersAttribute()

C5 が Qartznet と同じ .NET バージョンでコンパイルされていることを確認します。

(3) TGH 内の web.config に Quartz セクションを追加しました。このセクションでは、requirepermission が false に設定されていました。共通ログ セクションも requirepermission を false に設定し、Common.Logging.Simple.NoOpLoggerFactoryAdapter を使用するように構成しました。

<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
   <sectionGroup name="common">
     <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" requirePermission="false" />
   </sectionGroup>
   <section name="quartz" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
 </configSections>
 <common>
    <logging>
      <factoryAdapter type="Common.Logging.Simple.NoOpLoggerFactoryAdapter, Common.Logging">
           <arg key="showLogName" value="true" />
           <arg key="showDataTime" value="true" />
           <arg key="level" value="OFF" />
           <arg key="dateTimeFormat" value="HH:mm:ss:fff" />
      </factoryAdapter>
    </logging>
  </common>
  <quartz>
      <add key="quartz.scheduler.instanceName" value="QuartzScheduler" />
      <add key="quartz.threadPool.type" value="Quartz.Simpl.SimpleThreadPool, Quartz"  />
      <add key="quartz.threadPool.threadCount" value="10" />
      <add key="quartz.threadPool.threadPriority" value="2" />
      <add key="quartz.jobStore.misfireThreshold" value="60000" />
      <add key="quartz.jobStore.type" value="Quartz.Simpl.RAMJobStore, Quartz" />
  </quartz>

(4) namecollection をパラメーターとしてコンストラクターを使用してスケジューラーを初期化しました。namecollection は、web.config から取得された Quartz セクションでした。

global.asax 内

QuartzScheduler.Start();

クラス

public class QuartzScheduler
{
   public static void Start()
    {
       ISchedulerFactory schedulerFactory = new StdSchedulerFactory((NameValueCollection)ConfigurationManager.GetSection("quartz"));

       IScheduler scheduler = schedulerFactory.GetScheduler();
       scheduler.Start();

       IJobDetail inviteRequestProcessor = new JobDetailImpl("ProcessInviteRequest", null, typeof(InviteRequestJob));
       IDailyTimeIntervalTrigger trigger = new DailyTimeIntervalTriggerImpl("Invite Request Trigger", Quartz.TimeOfDay.HourMinuteAndSecondOfDay(0, 0, 0), Quartz.TimeOfDay.HourMinuteAndSecondOfDay(23, 23, 59), Quartz.IntervalUnit.Second, 1);
       scheduler.ScheduleJob(inviteRequestProcessor, trigger);
     }
  }

  public class InviteRequestJob : IJob
  {
     public void Execute(IJobExecutionContext context)
     {
        RequestInvite.ProcessInviteRequests();
     }
  }
于 2012-12-22T09:37:59.397 に答える
1

Common.Logging をプロジェクトから削除するのではなく、自分でビルドすることをお勧めします。http://netcommon.sourceforge.net/downloads.htmlから最新のソースを入手できます。

2 番目の問題は、C5.dll も信頼されていなかったことと関係があると思います。私も自分でそれを構築します。ソースはhttp://www.itu.dk/research/c5/にあります。

dll をビルドする以外のオプションもありますが (http://stackoverflow.com/questions/3072359/unblocking-a-dll-on-a-company-machine-how)、絶対に信頼できない限り、個人的には自分で dll をビルドすることを好みます。ダウンロードした製品。

于 2012-06-19T09:28:53.317 に答える