Вышеуказанное не работает для меня в PS 7 (из -за ядра .NET).
Я наткнулся на различные решения для этого по сети, например,
One. Тем не менее, я не могу заставить их работать.
Я сохраняю код C# в файл .cs и когда я запускаю Add-Type в PS, с путем к файлу .cs, я получаю много ошибок, таких как Следующее: < /p>
Add-Type: (51,6): error CS0246: The type or namespace name 'ResourceExposureAttribute' could not be found (are you missing a using directive or an assembly reference?)
[ResourceExposure(ResourceScope.None)]
^
Add-Type: (51,6): error CS0246: The type or namespace name 'ResourceExposure' could not be found (are you missing a using directive or an assembly reference?)
[ResourceExposure(ResourceScope.None)]
^
Add-Type: (52,6): error CS0246: The type or namespace name 'SuppressUnmanagedCodeSecurityAttribute' could not be found (are you missing a using directive or an assembly reference?)
[SuppressUnmanagedCodeSecurity]
^
Add-Type: (52,6): error CS0246: The type or namespace name 'SuppressUnmanagedCodeSecurity' could not be found (are you missing a using directive or an assembly reference?)
[SuppressUnmanagedCodeSecurity]
^
Add-Type: (51,23): error CS0103: The name 'ResourceScope' does not exist in the current context
[ResourceExposure(ResourceScope.None)]
^
Add-Type: (37,6): error CS0246: The type or namespace name 'ResourceExposureAttribute' could not be found (are you missing a using directive or an assembly reference?)
[ResourceExposure(ResourceScope.None)]
^
Add-Type: (37,6): error CS0246: The type or namespace name 'ResourceExposure' could not be found (are you missing a using directive or an assembly reference?)
[ResourceExposure(ResourceScope.None)]
^
Add-Type: (38,6): error CS0246: The type or namespace name 'SuppressUnmanagedCodeSecurityAttribute' could not be found (are you missing a using directive or an assembly reference?)
[SuppressUnmanagedCodeSecurity]
< /code>
Я думаю, что упускаю что -то в процессе импорта классов C# в ps. < /p>
Так выглядит файл CS сейчас: < /p>
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Principal;
using System;
using Resource;
using SnarlNetworkProtocol;
public static class Marshal2
{
internal const String OLEAUT32 = "oleaut32.dll";
internal const String OLE32 = "ole32.dll";
[System.Security.SecurityCritical] // auto-generated_required
public static Object GetActiveObject(String progID)
{
Object obj = null;
Guid clsid;
// Call CLSIDFromProgIDEx first then fall back on CLSIDFromProgID if
// CLSIDFromProgIDEx doesn't exist.
try
{
CLSIDFromProgIDEx(progID, out clsid);
}
// catch
catch (Exception)
{
CLSIDFromProgID(progID, out clsid);
}
GetActiveObject(ref clsid, IntPtr.Zero, out obj);
return obj;
}
//[DllImport(Microsoft.Win32.Win32Native.OLE32, PreserveSig = false)]
[DllImport(OLE32, PreserveSig = false)]
[ResourceExposure(ResourceScope.None)]
[SuppressUnmanagedCodeSecurity]
[System.Security.SecurityCritical] // auto-generated
private static extern void CLSIDFromProgIDEx([MarshalAs(UnmanagedType.LPWStr)] String progId, out Guid clsid);
//[DllImport(Microsoft.Win32.Win32Native.OLE32, PreserveSig = false)]
[DllImport(OLE32, PreserveSig = false)]
[ResourceExposure(ResourceScope.None)]
[SuppressUnmanagedCodeSecurity]
[System.Security.SecurityCritical] // auto-generated
private static extern void CLSIDFromProgID([MarshalAs(UnmanagedType.LPWStr)] String progId, out Guid clsid);
//[DllImport(Microsoft.Win32.Win32Native.OLEAUT32, PreserveSig = false)]
[DllImport(OLEAUT32, PreserveSig = false)]
[ResourceExposure(ResourceScope.None)]
[SuppressUnmanagedCodeSecurity]
[System.Security.SecurityCritical] // auto-generated
private static extern void GetActiveObject(ref Guid rclsid, IntPtr reserved, [MarshalAs(UnmanagedType.Interface)] out Object ppunk);
}
Подробнее здесь: https://stackoverflow.com/questions/794 ... r-net-core
[Runtime.interopservices.marshal] :: getactiveObject Обходной путь для .NET Core ⇐ C#
Место общения программистов C#
1739275207
Anonymous
Вышеуказанное не работает для меня в PS 7 (из -за ядра .NET).
Я наткнулся на различные решения для этого по сети, например,
One. Тем не менее, я не могу заставить их работать.
Я сохраняю код C# в файл .cs и когда я запускаю Add-Type в PS, с путем к файлу .cs, я получаю много ошибок, таких как Следующее: < /p>
Add-Type: (51,6): error CS0246: The type or namespace name 'ResourceExposureAttribute' could not be found (are you missing a using directive or an assembly reference?)
[ResourceExposure(ResourceScope.None)]
^
Add-Type: (51,6): error CS0246: The type or namespace name 'ResourceExposure' could not be found (are you missing a using directive or an assembly reference?)
[ResourceExposure(ResourceScope.None)]
^
Add-Type: (52,6): error CS0246: The type or namespace name 'SuppressUnmanagedCodeSecurityAttribute' could not be found (are you missing a using directive or an assembly reference?)
[SuppressUnmanagedCodeSecurity]
^
Add-Type: (52,6): error CS0246: The type or namespace name 'SuppressUnmanagedCodeSecurity' could not be found (are you missing a using directive or an assembly reference?)
[SuppressUnmanagedCodeSecurity]
^
Add-Type: (51,23): error CS0103: The name 'ResourceScope' does not exist in the current context
[ResourceExposure(ResourceScope.None)]
^
Add-Type: (37,6): error CS0246: The type or namespace name 'ResourceExposureAttribute' could not be found (are you missing a using directive or an assembly reference?)
[ResourceExposure(ResourceScope.None)]
^
Add-Type: (37,6): error CS0246: The type or namespace name 'ResourceExposure' could not be found (are you missing a using directive or an assembly reference?)
[ResourceExposure(ResourceScope.None)]
^
Add-Type: (38,6): error CS0246: The type or namespace name 'SuppressUnmanagedCodeSecurityAttribute' could not be found (are you missing a using directive or an assembly reference?)
[SuppressUnmanagedCodeSecurity]
< /code>
Я думаю, что упускаю что -то в процессе импорта классов C# в ps. < /p>
Так выглядит файл CS сейчас: < /p>
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Principal;
using System;
using Resource;
using SnarlNetworkProtocol;
public static class Marshal2
{
internal const String OLEAUT32 = "oleaut32.dll";
internal const String OLE32 = "ole32.dll";
[System.Security.SecurityCritical] // auto-generated_required
public static Object GetActiveObject(String progID)
{
Object obj = null;
Guid clsid;
// Call CLSIDFromProgIDEx first then fall back on CLSIDFromProgID if
// CLSIDFromProgIDEx doesn't exist.
try
{
CLSIDFromProgIDEx(progID, out clsid);
}
// catch
catch (Exception)
{
CLSIDFromProgID(progID, out clsid);
}
GetActiveObject(ref clsid, IntPtr.Zero, out obj);
return obj;
}
//[DllImport(Microsoft.Win32.Win32Native.OLE32, PreserveSig = false)]
[DllImport(OLE32, PreserveSig = false)]
[ResourceExposure(ResourceScope.None)]
[SuppressUnmanagedCodeSecurity]
[System.Security.SecurityCritical] // auto-generated
private static extern void CLSIDFromProgIDEx([MarshalAs(UnmanagedType.LPWStr)] String progId, out Guid clsid);
//[DllImport(Microsoft.Win32.Win32Native.OLE32, PreserveSig = false)]
[DllImport(OLE32, PreserveSig = false)]
[ResourceExposure(ResourceScope.None)]
[SuppressUnmanagedCodeSecurity]
[System.Security.SecurityCritical] // auto-generated
private static extern void CLSIDFromProgID([MarshalAs(UnmanagedType.LPWStr)] String progId, out Guid clsid);
//[DllImport(Microsoft.Win32.Win32Native.OLEAUT32, PreserveSig = false)]
[DllImport(OLEAUT32, PreserveSig = false)]
[ResourceExposure(ResourceScope.None)]
[SuppressUnmanagedCodeSecurity]
[System.Security.SecurityCritical] // auto-generated
private static extern void GetActiveObject(ref Guid rclsid, IntPtr reserved, [MarshalAs(UnmanagedType.Interface)] out Object ppunk);
}
Подробнее здесь: [url]https://stackoverflow.com/questions/79427694/runtime-interopservices-marshalgetactiveobject-workaround-for-net-core[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия