473,659 Members | 2,662 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.d ll")]
public extern static void unpack(
out mystruct str,
IntPtr buf);

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

}

[StructLayout(La youtKind.Sequen tial)]
public struct struct_a
{
byte a;
}

[StructLayout(La youtKind.Sequen tial)]
public struct struct_b
{
byte a;
[MarshalAs(Unman agedType.ByValA rray, SizeConst=15)]
byte[] b;
}

[StructLayout(La youtKind.Explic it)]
public struct struct_c
{
[FieldOffset(0)]
byte a;
[FieldOffset(1)]
struct_a b;
[FieldOffset(1)]
struct_b c;
}

[StructLayout(La youtKind.Sequen tial)]
public struct mystruct
{
byte a;
[MarshalAs(Unman agedType.ByValA rray, SizeConst = 15)]
mystruct[] b;
[MarshalAs(Unman agedType.ByValA rray, 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 2095

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

Similar topics

1
947
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 type in C# or VB.NET) be garbage collected? Similarily, if C# or VB.NET pass SAFEARRAY to the COM object via COM method invocation, will this SAFEARRAY be garbage collected after the call? My guess to answers for both questions is yes. Thanks.
1
1811
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 unpack(mystruct* str, void* in_buf); void pack(mystruct* str, void* out_buf); The data structure is as follows: typedef struct
8
3411
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 added. Converting the type library to a .Net assembly failed. A depended type library 'CDO' could not be converted to a .NET assembly. A dependent type library 'ADODB' could not be converted to a .NET assembly. Item has already been added." ...
6
2405
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 C++.NET . This COM component is referenced in my C# application. The COM component statically links with the 6.0 dll. I am facing problems in passing data from C# to the dll through the COM component. Description: 1. The dll exposes a function...
2
4947
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 method may succeed one time and not another. I cannot find any reason why it would work one time and not another. The exception occurs every two or three calls to the web method. The service utilizes a COM component provided by PeopleSoft...
1
4557
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 number of other C# dlls referencing Interfaces.dll and using logger.dll interop for logging.
5
3269
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 ubiquitously takes a float* which represents an array of floats. If the memory is allocated by the client, in C# or VB.NET, I assume it must be "fixed" so that the GC does not move the pointer during the C algorithm. Given that we are choosing between C#...
0
1140
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 StructureToBytesArray(object obj) { int len = Marshal.SizeOf(obj); byte arr = new byte; IntPtr ptr = Marshal.AllocHGlobal(len); Marshal.StructureToPtr(obj, ptr, true);
10
4000
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) I get the following: FileSaveAs(Name:="<>\MyProject.Published", UserID:="", DatabasePassWord:="", FormatID:="") However, this gives me the "useful" error message "An unexpected error occurred with the method." when applied to my application...
0
8427
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8330
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8850
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8746
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7355
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6178
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4334
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1975
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.