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.

Filter by
Sorted by
Tagged with
-1 votes
1 answer
47 views

How to set value to protected property derived from abstract class? C#

I have a class which was derived from base class. To make some manipulations with it in unit tests I would like to change some protected properties with reflection. But when I'm trying to do this I ...
Snail's user avatar
  • 57
1 vote
1 answer
31 views

How can I add value to a reflected variable?

I want to add value to a value I got through reflection. The += does not work and SetValue does not fit my needs. * Instance.Field does exist but this would not be good for my script(For reasons). ...
ReoCyan's user avatar
  • 13
-1 votes
1 answer
56 views

How do I fix this bug in Unity C# with getting a variable through reflection? [closed]

I have this code to find my variable: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.EventSystems; using System.Reflection; ...
ReoCyan's user avatar
  • 13
3 votes
1 answer
97 views

Why does integer '0' IEquatable.Equals return true against a null object when called through reflection but false when called on the integer?

Calling IEquatable.Equals from an integer 0 to test against a null object should return false but when using reflection it returns true. Given the following code, I would expect for iEquals and equals ...
Evelyn's user avatar
  • 81
-1 votes
0 answers
36 views

sentence similarity using ml.net (in dot net framework)

i have lost and found items with their descriptions respectively. when a lost item is reported its description is to be compared with all the existing found item's descriptions and it should display ...
Shatvika Shadvini's user avatar
0 votes
1 answer
77 views

Get original unique C# Enum objects when they share an integral value

If I have a C# enum where two objects map to the same integral value, is there any possible way to get each unique Enum object? Every method I have tried returns only one of the objects - which is ...
jhdepoiii's user avatar
0 votes
1 answer
63 views

Xamarin.Forms: Get PropertyInfo from Binding information

In XAML I define some elements, e.g. ToolbarItems: <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" ...
Bernd Morgeneyer's user avatar
1 vote
1 answer
45 views

Entity Framework Core how to instantiate DBContext using reflection?

I have a NET 7 console app using EF core, I have a situation where I need to instantiate my custom DB Context classes using reflection passing in a DBContextOptions parameter. I am getting the ...
AndyW's user avatar
  • 345
1 vote
2 answers
89 views

How to update the property value (Database field) of T Entity (Database Table) from the DbContext? (save decrypted data back to the DbContext)

How to iterate through DbContext and decrypt certain fields I am using this StackOverflow answer as a guide: Database Table Export to CSV using EntityFramework DbContext .NET 6 We have very a legacy ...
Tyson Gibby's user avatar
  • 3,052
1 vote
0 answers
44 views

How to prevent RuntimeMethodInfo objects from leaking memory?

I’m comparing two snapshots taken using dotMemory profiler, and I find that there are a number of RuntimeMethodInfo objects that survived through two snapshots. These objects represent methods of a ...
Alison's user avatar
  • 71
0 votes
0 answers
23 views

C# Reflection get nullable reference type [duplicate]

public class A { public A? MyA { get; set; } } We knew that a reference to A is always nullable, so using A? is actually redundant until ..... the introduction of nullsafety. My question is, how ...
s k's user avatar
  • 4,572
0 votes
0 answers
34 views

C# Compilation to be done from a EDITOR with JSON Support (Serialize and Deserialize)

I am here after spending weeks trying to resolve the below issue. I have c# code which is written in the front end editor. We use Monaco Editor on the front end to write the code. That code is ...
Shankar Kumar's user avatar
0 votes
0 answers
8 views

What is a plus sign in reflection get type?

Trying to get this old code working as I don't remember even why we used it instead of just using the built-ins. What is the plus sign in get type supposed to do? I don't see any sign of special types ...
Maslow's user avatar
  • 18.5k
-1 votes
1 answer
54 views

C# Static Constructors for Inherited Classes

I have a project with around 100k XML configuration files for managing test equipment. In order to make the files easier to update, I want to be able to port them around to Excel, Access, etc. I've ...
Manfred ad. Rickenbocker's user avatar
0 votes
0 answers
15 views

Text existence of covariant property without generating AmbiguousMatchException

My base view model uses Type.GetProperty to verify that a given property (for which we are about to raise PropertyChanged) actually exists in the class. It works great. But if you test for the ...
Joe's user avatar
  • 5,622
0 votes
0 answers
16 views

MethodBase.Invoke to Web Api from C#

I am using Reflection to invoke methods from a Web API, but when extracting the constructor, it returns a URL instead of the constructor information, which causes an error when using MethodBase.Invoke ...
Juan Carlos Macho's user avatar
0 votes
1 answer
63 views

Cannot convert type 'System.Reflection.PropertyInfo' to 'bool'

I am initializing a class at runtime using Activator.CreateInstance. How do I loop through all the properties of the class that is initialized? I get a compile-time error 'Cannot convert type 'System....
Max's user avatar
  • 480
