473,804 Members | 2,024 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

LayoutKind.Expl icit breaks service install

I have a structure declared as:

[StructLayout(La youtKind.Explic it, Size=6)]
private struct StandardFrame
{
[FieldOffset(0)] public byte [] frame;
[FieldOffset(0)] public UInt32 integrityCheck;
[FieldOffset(2)] public UInt32 sequenceNo;
[FieldOffset(4)] public UInt32 dataLength;

}

This is part of a Windows Service C# app. I've added an installer and
setup project but the install fails with "Unable to get installer types
in the <name of executable> --> one or more of the types in the
assembly unable to load."

I've narrowed the problem down to this struct. If I make the struct
LayoutKind.Sequ ential and remove the FieldOffset values the service
installs no problem. Obviously this is not what I want, the struct is
to be used as a union. This has really got me stumped, I can work
around it but I would prefer to use this approach.

Any clues gratefully accepted.

Nov 17 '05 #1
13 1775
Dave,

Well, the first problem I see is that you set the size of the structure
to 6, and yet, you have an integer (four bytes) at offset four, which means
the size of the structure needs to be 8.

Are you sure that you dont want that offset to be at 2? Or the size is
not correct?

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Dave" <pi******@gmail .com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
I have a structure declared as:

[StructLayout(La youtKind.Explic it, Size=6)]
private struct StandardFrame
{
[FieldOffset(0)] public byte [] frame;
[FieldOffset(0)] public UInt32 integrityCheck;
[FieldOffset(2)] public UInt32 sequenceNo;
[FieldOffset(4)] public UInt32 dataLength;

}

This is part of a Windows Service C# app. I've added an installer and
setup project but the install fails with "Unable to get installer types
in the <name of executable> --> one or more of the types in the
assembly unable to load."

I've narrowed the problem down to this struct. If I make the struct
LayoutKind.Sequ ential and remove the FieldOffset values the service
installs no problem. Obviously this is not what I want, the struct is
to be used as a union. This has really got me stumped, I can work
around it but I would prefer to use this approach.

Any clues gratefully accepted.

Nov 17 '05 #2
"Dave" <pi******@gmail .com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
I've narrowed the problem down to this struct. If I make the struct
LayoutKind.Sequ ential and remove the FieldOffset values the service
installs no problem. Obviously this is not what I want, the struct is
to be used as a union. This has really got me stumped, I can work
around it but I would prefer to use this approach.

Any clues gratefully accepted.


I dumped the installer from my service and install it using windows API when
the setup for my program is run.

Or, as nicholas said, your structure is pretty screwed up.

Michael
Nov 17 '05 #3
Good point, must have been having a bad day. So my structure is now
hopefully correct:

[StructLayout(La youtKind.Explic it, Size=6)]
private struct StandardFrame
{
[FieldOffset(0)] public byte [] frame;
[FieldOffset(0)] public UInt16 integrityCheck;
[FieldOffset(2)] public UInt16 sequenceNo;
[FieldOffset(4)] public UInt16 dataLength;
}

It is a 6-byte framing sequence that is a packet header for
communicating with a mainframe system.

Sadly fixing the structure declaration doesn't actually fix the
installer issue. When I run installutil against my service assembly it
throws an exception with the following call stack:

An exception occurred while trying to find the installers in the
c:\documents and settings\davec\ my documents\visua l studio
projects\hsmthr iftlineservice\ bin\debug\hsmth riftlineservice .exe
assembly.
System.Reflecti on.ReflectionTy peLoadException : One or more of the types
in the assembly unable to load.
at System.Reflecti on.Module.GetTy pesInternal(Sta ckCrawlMark&
stackMark)
at System.Reflecti on.Module.GetTy pes()
at
System.Configur ation.Install.A ssemblyInstalle r.GetInstallerT ypes(Assembly
assem)
at
System.Configur ation.Install.A ssemblyInstalle r.InitializeFro mAssembly()

To me it appears to be trolling through the types in the assembly and
trips up on the struct.

Nov 17 '05 #4
Thanks for the response. Do you have an example of doing this that I
could take a look at? Do you still use the setup project to generate
the install? I'm pretty sure I can work around the struct issue which
might be more expedient than going down the route you're suggesting.

