activator

Activator.CreateInstance can't find the constructor (MissingMethodException)

I have a class which has the following constructor public DelayCompositeDesigner(DelayComposite CompositeObject) { InitializeComponent(); compositeObject = CompositeObject; } along with a default constructor with no parameters. Next I'm trying to create an instance, but it only works without parameters: var...

Activator and static classes

I'm tossing around the idea of using the Activator class in order to get access to resources in an assembly that I would otherwise create a circular reference for (dependency injection). I've done it before with vanilla classes that I needed a reference to, but my question is: can I use the Activator to get access to a static class? T...

C# CF2.0 - System.Activator and Internal classes

I've got a data provider that contains a collection of entities. I only want to be able to create a new entity through the data provider. I.e, to create a new record I need to use: Entity entity = Provider.AddNew(); enity.set_Properties... etc My issue is that if I set my entities to Internal, System.Activator cannot create an Instan...

Activator.CreateInstance throws ArgumentNullException for parameter 'Type'

I recently encountered a problem with my Profile provider: it wouldn't retrieve profiles correctly (see error below). It worked locally, but when I put the code compiled by a Web Deployment project on a server it would crash. Value cannot be null. Parameter name: type Description: An unhandled exception occurred during th...

C# Create objects with Generics at runtime.

In the following example i can create an object dynamically via a string; however, i have no way to get at the public methods of BASE class. i can't cast obj to a BASE because i don't know what generic will be used at design time. any suggestings on doing so at runtime would be nice. Project A contains Class A{T,J> : BASE{T,J> Proje...

Define a typed dataset dynamically?

I am trying to create an instance of a typed dataset dynamically in my code at runtime. I have the type available to me, but when I try to do this: object obj = Activator.CreateInstance(Type.GetType("TYPED DATASET TYPE HERE")); The problem is the type doesn't seem to be valid according to the code when I try and run it. What could I b...

Activator.CreateInstance(t, 42, args) cannot find constructor

I am using (a slightly extended version of) the following code in a factory-pattern style function: public class SingleItemNew : CheckoutContext { public BookingContext Data { get; set; } public SingleItemNew(BookingContext data) { Data = data; } } public CheckoutContext findContext(BookingContext...

How to dynamically create generic C# object using reflection?

In C# I have the following object: public class Item { } public class Task<T> { } public class TaskA<T> : Task<T> { } public class TaskB<T> : Task<T> { } I want to dynamically create TaskA or TaskB using C# reflection (Activator.CreateInstance). However I wouldn't know the type before hand, so I need to dynamically create TaskA bas...

Using Activator best way to create instances of classes with multiple constructors?

I have implemented a 'plugin' system where my application creates classes that implement an interface at runtime to allow pluggable functionality. I am achieving this by using Activator.CreateInstance on all classes that implement the specified interface within the plugin assembly. At the current time I am only using one implementatio...

C# foreach loop causes CS 0246 Type or namespace could not be found

I have a foreach loop that cycles through a list of types and creates an instance of each one. However, when I build, it gives a CS0246 error ("The type or namespace could not be found ... "). Here's a simplified version of the code: internal static class TypeManager { internal static void LoadTypes() { // Fill the lis...

Activator.CreateInstance() troubles

I have a factory that is supposed to create objects that inherit from class Foo at run-time. I would think that System.Activator.CreateInstance's return type was the same as the type of an object it's creating, but judging from the following error message, its return type is Object. Error 1 Cannot implicitly convert type 'object' to ...

Set property Nullable<> by reflection

I try to set a Nullable<> property dynamicly. I Get my property ex : PropertyInfo property = class.GetProperty("PropertyName"); // My property is Nullable<> at this time So the type could be a string or int I want to set my property by reflection like property.SetValue(class,"1256",null); It's not working when my property is a Nu...

C#: How to find and create instances which fullfills multiple type constraints

Ok, maybe that title didn't make much sense, but here is the deal. Say I have a generic method with multiple type constraints, this this: public static void DoSomethingAwesome<T>(T thing) where T : IThing, IAwesome, IComparable<T> { ... } Now.... how can I, using reflection, create something I can send in there? If it was on...

.NET: Unable to cast object to interface it implements

I have a class (TabControlH60) that both inherits from a base class (UserControl) and implements an interface (IFrameworkClient). I instantiate the object using the .NET Activator class. With the returned instance, I can cast to the UserControl base class, but not to the interface. The exception I get is below the code snipet. How do I c...

Activator.GetObject - Using the state parameter.

In .NET Remoting, Activator.GetObject method has a state parameter. What is the purpose of this state param? Can I retrieve its value from server side? mdsn didn't help much. What I'd like to do: Client side: ChannelServices.RegisterChannel(new TcpChannel(0)); object obj = Activator.GetObject(typeof(MyObj), "tcp://serverName:1234/Remot...

Activator.CreateInstance()

Hey guys. I've been using Activator.CreateInstance() in some of my codes. But I was just wondering if there's any risk to making an instance using this? ...

How do i use Activator.CreateInstance with strings?

In my reflection code i hit a problem with my generic section of code. Specifically when i use a string. var oVal = (object)"Test"; var oType = oVal.GetType(); var sz = Activator.CreateInstance(oType, oVal); Exception An unhandled exception of type 'System.MissingMethodException' occurred in mscorlib.dll Addi...

How to access Microsoft Word existing instance using late binding

Hi, i am developing some code in c# where i will be interacting with Microsoft Word. I want to be able to have the option of re-using an existing instance or as an alternative creating a new instance. Keeping in mind i want to do all of this using LATE BINDING... it is safe to say i have figured out how to get things working when creati...

Use two vesrions of Microsoft.Reporting DLL's at the same time in VB

Problem It looks like MS have removed support for nested Business Objects in their Report Viewer 2010 companant. We would like to upgrade our web app to make use of the new features, but need to maintain backwards compat for loads of legacy reports. Caveats 1: We cant put anything in the GAC as we are on a hosted shared web server. 2:...

Passing method implementations of a class between web applications.

Hello, Is it possible to implement a system similar to this: 1 Centralized assembly storage in a central web application N Client web applications consuming types in assemblies in this centralized web app. It should work this way. I design an interface and deploy it with every client application Client application request for a spe...