• matthew@hierthinking.com

Forum

Please or Register to create posts and topics.

.NET 7.0 and FwLib32.cs

Hello,

i'm trying to use the FwLib32.cs in a .net 7.0 project and i receive this error when i initiate the connection with the method "Focas1.cnc_allclibhndl3(...)".

$exception {"Unable to load one or more of the requested types.\r\nCould not load type 'IODBPSD_3' from assembly 'TestEncapsulationAPI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' because it contains an object field at offset 4 that is incorrectly aligned or overlapped by a non-object field.\r\nCould not load type 'ODBMDL_2' from assembly 'TestEncapsulationAPI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' because it contains an object field at offset 4 that is incorrectly aligned or overlapped by a non-object field.\r\nCould not load type 'ODBDGN_3' from assembly 'TestEncapsulationAPI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' because it contains an object field at offset 4 that is incorrectly aligned or overlapped by a non-object field.\r\nCould not load type 'IODBTIMER' from assembly 'TestEncapsulationAPI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' because it contains an object field at offset 4 that is incorrectly aligned or overlapped by a non-object field."} System.Reflection.ReflectionTypeLoadException.

However it works fine if i use .net Franmework 4.8 for example.

Do you have an idea of a workaround ?

Thanks by advance

Regards

 

Tristan

Hi Tristan,

I am not sure why this would occur when switching to .Net 7.0. However, I have seen this happen when using the wrong architecture. You don't happen to be using 64 bit on your .net 7.0 project do you? Double check that, and if you are, make a new project using 32 bit. If you have to use 64-bit you will need the fwlib64.cs file which you can get here

https://github.com/versex799/FanucFocasTutorial/blob/master/FanucFocasTutorial/fwlib64.cs

Hi,

thanks for your fast answer.

I've tried to use the x64 build with fwlib64 and x86 build with fwlib32 but still getting the same error.

In fact i'm trying to encapsulate your excellent work in ASP.net Core 7 Web API as we don't need real time signals.
May be the error i'm getting is link to Marshall unmanaged types interpretation ?

I have these warnings :
Severity Code Description Project File Line Suppression State Details
Warning CS0618 'UnmanagedType.AsAny' is obsolete: 'Marshalling arbitrary types may be unavailable in future releases. Specify the type you wish to marshal as.' Focas64bits C:\Users\u117578\source\repos\Focas64bits\Focas64bits\fwlib64.cs 7366 Active

I've found this interesting topic : c# - Incorrectly aligned or overlapped by a non-object field error - Stack Overflow

But i don't know how much to allocate for each unmanaged types. Could you tell me please where i can find it in documentation ?

Thanks by advance

Regards

 

Tristan

Hi Tristan,

I have run into this error only one other time, and that was when I was creating my own entries in the fwlib32.cs file. I there are functions in the focas library that are not contained in the cs file, such as a function that changes the ethernet ip address. So when I went to add it, I had to figure out how to properly add the focas structures and how to marshal them properly. I went through a lot of trial and error. It ended up being the FieldOffsets were not set correctly. I do not think that is the issue here since it works on .net framework.

However, I did run across a post, which seems to show there is an issue in .Net 7.0 with using [StructLayout(LayoutKind.Explicit)]. 

Try dropping back to .Net 6.0 and see if you still get the error. If you do, perhaps there is more on this page that will help you.

https://github.com/dotnet/runtime/issues/80973