Nov 17 '05 #5
Actually it has been pointed out that quite apart from the types
declared in the struct being incorrect, it's not legal to overlap
reference and value types. Thanks anyway.

Nov 17 '05 #6

"Dave" <pi******@gmail .com> wrote in message
news:11******** ************@f1 4g2000cwb.googl egroups.com...
Actually it has been pointed out that quite apart from the types
declared in the struct being incorrect, it's not legal to overlap
reference and value types. Thanks anyway.


All you can do about this is flatten the byte[]...

[StructLayout(La youtKind.Explic it, Size=6)]
struct S
{
[FieldOffset(0)]public byte b1;
[FieldOffset(1)]public byte b2;
[FieldOffset(2)]public byte b3;
[FieldOffset(3)]public byte b4;
[FieldOffset(4)]public byte b5;
[FieldOffset(5)]public byte b6;
[FieldOffset(0)]public short s1;
[FieldOffset(2)]public short s2;
[FieldOffset(4)]public short s3;
}

Willy.

Nov 17 '05 #7
"Dave" <pi******@gmail .com> wrote in message
news:11******** *************@o 13g2000cwo.goog legroups.com...
Thanks for the response. Do you have an example of doing this that I
could take a look at? Do you still use the setup project to generate
the install? I'm pretty sure I can work around the struct issue which
might be more expedient than going down the route you're suggesting.
Fixing the struct is probably required anyway so might be the best way to
go. I found using the API a better way to go in my case. I don't have a C#
sample because I did it as an addin for NSIS in visual C 6 but look up help
on CreateService, OpenSCManager, QueryServiceSta tus, CloseServiceHan dle and
ControlService. There is a good example in the help which I pretty much
copied.

Nov 17 '05 #8
Hi Dave,
Regarding the struct, IMO the way to go is Willy's , you have to pay
attention to the byte ordering ( little/big endian) though.

