汗颜,写EnterpriseServices竟然忘了设置ComVisible了 http://blog.joycode.com/ghj/archive/2006/10/24/75866.aspx

本文记录了一次在部署企业服务时遇到的错误及其解决过程。作者在修改ClassLibrary项目时,由于AssemblyInfo.cs文件中的ComVisible属性被设置为false而导致部署失败。最终通过将该属性更改为true解决了问题。

今天在写一个企业服务组件,是在一个ClassLibrary项目基础上修改的.这个企业服务中包含很复杂的业务逻辑,其中用到了Singleton 模式来确保只有一个缓存。相关技术参看:http://sajadi.co.uk/dflat/archives/2005/11/creating_a_cach.html

编译时候没有任何问题,然后就是部署,结果部署的时候报下面错误:

出现下列安装错误:
1: 在程序集中找到无效的 ServicedComponent 派生类。
(类必须是公共的、具体的、有公共的默认构造函数并满足所有其他 ComVisibility 要求)

这个错误信息让我对是否可以在企业服务中使用单键模式产生怀疑。网上也有不少对企业服务使用单键模式的讨论。观点各不相同,结果一下午就迷失在这里了。

http://www.pcreview.co.uk/forums/thread-1382837.php
http://www.pcreview.co.uk/forums/thread-1382837-2.php

一直到快下班,才发现,根本不是上述使用单键模式的问题,而是ClassLibrary项目的AssemblyInfo.cs文件,默认设置是 [assembly: ComVisible(false)]

如果你要做EnterpriseServices,则需要把这个修改为true ,汗颜,最基本的地方给忘掉了。

在AssemblyInfo.cs文件ComVisible上有明确的提示,自己竟然没留意,提示如下:

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components.? If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(true)]

