本文介绍了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的解决方案资源管理器中,右键单击该项,选择属性。将Build 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()的问题
发布评论