You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
to access Sensor apis in a .NET Core 3.1 WinForms application.
We would like to migrate to .NET 5 but sadly only newer TargetFrameworks (e.g. net5-windows10.0.17763.0) are supported and our customers are still using older Windows 10 versions (special hardware).
Generating ISensorManager and other types using CsWin32 works. Where I still fail is at casting the COM object to ISensorManager:
Guid CLSID_SensorManager = new Guid("77A1C827-FCD2-4689-8915-9D613CC5FA3E");
Type type = Type.GetTypeFromCLSID(CLSID_SensorManager, true);
var sensorManager = Activator.CreateInstance(type);
var x = (ISensorManager) sensorManager;
"Unable to cast COM object of type 'System.__ComObject' to class type 'Microsoft.Windows.Sdk.ISensorManager'. Instances of types that represent COM components cannot be cast to types that do not represent COM components; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface."
I tried to include newer Win32Metadata but anything newer than preview.5 leads to compile time errors even though unsafe code is allowed for the project:
Microsoft.Windows.CsWin32.SourceGenerator\PWSTR.g.cs(21,41,21,47): error CS0214: Zeiger und Puffer fester Größe können nur in einem unsicheren Kontext verwendet werden. (pointers & buffers of fixed size can only be used in an unsafe context)
Any help would be very much appreciated!
The text was updated successfully, but these errors were encountered:
HaraldMuehlhoffCC
changed the title
Using CsWin32 generated interface / using newer Win32Metadata leads to compile time error
How to use CsWin32 generated interface / using newer Win32Metadata leads to compile time error
Feb 20, 2021
Firstly thanks for your cool project!
We're currently using
to access Sensor apis in a .NET Core 3.1 WinForms application.
We would like to migrate to .NET 5 but sadly only newer TargetFrameworks (e.g. net5-windows10.0.17763.0) are supported and our customers are still using older Windows 10 versions (special hardware).
Generating
ISensorManager
and other types using CsWin32 works. Where I still fail is at casting the COM object to ISensorManager:I tried to include newer Win32Metadata but anything newer than preview.5 leads to compile time errors even though unsafe code is allowed for the project:
Any help would be very much appreciated!
The text was updated successfully, but these errors were encountered: