LayoutKind.Explicit中断服务安装 [英] LayoutKind.Explicit breaks service install

查看:52
本文介绍了LayoutKind.Explicit中断服务安装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的结构声明为:


[StructLayout(LayoutKind.Explicit,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;


}


这是Windows Service C#应用程序的一部分。我添加了一个安装程序和

安装项目,但安装失败,并且无法获取安装程序类型

<可执行文件名称> - >

程序集中的一个或多个类型无法加载。


我已将问题缩小到此结构。如果我制作结构

LayoutKind.Sequential并删除FieldOffset值,服务

安装没问题。显然这不是我想要的,结构是

用作联合。这真让我难过,我可以在它周围工作

但我宁愿使用这种方法。


任何线索都会感激地接受。

解决方案

戴夫,


好​​吧,我看到的第一个问题是你设定的大小结构

到6,然而,你有一个偏移四的整数(四个字节),这意味着

结构的大小需要为8。


您确定不希望偏移量为2吗?或者尺寸是

不正确?


希望这会有所帮助。

-

- Nicholas Paldino [.NET / C#MVP]

- mv*@spam.guard.caspershouse.com


" Dave" < PI ****** @ gmail.com>在消息中写道

news:11 ********************** @ f14g2000cwb.googlegr oups.com ...

我的结构声明为:

[StructLayout(LayoutKind.Explicit,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 ;

}
这是Windows Service C#应用程序的一部分。我添加了一个安装程序和
安装项目,但安装失败,并且<可执行文件的名称>中的无法获取安装程序类型。 - >
程序集中的一个或多个类型无法加载。

我已将问题缩小到此结构。如果我制作结构
LayoutKind.Sequential并删除FieldOffset值,服务
安装没问题。显然这不是我想要的,结构被用作联合。这真让我难过,我可以围绕它工作但是我更愿意使用这种方法。

任何线索都会感激地接受。



" Dave和QUOT; < PI ****** @ gmail.com>在消息中写道

news:11 ********************** @ f14g2000cwb.googlegr oups.com ...

我已将问题缩小到这个结构。如果我制作结构
LayoutKind.Sequential并删除FieldOffset值,服务
安装没问题。显然这不是我想要的,结构被用作联合。这真让我难过,我可以在周围工作,但我宁愿使用这种方法。

任何线索都会感激地接受。




我从我的服务中转储安装程序并使用Windows API安装它

我的程序设置运行。


或者,作为尼古拉斯说,你的结构很糟糕。


Michael


好点,一定是天气不好。所以我的结构现在是

希望正确:


[StructLayout(LayoutKind.Explicit,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;

}

这是一个6字节的成帧序列,是与大型机系统通信的
的数据包标题。


遗憾地修复结构声明实际上并没有解决

安装程序问题。当我对我的服务程序集运行installutil时,

使用以下调用堆栈抛出异常:


尝试查找<中的安装程序时发生异常br />
c:\documents and settings \davec \ my documents \visual studio

projects \hsmthriftlineservice \bin\debug \hsmthriftl ineservice.exe

程序集。

System.Reflection.ReflectionTypeLoadException:程序集中的一个或多个类型

无法加载。

在System.Reflection.Module.GetTypesInternal(StackCra wlMark&

stackMark)

在System.Reflection.Module.GetTypes()

at

System.Configuration.Install.AssemblyInstaller.Get InstallerTypes(Assembly

assem)

at

System.Configuration .Install.AssemblyInstaller.Ini tializeFromAssembly()


对我来说,它似乎是通过装配中的类型来控制的,并且

绊倒结构。


I have a structure declared as:

[StructLayout(LayoutKind.Explicit, 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.Sequential 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.

解决方案

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.com

"Dave" <pi******@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...

I have a structure declared as:

[StructLayout(LayoutKind.Explicit, 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.Sequential 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.



"Dave" <pi******@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...

I''ve narrowed the problem down to this struct. If I make the struct
LayoutKind.Sequential 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


Good point, must have been having a bad day. So my structure is now
hopefully correct:

[StructLayout(LayoutKind.Explicit, 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\visual studio
projects\hsmthriftlineservice\bin\debug\hsmthriftl ineservice.exe
assembly.
System.Reflection.ReflectionTypeLoadException: One or more of the types
in the assembly unable to load.
at System.Reflection.Module.GetTypesInternal(StackCra wlMark&
stackMark)
at System.Reflection.Module.GetTypes()
at
System.Configuration.Install.AssemblyInstaller.Get InstallerTypes(Assembly
assem)
at
System.Configuration.Install.AssemblyInstaller.Ini tializeFromAssembly()

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


这篇关于LayoutKind.Explicit中断服务安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