2012-10-09 93 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? –

相关问题