2012-10-09 90 views
1

我有這個簡單的代碼:打開文件對話框沒有顯示在不同的AppDomain

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Timers; 
using System.IO; 
using Microsoft.Win32; 
using System.Xml; 

namespace ConsoleApplication1 
{ 
    class Program 
    { 
     public static void Main(string[] args) 
     { 
      OpenFileDialog ofd = new OpenFileDialog(); 
      ofd.ShowDialog(); 
     } 
    } 
} 

我點擊與CSharpCodeProvider按鈕時編譯。然後我將它加載到新的AppDomain並運行Main方法,但從未顯示打開的文件對話框。我知道它正在運行,因爲我已經測試過了。

還試圖卸載一個錯誤的域結果。

如果不再需要的信息只問!

+0

也許你應該粘貼錯誤卸載域給出。 – CrazyCasta

回答

0

最有可能你創建的AppDomain沒有FileDialogPermission。這意味着嘗試使用OpenFileDialog會失敗。有關更多信息,請參閱here

+0

您好我加入這個代碼創建'AppDomain'之後:'_compiledAssemblyDomain.PermissionSet.AddPermission(新FileDialogPermission(FileDialogPermissionAccess.OpenSave));'。但仍然沒有任何反應。這是你的意思嗎? – LynchDev

+0

好吧,我想你越是創建時http://msdn.microsoft.com/en-us/library/ms130766.aspx的(我不是非常熟悉.NET> 3.5)。 – CrazyCasta

0

假設你正在使用的命名體現了應用程序的類型:you cannot use OpenFileDialog just like that!

你有main函數之前試過adding [STAThread]

[STAThread] 
public static void Main(string[] args) 

操作系統的幾個組件,例如對話框,使用COM組件,其與,need to have this attribute present在程序的入口點進行通信。

+0

呃那個線程確實有解決方案來顯示對話框;從我的代碼到他們的唯一區別是我剛剛嘗試添加的[StaThread]屬性,但它不起作用(仍然無效) – LynchDev

+0

因此,添加[STAThread]沒有區別?你使用的是什麼版本的.NET?什麼版本的Visual Studio? –

相關問題