相关文章推荐
茫然的煎饼  ·  Python ...·  1 周前    · 
茫然的煎饼  ·  Get Up and Running ...·  9 月前    · 
茫然的煎饼  ·  【TS】一、类型注解 ·  9 月前    · 
茫然的煎饼  ·  ios html5 video m3u8 ...·  9 月前    · 
茫然的煎饼  ·  CPLEX出现'q1' is not ...·  10 月前    · 
严肃的皮蛋  ·  Retrieve Original ...·  19 小时前    · 
严肃的围巾  ·  C++内部函数与外部函数 | ...·  19 小时前    · 
性感的绿豆  ·  SQL ...·  19 小时前    · 
完美的充值卡  ·  A Basic AWS Lambda ...·  19 小时前    · 

You can check what resource names are available:

string[] names = this.GetType().Assembly.GetManifestResourceNames();

And then if Resource exists write correct name of Resource

Load the assembly where the resource is embedded, iterate through the GetManifestResourceNames to find the Fully Qualified Resource name which is then used to GetManifestResourceStream.

You can try

var assembly = Assembly.LoadFrom(Assembly.GetAssembly(typeof(MainWindow)).Location);
string[] names = assembly.GetManifestResourceNames();
var stream = assembly.GetManifestResourceStream(names[0]);
                                            

Just an update to .NET 5. What helped me to find out the name of the resources to help fix my issue in .NET 5 was the following:

string[] names = Assembly.GetCallingAssembly().GetManifestResourceNames();
                foreach (var name in names)
                    Console.WriteLine(name);
                                

Related Query

  • System Environment Variable with connection string returns null value when called in .net core 2.1
  • Why does ServiceStack OrmLite crash with null exception when I add OrmLite.Firebird?
  • Why does my dynamically created array of custom types return with null value instances?
  • Why IEnumerable<T> returns null here?
  • Why does a variable turn null after initialized in the Page_Init?
  • ASP.NET Core 3 - Logging with NLog does not log exceptions
  • Why does string EndsWith and StartsWith equals true with string.Empty
  • FromBody in ASP.NET Core API returns null
  • Why does digitally signing PDF with iTextSharp increases file size for 9MB
  • What's wrong with my AES encryption function in C#? Why does it return zero length data?
  • Why does Application.GetResourceStream always return null in WP7?
  • Why does HttpWebResponse return a null terminated string?
  • Why does default comparer consider null to be less than a value
  • Does dotnet core have a built in JSON serializer/deserializer for console applications?
  • why html action link does not pass the null Id value when use an id
  • Why is the fractional part of a double not showing with Console.Write, when it does with a decimal?
  • Weird Syntax with Func<T,Z> as parameter, why does it work?
  • Why does WebRequest work with invalid URL?
  • Why does asp .net core not log exceptions in async methods?
  • Linq query returns null when using the EF core relationship
  • Why does my C# Winforms program with a timer get bogged down after a day?
  • Using FileStream with dotnet core
  • Why does WNetGetUniversalName fail with ERROR_NOT_SUPPORTED on some machines?
  • Write a SQL query with a subquery in .NET Core using Entity Framework that returns a list of items with varying number of returned child rows
  • Deserialization with System.Text.Json in .NET Core 3.1 results in null property values
  • Why does interface comparison fail with Assembly.ReflectionOnlyLoadFrom() and not with Assembly.LoadFrom()?
  • Adding constraint with HttpGet (...) does not work in ASP.Net Core
  • Why does this .Net Core implementation of ImmutableList<T> not produce an infinite loop?
  • why does my loop work with the "&&" operator but not "||" or "^"?
  • Why does only the first DropDown gets populated when generating DropDown Dynamically with Jquery?
  • More Query from same tag

  • Some form events (Load, Shown) stopped working
  • How to use for loop to sum items
  • IE6 AJAX Response Data Issue
  • How to create a basic user login using asp.net-mvc?
  • when using iText, how to SetPdfVersion in C#?
  • Error: "The process cannot access.... because it is being used by another process. " in Delete Image
  • How to loop trough dictionary and check if the ReadLine input is equal to the Dictionary Key
  • Syntax error (missing operator) in query expression in C#
  • HttpPostedFileBase returns Null MVC3
  • Automatic highlighting a part of the text in a TextBox or RichTextBox
  • Can I build a console application into my C# GUI application?
  • Delphi equivalent code of C# extraction of Embedded Resource
  • Specflow C# Date Functions
  • Getting different base64 encoding while porting to PHP from C#
  • How to assign a value to a property using an expression?
  • C# XDocument get a attribute from a specific element
  • Text in the center of the box centering
  • Using Regex to extract part of a string
  • Extension method for list that performs arithmetic operation on list item
  • Clipboard is empty after setting text
  • ViewModel that automagically has same properties than generic model
  • An exam exercise about swapping items in an array in C#
  • CQS with out parameter
  • ADFS in asp.net c#
  • How can I suppress ExecutionContext capturing the current SynchronizationContext?
  • Is it possible to use a conditional construct to enable an attribute in Blazor?
  • In Visual Studio, is there a quick way to generate these types of comment blocks?
  • How to test bounds of a bidimensional array, to avoid indexOutOfRangeException (C#)
  • Compounding some arbitrary Regexes (Or, are many small Regexes better than one big one)
  • How should I configure development-testing environment for a SIP gateway
  •  
    推荐文章