0 votes
1 answer
201 views

Creation of secondary AppDomains not supported

The .NET 7 docs provide an example on how to use the MarshalByRefObject class to create class instances in secondary domains. I replicated this example almost identically as follows: using System; ...
user32882's user avatar
  • 5,276
0 votes
1 answer
33 views

How to get interface implementation type for currently executing method?

I have an interface with several implementations. The implementations and interface method call are in different packages if that matters. I'm trying to catch the exception that may occur during the ...
Pukanium's user avatar
0 votes
0 answers
34 views

Assembly loading by reflection c# causes type comparison problem

I have the following scenario in which some dll could be referenced as normal reference and also can be loaded by reflection. I have a library with an xml configuration file which specifies what ...
JuanDYB's user avatar
  • 590
0 votes
0 answers
64 views

Setting private property via reflection - property not being found

TLDR: Can't set a private field on an instance of this class using reflection, despite having the correct binding flags. I'm working on a C# unit test to verify batch update functionality on a ...
Sam vds's user avatar
0 votes
0 answers
37 views

How to get the underlying type of a ByRef type from Reflection.ParmeterInfo

I want to find the types of all the parameters of a given method using reflection, but I'm having trouble with parameters that are passed by reference (ref keyword). For example, say the original ...
NⵙⵙB's user avatar
0 votes
1 answer
213 views

Performance impact of reflection when creating the Json object

I have below code to prepare the logEventInfo object to log the data. I am using the Nlog. I found it is convenient to use reflection to add the name and value dynamically. But I know there is a big ...
wadefanyaoxia's user avatar
0 votes
0 answers
47 views

How to GetProperties of an object that is List<T>

I need to get all properties of a class that have an element that is a list of other class and you don't know how is that class. I need to get the properties including those belonging to the second ...
CBal's user avatar
  • 21
-1 votes
1 answer
32 views

Access properties in generic class

