Questions tagged [system.reflection]

System.Reflection is a namespace of the .NET framework. It contains types that retrieve information about assemblies, modules, members, parameters, and other entities in managed code by examining their metadata.

System.Reflection is a namespace of the .NET framework. It contains types that retrieve information about assemblies, modules, members, parameters, and other entities in managed code by examining their metadata.

References

1116 questions
21
votes
2 answers

Why does ICustomAttributeProvider.GetCustomAttributes() return object[] instead of Attribute[]?

Why does ICustomAttributeProvider.GetCustomAttributes() return object[] instead of Attribute[]? Is there any circumstance when using the ICustomAttributeProvider implementations from mscorlib and System assemblies will return objects that are not of…
smartcaveman
  • 41,281
  • 29
  • 127
  • 212
21
votes
4 answers

Create object instance of a class from its name in string variable

I don't know whether this is possible or not, but I would like to know if it is and, if so, how it works. So here is my question: I have 2-3 custom model classes of my own. For example, Customer, Employee and Product. I also have a class name in a…
Dhwani
  • 7,484
  • 17
  • 78
  • 139
20
votes
5 answers

How are CIL 'fault' clauses different from 'catch' clauses in C#?

According to the CLI standard (Partition IIA, chapter 19) and the MSDN reference page for the System.Reflection.ExceptionHandlingClauseOptions enum, there are four different kinds of exception handler blocks: catch clauses: "Catch all objects of…
stakx - no longer contributing
  • 83,039
  • 20
  • 168
  • 268
19
votes
3 answers

Get Types in assembly (error: System.Reflection.ReflectionTypeLoadException)

I'm receiving an Exception of type "Exception Details: System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information." with the following code: public…
s_h
  • 1,476
  • 2
  • 27
  • 61
18
votes
3 answers

Null Reference Exception with System.Reflection.Assembly

I have developed a Library for internal email reporting. When I am using that Library from another project (By Adding Reference). It gives NullReferenceException on the following line.…
Scorpion
  • 4,495
  • 7
  • 39
  • 60
18
votes
3 answers

Get assembly version in PCL

I have the following line of code in .NET 4.5 that I am trying to build as Portable Class Library. It's purpose is to get assembly version: this.GetType().Assembly.GetName().Version.Major; The problem is that Assembly.GetName() is not available in…
kls
  • 591
  • 3
  • 13
17
votes
2 answers

Include all navigation properties using Reflection in generic repository using EF Core

I'm working on creating a generic repository for an EF Core project to avoid having to write CRUD for all models. A major roadblock I've hit is navigation properties not being loaded since Core doesn't yet support lazy loading and the generic class…
Valuator
  • 3,262
  • 2
  • 29
  • 53
17
votes
3 answers

How to get constructor as MethodInfo using Reflection

The constructor looks like this: public NameAndValue(string name, string value) I need to get it as a MethodInfo using Reflection. It tried the following, but it does not find the constructor (GetMethod returns null). MethodInfo constructor =…
user65199
16
votes
1 answer

CreateType missing from TypeBuilder. How to port this?

Trying to port an application from .net 4.5 to .net core for a client. I'm noticing that CreateType is no longer part of TypeBuilder. I've searched through multiple of the new reflection libs with no luck. Does anyone know how to port this? Code in…
Zoey M
  • 714
  • 5
  • 17
15
votes
2 answers

Internal error when running visual studio project

I'm building a WPF application that currently only has UI elements in place. I'm trying to use some classes I made in another project by importing a dll. When I run the wpf application, Visual Studio pops up this dialog in the Team Explorer: The…
Batman
  • 541
  • 4
  • 25
14
votes
3 answers

Is C# namespace separator (.) defined somewhere?

Full name separator in C# is period character (.). e.g. System.Console.Write. Is this defined somewhere like Path.PathSeperator, or is it hard coded in .NET reflection classes as well? (e.g. is Type.FullName implemented as Type.Namespace + "." +…
ahmet alp balkan
  • 42,679
  • 38
  • 138
  • 214
13
votes
4 answers

How to convert PropertyInfo to property expression and use it to invoke generic method?

How to convert PropertyInfo to property expression which can be used to invoke StructuralTypeConfiguration.Ignore(Expression> propertyExpression) method? I tried to use…
Pol
  • 5,064
  • 4
  • 32
  • 51
13
votes
2 answers

How to get method name from inside that method without using reflection in C#

I want get the method name from inside itself. This can be done using reflection as shown below. But, I want to get that without using reflection System.Reflection.MethodBase.GetCurrentMethod().Name Sample code public void myMethod() { string…
13
votes
2 answers

Get only the current class members via Reflection

Assume this chunk of code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Reflection; namespace TestFunctionality { class Program { static void Main(string[]…
Aaron Azhari
  • 987
  • 1
  • 10
  • 24
13
votes
3 answers

C# reflection: If ... else?

I'm currently facing new problem with operators. Using following code, I want to make output that would be same as when using if ... else pair in C#. var method = new DynamicMethod("dummy", null, Type.EmptyTypes); var g =…
user35443
  • 6,309
  • 12
  • 52
  • 75
1
2
3
74 75