473,394 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Activator problems

Hi,

I have an internal class, which an internal constructor. In the same
assembly as this class, I have a factory class which uses
Activator.CreateInstance to create the instance. The code is as
follows:

ISubscriptionChangeWatcher result;
string[] watcherConfig;
ObjectHandle handle;

if
( ConfigurationManager.AppSettings[ "SubscriptionWatcher" ] == null )
{
throw new InvalidOperationException(
Properties.Resources.WatcherNotConfigured
);
}

// This is like this string:
MedAssociates.Test.SubscriptionManager.TestProcess or,MedSubscriptionManager.Business.Test
watcherConfig = ConfigurationManager.AppSettings[
"SubscriptionWatcher" ].Split( ',' );

if ( watcherConfig.Length != 2 ) {
throw new InvalidOperationException(
Properties.Resources.WatcherNotConfigured
);
}

handle = Activator.CreateInstance(
watcherConfig[ 1 ],
watcherConfig[ 0 ]
);

result = (ISubscriptionChangeWatcher)handle.Unwrap();

return result;

For some reason, everything works fine via NUnit tests, which are in a
seperate assembly. InternalsVisiableTo allows the testing assembly to
see internals of the assembly with the above code.

In my application, I get a MissingMethodException. I was under the
impression that Activator could call constructor code on any member
even if its not directly visible to it. Is this not the case? how is
this usually acomplished.. I know this method of specifing a type to
load via a config file is common.

Thanks
Andy

Jul 31 '07 #1
0 1051

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: philipl | last post by:
hi, i am having a problem catching a user defined exception, defined in a class A library on its own, thrown from another class B. I am trying to catch it in a console app which invokes class B...
2
by: 2G | last post by:
Hi, I'm having some problems creating an instance of the dataset I compile in memory and I don't know why. I what to do this to Invoke WriteXmlSchema or GetSchemaSerializable so I could save...
7
by: hazz | last post by:
this is a repost with more concise code (well, for me) and better questions (I hope....) . given the following two classes, my intent is to use either Activator.CreateInstance or InvokeMember pass...
3
by: System.Reflection Activator | last post by:
************************************** //Load the Assembly Assembly a = Assembly.LoadFrom(sAssembly); //Get Types so we can Identify the Interface. Type mytypes = a.GetTypes(); BindingFlags...
7
by: Ian Frawley | last post by:
Hi I have used the Activator class a number of times in my Windows apps and Windows Services and was thinking of using it again in one of my web services that I have been developing. I have been...
2
by: Huw | last post by:
I have written a small procedure that opens a dialog that I pass it. Sub MyOpen(txtForm as string) Dim frm As Object Dim frmType As Type frmType = Type.GetType(txtForm) frm =...
1
by: Johnny R | last post by:
Hello, I'm loading a Class from Assemly DLL using Activator.CreateInstance. That loaded Class is executed in a worker Thread with no loop. What actually happends when class is loaded using...
0
by: Jon Skeet [C# MVP] | last post by:
On Apr 11, 8:40 am, Andrew <And...@discussions.microsoft.comwrote: Okay, that means you've either not given the full classname (including namespace) or it's not in mscorlib or the currently...
0
by: =?Utf-8?B?QW5kcmV3?= | last post by:
Found it. string name = Properties.Settings.Default.ClassName.ToString(); //"myproject.myclass, myassembly" format. //name = "ABC.MyClass, Assem" ; Type t = Type.GetType(name); Object obj...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.