System.ArgumentException的解决办法
2007-06-28 09:47
134 查看
者tag:开发心得 CSDN 推荐tag:asm 项目
上一篇: 新的一年,新的精彩 | 下一篇: 今天,您OLAP了吗(二)
function StorePage(){d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(keyit=window.open('http://www.365key.com/storeit.aspx?t='+escape(d.title)+'&u='+escape(d.location.href)+'&c='+escape(t),'keyit','scrollbars=no,width=475,height=575,left=75,top=20,status=no,resizable=yes'));keyit.focus();}
![](http://blog.csdn.net/images/authorship.gif)
使用Bitmap.FromStream(GetType().Assembly.GetManifestResourceStream())出现System.ArgumentException的解决办法
今天碰到了一个非常“妖”的问题,就是在自己的数据挖掘开发包中需要动态加载一张图片,以在数据挖掘结果图表Chart中显示,程序如下:
Image image = Bitmap.FromStream(
GetType().Assembly.GetManifestResourceStream( NameSpace+"." + mapname) );
但是调试时总会抛出异常“未处理的“System.ArgumentException”类型的异常出现在 system.drawing.dll 中。其他信息: “null”不是“stream”的有效值。”,显然GetTyp().Assembly.GetManifestResourceStream()方法并没有找到需要加载的图片。难道是命名空间的问题,我就采用
Assembly asm = Assembly.GetExecutingAssembly();
Image image = new Bitmap(asm.GetManifestResourceStream(asm.GetName().Name
+ "." +mapname));
和
string localNameSpace = this.GetType().Namespace;
Image image = Bitmap.FromStream(
GetType().Assembly.GetManifestResourceStream(localNameSpace + "." + mapname) );
这两种方式分别进行尝试,跟踪进去发现命名空间都是一样且正确的,结果仍返回同样的异常。
可是其他代码都没有问题啊,实在让人不得其解。
查了一下资料,发现有人提到Build Action" property should be set to " Embedded Resourse",我突然想到Assembly.GetManifestResourceStream 是从当前程序集加载指定的清单资源,呵呵,我要加载的图片仅仅
是放在项目文件夹中并包含在项目中,这个不能算是程序集中的资源阿。赶紧从项目文件列表中找到相应图片,果然发现图片的属性-〉生成操作类型是“编译”,将其改成“嵌入的资源”,重新编译,RUN。哈哈,一切都OK了。
上一篇: 新的一年,新的精彩 | 下一篇: 今天,您OLAP了吗(二)
function StorePage(){d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(keyit=window.open('http://www.365key.com/storeit.aspx?t='+escape(d.title)+'&u='+escape(d.location.href)+'&c='+escape(t),'keyit','scrollbars=no,width=475,height=575,left=75,top=20,status=no,resizable=yes'));keyit.focus();}
![](http://blog.csdn.net/images/authorship.gif)
使用Bitmap.FromStream(GetType().Assembly.GetManifestResourceStream())出现System.ArgumentException的解决办法
今天碰到了一个非常“妖”的问题,就是在自己的数据挖掘开发包中需要动态加载一张图片,以在数据挖掘结果图表Chart中显示,程序如下:
Image image = Bitmap.FromStream(
GetType().Assembly.GetManifestResourceStream( NameSpace+"." + mapname) );
但是调试时总会抛出异常“未处理的“System.ArgumentException”类型的异常出现在 system.drawing.dll 中。其他信息: “null”不是“stream”的有效值。”,显然GetTyp().Assembly.GetManifestResourceStream()方法并没有找到需要加载的图片。难道是命名空间的问题,我就采用
Assembly asm = Assembly.GetExecutingAssembly();
Image image = new Bitmap(asm.GetManifestResourceStream(asm.GetName().Name
+ "." +mapname));
和
string localNameSpace = this.GetType().Namespace;
Image image = Bitmap.FromStream(
GetType().Assembly.GetManifestResourceStream(localNameSpace + "." + mapname) );
这两种方式分别进行尝试,跟踪进去发现命名空间都是一样且正确的,结果仍返回同样的异常。
可是其他代码都没有问题啊,实在让人不得其解。
查了一下资料,发现有人提到Build Action" property should be set to " Embedded Resourse",我突然想到Assembly.GetManifestResourceStream 是从当前程序集加载指定的清单资源,呵呵,我要加载的图片仅仅
是放在项目文件夹中并包含在项目中,这个不能算是程序集中的资源阿。赶紧从项目文件列表中找到相应图片,果然发现图片的属性-〉生成操作类型是“编译”,将其改成“嵌入的资源”,重新编译,RUN。哈哈,一切都OK了。
相关文章推荐
- 【转载】使用Bitmap.FromStream(GetType().Assembly.GetManifestResourceStream())出现System.ArgumentException的解决办法
- 使用Bitmap.FromStream(GetType().Assembly.GetManifestResourceStream())出现System.ArgumentException的解决办法
- 使用Bitmap.FromStream(GetType().Assembly.GetManifestResourceStream())出现System.ArgumentException的解决办法
- System.ArgumentException: 已添加项。字典中的关键字:“RegEx”所添加的关键字:“RegEx” 异常的解决办法
- 使用Bitmap.FromStream(GetType().Assembly.GetManifestResourceStream())出现System.ArgumentException的解决办法
- 【求助,已经解决】未能注册sharepoint服务。已引发类型为SYSTEM.ARGUMENTEXCEPTION异常,其他异常信息,加密和解密过程中出错,系统错误代码为997
- 异常详细信息: System.Data.SqlClient.SqlException: 用户 'NT AUTHORITY\IUSR' 登录失败解决办法
- .net应用程序安装部署时异常 Error 1001. 在初始化安装时发生异常 System.BadImageFormatException:未能加载文件或程序集 的解决办法【成功解决】
- Andriod java.lang.IllegalArgumentException:already added:异常解决办法
- Unity 安卓下使用串口提示:System.DllNotFoundException: MonoPosixHelper的解决办法
- 异常详细信息: System.DllNotFoundException: 无法加载 DLL (oci.dll)的解决办法
- 调用微信退款接口或发红包接口时出现System.Security.Cryptography.CryptographicException: 出现了内部错误 解决办法
- System.FormatException: GUID 应包含带 4 个短划线的 32 位数(xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)。解决办法
- IllegalArgumentException错误的解决办法
- 调用微信退款接口时出现System.Security.Cryptography.CryptographicException: 出现了内部错误 解决办法
- c#中 Exception of type 'System.OutOfMemoryException' was throw的解决办法
- ASP.net 异常详细信息: System.ArgumentOutOfRangeException: 索引超出范围。必须为非负值并小于集合大小。解决方法
- java.lang.IllegalArgumentException: 请设置InstanceName的解决办法
- System.Runtime.InteropServices.COMException解决办法
- C# post数据时 出现如下错误: System.Net.WebException: 远程服务器返回错误: (417) Expectation Failed 的解决办法