Вышеуказанное не работает для меня в 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#
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
[Runtime.interopservices.marshal] :: getactiveObject Обходной путь для .NET Core
Anonymous » » в форуме C# - 0 Ответы
- 8 Просмотры
-
Последнее сообщение Anonymous
-
-
-
[Runtime.interopservices.marshal] :: GetactiveObject Обходной путь для .NET Core [закрыто]
Anonymous » » в форуме C# - 0 Ответы
- 10 Просмотры
-
Последнее сообщение Anonymous
-