2017-08-30 22 views
0

私はCSLAフォーラムで初めてasked for helpを取得しましたが、まだ解決できませんでした。私は経験している問題を示すtest VS2015 solutionを作成しました。CSLAでのOffice 2013/2016 VSTOアドイン

Outlook、Word、Excel、PowerPointでCSLA 4.6.603を使用しています。 Csla.ApplicationContext.Userを設定した後、Formまたはを表示するか、XMLを読むときにSerializationExceptionがスローされます。 dataSet.ReadXml(tempFileName, XmlReadMode.InferSchema);

私はAppDomain.CurrentDomain.AssemblyResolveを処理しています経由でXMLを読み込むしようとしたときと同じSerializationExceptionをスロー別の例がある試験溶液で

private void MessageThrows(object sender, EventArgs e) 
{ 
    // This message displays correctly 
    MessageBox.Show("About to set user to UnauthenticatedPrincipal. " + 
        "Check Debug Output to see exception.", 
        "Before UnauthenticatedPrincipal"); 

    // The user is set correctly with no exception 
    Csla.ApplicationContext.User = new Csla.Security.UnauthenticatedPrincipal(); 

    try 
    { 
     // The following message throws: 

     // System.Runtime.Serialization.SerializationException: 
     // Type is not resolved for member 'Csla.Security.UnauthenticatedPrincipal,Csla, 
     // Version =4.6.603.0, 
     // Culture =neutral, 
     // PublicKeyToken =93be5fdc093e4c30'. 

     MessageBox.Show("The user has been set to UnauthenticatedPrincipal.", 
         "After UnauthenticatedPrincipal"); 
    } 
    catch (Exception ex) 
    { 
     Debug.WriteLine(ex); 
    } 
} 

問題の最も簡単な例は以下のとおりです。イベント、およびCSLAは、例外がスローされる直前にAppDomain.CurrentDomain.GetAssemblies()にリストされています。

テストソリューションには、非常に基本的なカスタムID、生成されたXMLファイルから読み取る基本ビジネスオブジェクト、および3つのボタンを持つフォームがあります。

WindowsUIプロジェクトをStartUpプロジェクトとして設定して実行すると、メインフォームの各ボタンが成功し、例外はスローされません。

WordAddInプロジェクトをStartUpプロジェクトとして設定して実行します。 Wordが起動し、同じフォームがアドインの読み込み時に表示されます。最初のボタンは成功しますが、次の2つのボタンは例外をスローします。詳細については、デバッグ出力を参照するか、ブレークポイントを設定してください。 OutlookAddInプロジェクトについても同様です。

他の人がCSLAフォーラムのスレッドで先に指摘したように、これは.NETがアセンブリの解決に失敗したことに起因するか、関連しています。 AssemblyResolveイベントが答えかもしれない、私はそれを把握することができませんでした。

ご協力いただければ幸いです。

答えて

0

私はCSLAフォーラムでIngoの助けを借りて、回避策を見つけたと思います。私が見つけた何

private void ThisAddIn_Startup(object sender, System.EventArgs e) 
{ 
    Csla.ApplicationContext.PropertyChangedMode = Csla.ApplicationContext.PropertyChangedModes.Windows; 

    Csla.ApplicationContext.ContextManager  = new Csla.Windows.ApplicationContextManager(); 

    // Workaround to prevent 'SerializationException' in VSTO add-in 

    // 1. Force initialisation of ConfigurationManager 
    System.Configuration.ConfigurationManager.GetSection("Dummy"); 

    // 2. Set UnauthenticatedPrincipal explicitly after 
    // setting the Csla.ApplicationContextManager 
    Csla.ApplicationContext.User = new Csla.Security.UnauthenticatedPrincipal(); 
} 

は、任意のUIは、任意のリボンコントロールのイベントハンドラによって表示される前に、我々はこの問題を回避するコードを再実行する必要があり、現在のユーザを再割り当てすることは十分であることです。ばかげて見えるが、うまくいく。

/// <summary> 
/// Microsoft Office add-ins can experience 
/// <code>System.Runtime.Serialization.SerializationException</code> 
/// "Type is not resolved for member Csla.Security.UnauthenticatedPrincipal". 
/// Calling this method before showing any UI works around the problem. 
/// </summary> 
public static void ExceptionWorkaround(bool setUnauthenticatedPrincipal = false) 
{ 
    // 1. Force initialisation of ConfigurationManager 
    ConfigurationManager.GetSection("Dummy"); 

    // 2. Set User explicitly 
    if (setUnauthenticatedPrincipal) 
     Csla.ApplicationContext.User = new UnauthenticatedPrincipal(); 
    else 
     Csla.ApplicationContext.User = Csla.ApplicationContext.User; 
} 
関連する問題