Assembly.GetExecutingAssembly()的问题

编程入门 行业动态 更新时间:2024-10-19 20:24:06
本文介绍了Assembly.GetExecutingAssembly()的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在我的代码中尝试使用以下功能:

Hi, I am trying using below function in my code:

var assembly = Assembly.GetExecutingAssembly(); var resourceName = "C://reza.txt"; string result = ""; using (Stream stream = assembly.GetManifestResourceStream(resourceName)) using (StreamReader reader = new StreamReader(stream)) { result = reader.ReadToEnd(); }

但对于此部分:new StreamReader(stream)) 我得到以下错误:

But for this section: "new StreamReader(stream)) I get below errors:

System.ArgumentNullException was unhandled Message=Value cannot be null. Parameter name: stream Source=mscorlib ParamName=stream StackTrace: at System.IO.StreamReader..ctor(Stream stream, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize) at System.IO.StreamReader..ctor(Stream stream) at SendEmail.Program.Email(String ename, String name) in C:\Users\Reza\Desktop\Test_Projects\C#\SendEmail\SendEmail\Program.cs:line 44 at SendEmail.Program.Main(String[] args) in C:\Users\Reza\Desktop\Test_Projects\C#\SendEmail\SendEmail\Program.cs:line 21 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException:

如何解决这个问题? 问候,

How to fix that? Regards,

推荐答案

尝试从资源名称中删除c:/。 Try removing the "c:/" from your resource name.

在Visual Studio的解决方案资源管理器中,右键单击该项,选择属性。将Bu​​ild Action设置为Embedded resource。然后重新构建您的应用程序。 In Visual Studio's solution explorer, right click on that item, select properties. Set "Build Action" to "Embedded resource". Then re-build your application.

更多推荐

Assembly.GetExecutingAssembly()的问题

本文发布于:2023-11-13 14:42:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1584608.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Assembly   GetExecutingAssembly

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!