C# OpenFileDialog在不同的AppDomain中不显示
我有一个简单的代码:C# OpenFileDialog在不同的AppDomain中不显示,c#,.net,appdomain,openfiledialog,C#,.net,Appdomain,Openfiledialog,我有一个简单的代码: 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 st
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
方法,但从未显示“打开文件”对话框。我知道它正在运行,因为我已经测试过了
同时尝试卸载域也会导致错误
如果需要更多信息,请询问 您创建的
AppDomain
很可能没有FileDialogPermission
。这当然意味着尝试使用OpenFileDialog
将失败。有关更多信息,请参阅。假设您使用的命名空间反映了应用程序的类型:
你试过主要功能吗
[STAThread]
public static void Main(string[] args)
操作系统的多个组件,如对话框,在程序的入口点使用COM组件进行通信。Eh该线程确实有一个显示对话框的解决方案;我的代码与他们的代码的唯一区别是[StatThread]属性,我刚刚尝试添加该属性,但它不起作用(仍然不起作用),所以添加[StatThread]没有什么区别?您使用的是什么版本的.NET?什么版本的Visual Studio?您好,我在创建
AppDomain
:\u compiledAssemblyDomain.PermissionSet.AddPermission(新建FileDialogPermissionAccess(FileDialogPermissionAccess.OpenSave))之后添加了这段代码代码>。但还是什么都没发生。这就是你的意思吗?当你创建它的时候,我考虑的更多(我对.net>3.5不是很熟悉)。也许你应该粘贴卸载域时出现的错误。