Regarding the install, are you including an installer?
Right click the project in the project explorer and select Add an installer,
then add a setup project to the solution, add the primary output of your
project, and finally add a custom action (for all the 4 events) of your
primary output.
I had a link from MSDN explaining all this, but cannot find it right now
:( , will post it when I find it.
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


"Dave" <pi******@gmail .com> wrote in message
news:11******** ************@g4 9g2000cwa.googl egroups.com...
Good point, must have been having a bad day. So my structure is now
hopefully correct:

[StructLayout(La youtKind.Explic it, Size=6)]
private struct StandardFrame
{
[FieldOffset(0)] public byte [] frame;
[FieldOffset(0)] public UInt16 integrityCheck;
[FieldOffset(2)] public UInt16 sequenceNo;
[FieldOffset(4)] public UInt16 dataLength;
}

It is a 6-byte framing sequence that is a packet header for
communicating with a mainframe system.

Sadly fixing the structure declaration doesn't actually fix the
installer issue. When I run installutil against my service assembly it
throws an exception with the following call stack:

An exception occurred while trying to find the installers in the
c:\documents and settings\davec\ my documents\visua l studio
projects\hsmthr iftlineservice\ bin\debug\hsmth riftlineservice .exe
assembly.
System.Reflecti on.ReflectionTy peLoadException : One or more of the types
in the assembly unable to load.
at System.Reflecti on.Module.GetTy pesInternal(Sta ckCrawlMark&
stackMark)
at System.Reflecti on.Module.GetTy pes()
at
System.Configur ation.Install.A ssemblyInstalle r.GetInstallerT ypes(Assembly
assem)
at
System.Configur ation.Install.A ssemblyInstalle r.InitializeFro mAssembly()

To me it appears to be trolling through the types in the assembly and
trips up on the struct.

Nov 17 '05 #9
Hi,

Another suggestion, I would test ALL your code and communication from either
a windows or console app, only when you are sure it does work move it to a
windows service.
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


"Dave" <pi******@gmail .com> wrote in message
news:11******** ************@g4 9g2000cwa.googl egroups.com...
Good point, must have been having a bad day. So my structure is now
hopefully correct:

[StructLayout(La youtKind.Explic it, Size=6)]
private struct StandardFrame
{
[FieldOffset(0)] public byte [] frame;
[FieldOffset(0)] public UInt16 integrityCheck;
[FieldOffset(2)] public UInt16 sequenceNo;
[FieldOffset(4)] public UInt16 dataLength;
}

It is a 6-byte framing sequence that is a packet header for
communicating with a mainframe system.

Sadly fixing the structure declaration doesn't actually fix the
installer issue. When I run installutil against my service assembly it
throws an exception with the following call stack:

An exception occurred while trying to find the installers in the
c:\documents and settings\davec\ my documents\visua l studio
projects\hsmthr iftlineservice\ bin\debug\hsmth riftlineservice .exe
assembly.
System.Reflecti on.ReflectionTy peLoadException : One or more of the types
in the assembly unable to load.
at System.Reflecti on.Module.GetTy pesInternal(Sta ckCrawlMark&
stackMark)
at System.Reflecti on.Module.GetTy pes()
at
System.Configur ation.Install.A ssemblyInstalle r.GetInstallerT ypes(Assembly
assem)
at
System.Configur ation.Install.A ssemblyInstalle r.InitializeFro mAssembly()

To me it appears to be trolling through the types in the assembly and
trips up on the struct.

Nov 17 '05 #10

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

Similar topics

0
1390
by: chriss | last post by:
Hello everybody! I'm very bad in English but I'm going to try to explain my problem. I have a python program and this program is a service. chronologically: 1. I install my program like service -> it's ok 2. I start the service -> it's ok 3. I stop the service -> it's ok
4
386
by: DraguVaso | last post by:
Hi, I developped a Windows Service in VB.NET (2005). I need to have it installed two times on 1 machine. When I want to install it a second time, the setup doesn't allow me to install it again in an other directory, but only to repair or remove the other version. I get arround this by simply copying the files of the first installed in a second directory.
0
1664
by: poi | last post by:
Running the code below, I get the error Cannot start service from the command line opr debugger. A Windows Service must first be installed (using installutil.exe) and then started with the ServerExplorer..... But the text log from my install shows this: Running a transacted installation.
4
13909
by: Chua Wen Ching | last post by:
Hi there, I had a union in C: typedef union TagMessage { struct { unsigned char avalue; unsigned char bvalue; } a;
3
57011
by: Jeremy S. | last post by:
On my dev machine (XP/Pro with VS.NET 2003) I have been developing a Windows Service and installing it on the local machine by opening the Visual Studio Command Prompt and then executing . Now I want to test this service on a Windows Server 2003 box that doesn't have the Visual Studio Command prompt. How do I go about installing the service on the Windows Server 2003 box? Thanks!
2
4690
by: letibal | last post by:
Hello, I have written a windows service and created an installer for it. The service runs under the system accounts. When started, it launches a GUI. By default, the InteractiveProcess property of the service is not set (this can be checked by right-clicking on the service in the Services window (Admin tools>Services), choosing Properties, LogOn tab). In order to enable my service to launch a GUI at startup, I added the following lines...
15
4236
by: Joseph Geretz | last post by:
OK, I'll admit it up front - I just don't get it. Here's our previous VS2003 development model. Developers develop the WS solution on their own workstations, using their own IIS web servers mapped to the local devleopment folder. Project compiles to a subfolder .\bin. To deploy, the asmx page and bin subfolder are copied to the production server. So now I upgrade to VS2005. OK, so except for the name, everything is changed. No more...
0
1063
by: Ayrin | last post by:
The code below works fine on my Windows2003, dotnet 1.1 server. UNTIL I install service pak one for Windows 2003. After I install SP1 this code brings up the Open/save box but one you select something, nothing happens (0% downloads) If I run this code on my dev machine with winXPsp2 and IE7, the code only works for text files. Other files will download, but they are corrupt when I open them.(missing bytes I think) Does anyone have...
5
3313
by: dm3281 | last post by:
I'm really starting to hate writing services -- or trying to, anyway. Why do I need to rename my project to the service name? Why do I need to set the "ServiceName" property to my service name? Why do I need to set a property within my code to the service name? Are all these required or am I just doing this for consistency purposes?
0
9711
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...
1
10331
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10087
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9166
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...
0
6861
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
5667
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4306
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.