namespace System.Drawing { // // 摘要: // 封装 GDI+ 位图,此位图由图形图像及其属性的像素数据组成。 System.Drawing.Bitmap 是用于处理由像素数据定义的图像的对象。 [ComVisible(true)] [Editor("System.Drawing.Design.BitmapEditor, System.Drawing.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))] public sealed class Bitmap : Image { // // 摘要: // 从指定的文件初始化 System.Drawing.Bitmap 类的新实例。 // // 参数: // filename: // 位图文件的名称和路径。 // // 异常: // T:System.IO.FileNotFoundException: // 找不到指定文件。 public Bitmap(string filename); // // 摘要: // 从指定的数据流初始化 System.Drawing.Bitmap 类的新实例。 // // 参数: // stream: // 用于加载图像的数据流。 // // 异常: // T:System.ArgumentException: // stream 不包含图像数据,或者为 null。 或 - stream 包含一个 PNG 图像文件,其一维大于 65,535 像素。 public Bitmap(Stream stream); // // 摘要: // 从指定的现有图像初始化 System.Drawing.Bitmap 类的新实例。 // // 参数: // original: // 从中创建新 System.Drawing.Bitmap 的 System.Drawing.Image。 public Bitmap(Image original); // // 摘要: // 从指定的文件初始化 System.Drawing.Bitmap 类的新实例。 // // 参数: // filename: // 位图文件的名称。 // // useIcm: // 如果要为此 System.Drawing.Bitmap 使用颜色校正,则为 true;否则为 false。 public Bitmap(string filename, bool useIcm); // // 摘要: // 从指定的资源初始化 System.Drawing.Bitmap 类的新实例。 // // 参数: // type: // 用于提取资源的类。 // // resource: // 资源的名称。 public Bitmap(Type type, string resource); // // 摘要: // 从指定的数据流初始化 System.Drawing.Bitmap 类的新实例。 // // 参数: // stream: // 用于加载图像的数据流。 // // useIcm: // 如果要为此 System.Drawing.Bitmap 使用颜色校正,则为 true;否则为 false。 // // 异常: // T:System.ArgumentException: // stream 不包含图像数据,或者为 null。 或 - stream 包含一个 PNG 图像文件,其一维大于 65,535 像素。 public Bitmap(Stream stream, bool useIcm); // // 摘要: // 用指定的大小初始化 System.Drawing.Bitmap 类的新实例。 // // 参数: // width: // 新 System.Drawing.Bitmap 的宽度(以像素为单位)。 // // height: // 新 System.Drawing.Bitmap 的高度(以像素为单位)。 // // 异常: // T:System.Exception: // 操作失败。 public Bitmap(int width, int height); // // 摘要: // 从指定的现有图像(缩放到指定大小)初始化 System.Drawing.Bitmap 类的新实例。 // // 参数: // original: // 从中创建新 System.Drawing.Bitmap 的 System.Drawing.Image。 // // newSize: // 表示新的 System.Drawing.Bitmap 大小的 System.Drawing.Size 结构。 // // 异常: // T:System.Exception: // 操作失败。 public Bitmap(Image original, Size newSize); // // 摘要: // 用指定的大小和格式初始化 System.Drawing.Bitmap 类的新实例。 // // 参数: // width: // 新 System.Drawing.Bitmap 的宽度(以像素为单位)。 // // height: // 新 System.Drawing.Bitmap 的高度(以像素为单位)。 // // format: // 新 System.Drawing.Bitmap 的像素格式。 这必须指定以格式开头的值。 // // 异常: // T:System.ArgumentException: // 已指定名称不以格式开头的 System.Drawing.Imaging.PixelFormat 值。 例如,指定 System.Drawing.Imaging.PixelFormat.Gdi // 将导致一个 System.ArgumentException,但 System.Drawing.Imaging.PixelFormat.Format48bppRgb // 不会出现这种情况。 public Bitmap(int width, int height, PixelFormat format); // // 摘要: // 用指定的大小和指定的 System.Drawing.Graphics 对象的分辨率初始化 System.Drawing.Bitmap 类的新实例。 // // 参数: // width: // 新 System.Drawing.Bitmap 的宽度(以像素为单位)。 // // height: // 新 System.Drawing.Bitmap 的高度(以像素为单位)。 // // g: // System.Drawing.Graphics 对象,该对象为新 System.Drawing.Bitmap 指定分辨率。 // // 异常: // T:System.ArgumentNullException: // g 为 null。 public Bitmap(int width, int height, Graphics g); // // 摘要: // 从指定的现有图像(缩放到指定大小)初始化 System.Drawing.Bitmap 类的新实例。 // // 参数: // original: // 从中创建新 System.Drawing.Bitmap 的 System.Drawing.Image。 // // width: // 新 System.Drawing.Bitmap 的宽度(以像素为单位)。 // // height: // 新 System.Drawing.Bitmap 的高度(以像素为单位)。 // // 异常: // T:System.Exception: // 操作失败。 public Bitmap(Image original, int width, int height); // // 摘要: // 用指定的大小、像素格式和像素数据初始化 System.Drawing.Bitmap 类的新实例。 // // 参数: // width: // 新 System.Drawing.Bitmap 的宽度(以像素为单位)。 // // height: // 新 System.Drawing.Bitmap 的高度(以像素为单位)。 // // stride: // 指定相邻扫描行开始处之间字节偏移量的整数。 这通常(但不一定)是以像素格式表示的字节数(例如,2 表示每像素 16 位)乘以位图的宽度。 传递给此参数的值必须为 // 4 的倍数。 // // format: // 新 System.Drawing.Bitmap 的像素格式。 这必须指定以格式开头的值。 // // scan0: // 指针指向包含像素数据的字节数组。 // // 异常: // T:System.ArgumentException: // 已指定名称不以格式开头的 System.Drawing.Imaging.PixelFormat 值。 例如,指定 System.Drawing.Imaging.PixelFormat.Gdi // 将导致一个 System.ArgumentException,但 System.Drawing.Imaging.PixelFormat.Format48bppRgb // 不会出现这种情况。 public Bitmap(int width, int height, int stride, PixelFormat format, IntPtr scan0); // // 摘要: // 从图标的 Windows 图柄创建 System.Drawing.Bitmap。 // // 参数: // hicon: // 图标的图柄。 // // 返回结果: // 此方法创建的 System.Drawing.Bitmap。 public static Bitmap FromHicon(IntPtr hicon); // // 摘要: // 从指定的 Windows 资源创建 System.Drawing.Bitmap。 // // 参数: // hinstance: // 包含该资源的可执行文件的实例图柄。 // // bitmapName: // 包含资源位图名称的字符串。 // // 返回结果: // 此方法创建的 System.Drawing.Bitmap。 public static Bitmap FromResource(IntPtr hinstance, string bitmapName); // // 摘要: // 创建此 System.Drawing.Bitmap(用指定的 System.Drawing.Imaging.PixelFormat 枚举定义)部分的副本。 // // 参数: // rect: // 定义此 System.Drawing.Bitmap 中要复制的部分。 // // format: // 为目标 System.Drawing.Bitmap 指定 System.Drawing.Imaging.PixelFormat 枚举。 // // 返回结果: // 此方法创建的 System.Drawing.Bitmap。 // // 异常: // T:System.OutOfMemoryException: // rect 位于源位图边界之外。 // // T:System.ArgumentException: // rect 的高度或宽度为 0。 public Bitmap Clone(RectangleF rect, PixelFormat format); // // 摘要: // 创建此 System.Drawing.Bitmap(它由 System.Drawing.Rectangle 结构并使用指定的 System.Drawing.Imaging.PixelFormat // 枚举定义)部分的副本。 // // 参数: // rect: // 定义此 System.Drawing.Bitmap 中要复制的部分。 坐标相对于此 System.Drawing.Bitmap。 // // format: // 新 System.Drawing.Bitmap 的像素格式。 这必须指定以格式开头的值。 // // 返回结果: // 此方法创建的新 System.Drawing.Bitmap。 // // 异常: // T:System.OutOfMemoryException: // rect 位于源位图边界之外。 // // T:System.ArgumentException: // rect 的高度或宽度为 0。 或 - 已指定名称不以格式开头的 System.Drawing.Imaging.PixelFormat 值。 例如,指定 // System.Drawing.Imaging.PixelFormat.Gdi 将导致一个 System.ArgumentException,但 System.Drawing.Imaging.PixelFormat.Format48bppRgb // 不会出现这种情况。 public Bitmap Clone(Rectangle rect, PixelFormat format); // // 摘要: // 从此 System.Drawing.Bitmap 创建 GDI 位图对象。 // // 返回结果: // 此方法创建的 GDI 位图对象的图柄。 // // 异常: // T:System.ArgumentException: // 此位图的高度或宽度大于 System.Int16.MaxValue。 // // T:System.Exception: // 操作失败。 [EditorBrowsable(EditorBrowsableState.Advanced)] public IntPtr GetHbitmap(); // // 摘要: // 从此 System.Drawing.Bitmap 创建 GDI 位图对象。 // // 参数: // background: // 一个 System.Drawing.Color 结构,指定背景色。 如果位图完全不透明,则忽略此参数。 // // 返回结果: // 此方法创建的 GDI 位图对象的图柄。 // // 异常: // T:System.ArgumentException: // 此位图的高度或宽度大于 System.Int16.MaxValue。 // // T:System.Exception: // 操作失败。 [EditorBrowsable(EditorBrowsableState.Advanced)] public IntPtr GetHbitmap(Color background); // // 摘要: // 返回图标的图柄。 // // 返回结果: // 图像与 System.Drawing.Bitmap 相同的图标的 Windows 图柄。 // // 异常: // T:System.Exception: // 操作失败。 [EditorBrowsable(EditorBrowsableState.Advanced)] public IntPtr GetHicon(); // // 摘要: // 获取此 System.Drawing.Bitmap 中指定像素的颜色。 // // 参数: // x: // 要检索的像素的 X 坐标。 // // y: // 要检索的像素的 Y 坐标。 // // 返回结果: // 表示指定像素颜色的 System.Drawing.Color 结构。 // // 异常: // T:System.ArgumentOutOfRangeException: // x 小于 0,或者大于或等于 System.Drawing.Image.Width。 或 - y 小于 0,或者大于或等于 System.Drawing.Image.Height。 // // T:System.Exception: // 操作失败。 public Color GetPixel(int x, int y); // // 摘要: // 将 System.Drawing.Bitmap 锁定到系统内存中。 // // 参数: // rect: // 一个 System.Drawing.Rectangle 结构,指定要锁定的 System.Drawing.Bitmap 部分。 // // flags: // 一个 System.Drawing.Imaging.ImageLockMode 枚举,指定 System.Drawing.Bitmap 的访问级别(读/)。 // // format: // 一个 System.Drawing.Imaging.PixelFormat 枚举,指定此 System.Drawing.Bitmap 的数据格式。 // // 返回结果: // 包含有关此锁定操作信息的 System.Drawing.Imaging.BitmapData。 // // 异常: // T:System.ArgumentException: // System.Drawing.Imaging.PixelFormat 不是特定的每像素位数值。 或 - 为位图传入了错误的 System.Drawing.Imaging.PixelFormat。 // // T:System.Exception: // 操作失败。 public BitmapData LockBits(Rectangle rect, ImageLockMode flags, PixelFormat format); // // 摘要: // 将 System.Drawing.Bitmap 锁定到系统内存中 // // 参数: // rect: // 一个矩形结构,指定要锁定的 System.Drawing.Bitmap 部分。 // // flags: // 某个 System.Drawing.Imaging.ImageLockMode 值,指定 System.Drawing.Bitmap 的访问级别(读/)。 // // format: // 某个 System.Drawing.Imaging.PixelFormat 值,指定 System.Drawing.Bitmap 的数据格式。 // // bitmapData: // 包含锁定操作信息的 System.Drawing.Imaging.BitmapData。 // // 返回结果: // 包含锁定操作信息的 System.Drawing.Imaging.BitmapData。 // // 异常: // T:System.ArgumentException: // System.Drawing.Imaging.PixelFormat 值不是特定的每像素位数值。 或 - 为位图传入了错误的 System.Drawing.Imaging.PixelFormat。 // // T:System.Exception: // 操作失败。 public BitmapData LockBits(Rectangle rect, ImageLockMode flags, PixelFormat format, BitmapData bitmapData); // // 摘要: // 让 System.Drawing.Bitmap 的默认透明颜色为透明。 // // 异常: // T:System.InvalidOperationException: // System.Drawing.Bitmap 的图像格式为图标格式。 // // T:System.Exception: // 操作失败。 public void MakeTransparent(); // // 摘要: // 使指定的颜色对此 System.Drawing.Bitmap 透明。 // // 参数: // transparentColor: // 表示要使之透明的颜色的 System.Drawing.Color 结构。 // // 异常: // T:System.InvalidOperationException: // System.Drawing.Bitmap 的图像格式为图标格式。 // // T:System.Exception: // 操作失败。 public void MakeTransparent(Color transparentColor); // // 摘要: // 在此 System.Drawing.Bitmap 中设置指定像素的颜色。 // // 参数: // x: //设置的像素的 x 坐标。 // // y: //设置的像素的 y 坐标。 // // color: // 代表分配到指定像素的颜色的 System.Drawing.Color 结构。 // // 异常: // T:System.Exception: // 操作失败。 public void SetPixel(int x, int y, Color color); // // 摘要: // 设置此 System.Drawing.Bitmap 的分辨率。 // // 参数: // xDpi: // System.Drawing.Bitmap 的水平分辨率(以“点/英寸”为单位)。 // // yDpi: // System.Drawing.Bitmap 的垂直分辨率(以“点/英寸”为单位)。 // // 异常: // T:System.Exception: // 操作失败。 public void SetResolution(float xDpi, float yDpi); // // 摘要: // 从系统内存解锁此 System.Drawing.Bitmap。 // // 参数: // bitmapdata: // 一个 System.Drawing.Imaging.BitmapData,指定有关锁定操作的信息。 // // 异常: // T:System.Exception: // 操作失败。 public void UnlockBits(BitmapData bitmapdata); } }这个能不能看出
10-31
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值