Need to embed a json file as a source for testing in my .NET Core application. The author of this post http://codeopinion.com/asp-net-core-embedded-resource/ provided sample code that included the use of var assembly = Assembly.GetExecutingAssembly();
However when I try this I get the error: Cannot resolve symbol ‘GetExecutingAssembly’ and ‘Assembly’ does not contain a definition for ‘GetExecuringAssembly’
Assembly property to get the currently executing assembly based on a type contained in that assembly. It also calls the GetExecutingAssembly method to show that it returns an Assembly object that represents the same assembly.
Loads an assembly given its AssemblyName. The assembly is loaded into the domain of the caller using the supplied evidence. Loads the assembly with a common object file format (COFF)-based image containing an emitted assembly. The assembly is loaded into the application domain of the caller.
Namespace: System.Reflection. Summary. Defines an Assembly, which is a reusable, versionable, and self-describing building block of a common language runtime application.
If you are targeting .NET Standard 1.5 or above, you may call any of the following:
System.Reflection.Assembly.GetExecutingAssembly(); System.Reflection.Assembly.GetEntryAssembly(); System.Reflection.Assembly.GetCallingAssembly();
If targeting earlier versions of .NET Standard then the typeof(SomeClass).GetTypeInfo().Assembly
method is the only way.
There is no "static" Assembly
class in .NET Standard prior to version 1.5
. Instead you have to do something like:
typeof(<AClassHere>).GetTypeInfo().Assembly
Where <AClassHere>
should be replaced by the name of a class/type in the assembly you wish to load.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With