Suppose I have a class like this: public class DepartmentBase<T> : MyBase where T : new() { public ObservableCollection<T> Employees { get { return ...
Lucy82's user avatar
  • 662
1 vote
0 answers
97 views

Where does PowerShell retrieve Intellisense/AutoComplete information from (specifically for .NET class methods)?

In the console, if I type [string]::Concat( and press CTRL + SPACE I can see every method overload. Where exactly does PowerShell retrieve this kind of overload definition/syntax information from? PS ...
Paul π's user avatar
  • 180
0 votes
0 answers
94 views

C# Build anonymous type from array string

I'm looking for a way to build an anonymous type from an object where it's property names match those in a given string array. Something like: //Current Way: var anonObject = primaryObject.Select(...
Phil's user avatar
  • 1,902
1 vote
1 answer
40 views

Trying to call a generic version from a non-generic version using System.Reflection

I'm trying to call the generic version using System.Reflection from the non-generic version. When I run the migrations I'm getting the following error: System.MissingMethodException: Constructor on ...
nop's user avatar
  • 5,043
0 votes
2 answers
107 views

Converting a value with object type, declared as List<T> to List<U> using Dictionary<Type, Type> with the types corresponding to T and U respectively

I am refactoring on a legacy code where back compatiblity is critical. I got stuck in trying to develop a converter for more than 40 different types to be serialized. I need to convert List<T>s ...
Mustafa şentürk's user avatar
0 votes
1 answer
54 views

Invoking a generic interface's method through reflection invokes a method from a base implementation of the same interface in Unity

I have the following generic interface: public interface IGenericInterface<T> { public void PrintGenericParameterTypeName() { Debug.Log($"Generic parameter type: {typeof(T)....
Georgi Tonchev's user avatar
0 votes
0 answers
147 views

How to set default property value of class type in C# System.Reflection.Emit

I am using System.Reflection in C# to create a dynamic object class at runtime. This is the example object class that I want to create at runtime. public class RequestForTest { public string ...
Đặng Đức's user avatar
0 votes
0 answers
232 views

Powershell Script Deobfuscation

I've recently going down a rabbit hole of picking apart a piece of malware that my partner had fallen victim to, looking through the Powershell Script in a testing environment. I am very much new to ...
Shawna Smith's user avatar
2 votes
1 answer
94 views

Setting a property value using reflection throwing an exception

Im using the Microsoft Community MVVM package within my MAUI app. It's working well, but I've hit an issue. Part of my UI modifies a structure which sends a message to the view model. This works fine. ...
Nodoid's user avatar
  • 1,469
0 votes
1 answer
45 views

Passing parameter to event handler using System.Reflection

I have the following two programs (1) windows forms application (2) ClassLibrary1.dll The ClassLibrary1.dll is loaded to the winform through appdomain. In windows forms, I have subscribed to event in ...
Crystal Crystal's user avatar
0 votes
0 answers
17 views

Show all Types of all references in project from an IWizard

I was trying to create a Template that takes in a Type to substitute it's name in a template. The template looks like this using System; using System.Collections.Generic; using System.Text; namespace ...
Francesco Giori's user avatar
1 vote
0 answers
54 views

Cannot convert from method group to System.EventHandler. Changing handler signature shows error when dealing with appdomain

I have the following two programs (1) Windows forms application (2) ClassLibrary1.dll In the winform, the dll is loaded using appdomain. The winform subscribes to the action('TestAction') in the dll. ...
Crystal Crystal's user avatar
1 vote
2 answers
65 views

How to capture arguments returned by dll events (events are subscribed using Reflection)?

I have a winform application(WindowsFormsApplication2) that loads a dll using appdomain. In the winform, I have suscribed to 'TestEvent' implemented in ClassLibrary.dll. If the TestEvent returns an ...
Crystal Crystal's user avatar
3 votes
1 answer
8k views

Activator.CreateInstance - MissingMethodException: Constructor on type 'xxx' not found

I have the following code Driver Code var provider = DataManager.BuildDatabase<FileDatabase>(config,false,dbPath).Result; DataManager.cs public static async Task<IStorageProvider> ...
Freddyy's user avatar
  • 59
0 votes
0 answers
437 views

ModuleNotFoundError: No module named 'System'

I'm working on an EXE file crypter in python 3.11.1 and I cannot seem to get the System.Reflection import working. I've tried pythonnet and clr, but it just doesn't recognize 'System.' I've tried to ...
FakeCoreyTaylor's user avatar
2 votes
2 answers
144 views

Find suitable Constructor with reflection?

I am having some reflection issues, when finding the right constructor depending on the passed parameters. So far this piece of code works fine, when the constructor arguments that are passed are not ...
DominikAmon's user avatar
0 votes
0 answers
44 views

Problem with a model and DataAttribute [Required] used even if not present on property

I have this model : using System.ComponentModel.DataAnnotations; namespace Core.Domain.Models.Contracts.V1._0 { public class Body { [StringLength(10)] public string field1 { ...
user2776069's user avatar
0 votes
1 answer
362 views

Using Reflection to Iterate and update value of an object for specific property types

I have an object, employeesOfTheMonth of type EmployeesOfTheMonth, which contains a number of properties of types Employee as well as List<Employee>. In some instances, the value of a given ...
PaulPerkins's user avatar
2 votes
1 answer
250 views

NullReferenceException thrown but the object passed the null check, how is that possible?

I'm using the AddEventHandler method from that answer, but when doing it on an EventHandler with a value type argument that happens: using System.Reflection; public class Program { public static ...
KBar's user avatar
  • 92
1 vote
0 answers
259 views

MethodBase.GetMethodInfo() returns MoveNext [duplicate]

In Visual Studio 2022, I've written the following C# (.NET 6) code (in case it matters, it's in a non-generic class derived from a generic base class): private async Task<bool> MyMethod() { ...
Green Grasso Holm's user avatar
0 votes
0 answers
70 views

Exception unhandled when event is raised in dll (accessed using app domain)

My project contains windows form application(WindowsFormsApplication1) dll (ClassLibrary1). I am trying to implement some logic in my windows form application when an event is raised in my DLL. I am ...
Crystal Crystal's user avatar
-1 votes
2 answers
263 views

Print the namespace of the currently executing code in C# running in .NET 7 [duplicate]

I'd like to print the namespace of the currently executing code running in .NET 7 using C#. Something akin to: Inside of Main (in Program.cs of a program called myApp): // See https://aka.ms/new-...
decuser's user avatar
  • 238
0 votes
0 answers
516 views

EF Core 6.0 get InternalDbSet<> from type

I do have a problem with EF Core. I need a Instance of a DBSet<> without knowing the Type until runtime and method is called. I need this Instance to add Include Statements dynamically and ...
Luis07's user avatar
  • 1
0 votes
1 answer
114 views

PropertyInfo.GetValue() Throws: Object does not match target type

I want to read all the values of each row internal class ExcelTable<T> : IExcelTable where T : IExcelTableRow { void Foo(){ var props = typeof(T).GetProperties().ToList(); ...
Theodor349's user avatar
1 vote
1 answer
42 views

Nested Object Acess to properties from Origin Object

Considering the following scheme. A class that contains an object, in this case I'm using OriginObject. The main problem is that the property NestedName has to access instructions about its behavior ...
James Jonatah's user avatar
1 vote
2 answers
3k views

Get the name of a element (.Net MAUI / Xamarin.Forms)

Hey i looking for a option to get the Element of a Control by finding the Parent. Does this function exist in Xamarin.Forms / .Net MAUI? (Parents are GRID and Childrens are Frames) It needs to be find ...
Seth Macis's user avatar

1
2 3 4 5
23