powered by simpleCommunicator - 2.0.56     © 2025 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / WinForms, .Net Framework [игнор отключен] [закрыт для гостей] / Почему ошибка ?....the current thread is not in a single-threaded apartment.
2 сообщений из 2, страница 1 из 1
Почему ошибка ?....the current thread is not in a single-threaded apartment.
    #38428314
Hazard
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Коллеги,

в моем проекте VS есть кусок кода, который вызывает ошибку
Код: c#
1.
ActiveX control '8856f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated because the current thread is not in a single-threaded apartment.



при создании экземпляра WebBrowser. Примечательно, что в других проектах все работает. С чем это может быть связано?

Код: c#
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                DevExpress.XtraEditors.XtraMessageBox.Show(string.Format("{0} version {1} Usage: userid", GetAppName(), System.Reflection.Assembly.GetExecutingAssembly().GetName().Version));
                Environment.Exit(255);
            }

            try
            {
                System.Windows.Forms.Application.EnableVisualStyles();
                System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);

                System.Windows.Forms.WebBrowser a = new System.Windows.Forms.WebBrowser();

                System.Windows.Forms.Application.Run(new FormJournal (args[0]));
            }
            catch (Exception ex)
            {
                DevExpress.XtraEditors.XtraMessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Environment.ExitCode = 255;
            }
        }
...
Рейтинг: 0 / 0
Почему ошибка ?....the current thread is not in a single-threaded apartment.
    #38475335
Hazard
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Solution:

It might be that you are facing the following problem reported on Connect1:

.vshost.exe forces wrong threading model used when debugging a .exe if a .dll of the same name exists in same bin directory

According to that issue it happens that the hosting process of Visual Studio, i.e. the myprogram.vshost.exe enforces the wrong apartment state when you have both a myprogram.exe and a myprogram.dll file in your output folder.
...
Рейтинг: 0 / 0
2 сообщений из 2, страница 1 из 1
Форумы / WinForms, .Net Framework [игнор отключен] [закрыт для гостей] / Почему ошибка ?....the current thread is not in a single-threaded apartment.
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]