473,387 Members | 3,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Interop service error: Cannot marshal field 'XXX' of type 'XXX': There is no marshaling support for this type.

I'm trying to call my DLL written in C, and got the error:

Cannot marshal field 'b' of type 'mystruct': There is no marshaling
support for this type.

The 2 functions in the DLL are:

void unpack(mystruct* str, void* in_buf);
void pack(mystruct* str, void* out_buf);

The data structure is as follows:

typedef struct
{
byte a;
} struct_a;

typedef struct
{
byte a;
byte b[15];
} struct_b;

typedef struct
{
byte a;
union
{
struct_a b;
struct_b c;
};
} struct_c;

typedef struct
{
byte a;
struct_c b[15];
struct_c c[15];
} mystruct;

My type definition in C# is:

public class PRLCodec
{
[DllImport("my.dll")]
public extern static void unpack(
out mystruct str,
IntPtr buf);

[DllImport("my.dll")]
public extern static void pack(
ref mystruct str,
IntPtr buf);

}

[StructLayout(LayoutKind.Sequential)]
public struct struct_a
{
byte a;
}

[StructLayout(LayoutKind.Sequential)]
public struct struct_b
{
byte a;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=15)]
byte[] b;
}

[StructLayout(LayoutKind.Explicit)]
public struct struct_c
{
[FieldOffset(0)]
byte a;
[FieldOffset(1)]
struct_a b;
[FieldOffset(1)]
struct_b c;
}

[StructLayout(LayoutKind.Sequential)]
public struct mystruct
{
byte a;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 15)]
mystruct[] b;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 15)]
mystruct[] c;
}

The code compiles but gives the above error. What could be wrong? I
tried to read documents on interop service, but it seemed overwhelming
to a new .NET programmer. Any help is appreciated.

Nov 17 '05 #1
0 2069

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: JC | last post by:
How does garbage collection work in C# and VB.NET for data returned from COM object? For example, a COM object written in C++ returns a SAFEARRAY to C# or VB.NET, will this SAFEARRAY (mapped to...
1
by: weixian_shen | last post by:
I'm trying to call my DLL written in C, and got the error: "Cannot marshal field 'b' of type 'mystruct': There is no marshaling support for this type." The 2 functions in the DLL are: void...
8
by: Rob Edwards | last post by:
When trying to add the Microsoft CDO for Exchange Management Library (aka CDOEXM.dll) I receive the following message: "A reference to 'Microsoft CDO for Exchange Management Library' could not be...
6
by: Nataraj1978 | last post by:
I have a requirement to use a dll written in Visual C++ 6.0 in my C# application. In order to establish the link between my application and the dll, I have written a ATL COM Component in Visual...
2
by: Richard Collette | last post by:
Hi, I have a service, that runs perfectly when executed outside of the web service environment. When called as a web service I get the exception listed below sporadically. A call to the web...
1
by: Don.Leri | last post by:
Hi, I have a logger.dll (unmanaged c++ dll compiled in vs2005). I have a C# interop to use that dll in managed code implemented in Interfaces.dll (used by other C# dlls). I also have a...
5
by: John | last post by:
I would like to ask a question that is obvious to all people porting applications from the "traditional" C\VB6 interop scheme choosing C# vs VB.NET. We have a math library in C which...
0
by: swts | last post by:
hi, the following marshaling code gives me an errror of "type packet cannot be marshaled as an unmanaged structure; no meaningful size or offset can be managed". public static byte...
10
by: =?Utf-8?B?SGVyYg==?= | last post by:
In trying to write VB.Net code to control MSProject 2003 it was recommended that I record a macro in MSProject and transfer the code to VB.Net. When recording the FileSaveAs (to the project server)...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.