本文介绍了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,
推荐答案
这篇关于Assembly.GetExecutingAssembly()的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!