Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Activator.CreateInstance

46 views
Skip to first unread message

Thomas Zueger

unread,
Oct 31, 2002, 6:18:39 AM10/31/02
to
Hi

We have a problem with the dynamicly creation of winfomrs. After calling the
Activator.CreateInstance method, the follwing exception will be thrown:
Exception: System.Runtime.InteropServices.SEHException
Message: External component has thrown an exception.
Source: mscorlib
at System.Reflection.Assembly.GetResource(String resourceName, UInt64&
length, StackCrawlMark& stackMark, Boolean skipSecurityCheck)
at System.Reflection.Assembly.GetManifestResourceStream(String name,
StackCrawlMark& stackMark, Boolean skipSecurityCheck)
at System.Reflection.Assembly.GetManifestResourceStream(Type type, String
name, Boolean skipSecurityCheck, StackCrawlMark& stackMark)
at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo
culture, Boolean createIfNotExists, Boolean tryParents)
at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo
culture, Boolean createIfNotExists, Boolean tryParents)
at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo
culture, Boolean createIfNotExists, Boolean tryParents)
at System.Resources.ResourceManager.GetObject(String name, CultureInfo
culture)
at System.Resources.ResourceManager.GetObject(String name)
at ACAG.AppConfiguratorWinForms.DataFormResKategorie.InitializeComponent()
at ACAG.AppConfiguratorWinForms.DataFormResKategorie..ctor()

another exception:
Exception: System.Reflection.TargetInvocationException
Message: Exception has been thrown by the target of an invocation.
Source: mscorlib
at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
at ACAG.DnxCommon.DynamicInstances.CreateDataFormOfEntryAssembly(String
formTypeName)
at ACAG.DnxWinControls.SelectionManager.CreateDataForm()
at ACAG.DnxWinControls.SelectionManager.OnEdit(DataRow selectedRow)
at ACAG.DnxWinControls.SelectionFormDataGrid.grdSelection_DoubleClick(Object
sender, EventArgs e)
at System.Windows.Forms.Control.OnDoubleClick(EventArgs e)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button,
Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr
wparam, IntPtr lparam)

Nested Exception

Exception: System.BadImageFormatException
Message: An attempt was made to load a program with an incorrect format.
Source: AppConfiguratorWinForms
at ACAG.AppConfiguratorWinForms.DataFormResKontext..ctor()


This is the method to create the instance:
public static IDnxDataStatusManageable CreateDataFormOfEntryAssembly(string
formTypeName)
{

Type t =
System.Reflection.Assembly.GetEntryAssembly().GetType(formTypeName);
return (IDnxDataStatusManageable)Activator.CreateInstance(t);
}

The point is, that the exception is not thrown in general. Does anybody have
the similar problem with Winforms or is the anything to know when creating
dynamic instances of forms?

Regards
Thomas


Bharat Patel [MS]

unread,
Nov 1, 2002, 5:14:11 PM11/1/02
to
Hi Thomas,

I am not sure if I understand this issue. I will get someone in the CLR team
look at this post.
Can you make a small test repro? Do you also get an error when you do not cast
it to IDnxDataStatusManageable object?
Where is interop involved here?

Please let me know.

Thanks!
Bharat Patel
Microsoft, Visual Basic .NET

This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only. Thanks.

Bharat Patel [MS]

unread,
Nov 4, 2002, 6:14:39 PM11/4/02
to
Hi Thomas,

Thanks for the update. As I go through your message again, it seems to me that
you have created some custom functions in the Framework. Is this true? Are you
using SP1 build of Framework or RTM?

I cannot locate System.Reflection.Assembly.GetResource method and also other
method (like GetManifestResouceStream) signatures are completely different.

Thomas Zueger

unread,
Nov 5, 2002, 7:47:44 AM11/5/02
to
Bharat,

We are using the latest update(NDP10_SP_Q321884_En.exe).

I had checked the mscorlib with the tool
Reflector(http://www.aisto.com/roeder/dotnet/) and found the method
System.Reflection.Assembly.GetResource. The method is declared as private
byte* GetResource(string resourceName, ref ulong length, ref StackCrawlMark
stackMark, bool skipSecurityCheck);

This is an external call. Which library will be called by the method?

Thomas

"Bharat Patel [MS]" <bha...@online.microsoft.com> wrote in message
news:obKJZfFhCHA.548@cpmsftngxa09...

Bharat Patel [MS]

unread,
Nov 5, 2002, 10:34:16 AM11/5/02
to
Hi,

That clears it up. Since the method is private, it is being called by the
internal instance. Now can you try returning the generic Form object on the
Activator.CreateInstance(t); call? Then let me know what happens. Also let me
know what kind of string value you have in formTypeName variable?

Thomas Zueger

unread,
Nov 5, 2002, 1:10:41 PM11/5/02
to
Bharat,

We have to be aware that we don't mixup the two exceptions.
1. Is it possible to get the information which library will be called from
the GetResource method? What might be the reason for this exception?

2. I'll try to test the bevavior with different return values, but I'll need
a portion of time to do this. The question on this point is what a
BadImageFormatException exactly means.

Thanks,
Thomas

"Bharat Patel [MS]" <bha...@online.microsoft.com> wrote in message

news:EyUafCOhCHA.2232@cpmsftngxa08...

Thomas Zueger

unread,
Nov 5, 2002, 1:16:52 PM11/5/02
to
Bharat,

I saw that the CreateInstanceImpl method is also an external call.

Regards
Thomas

"Bharat Patel [MS]" <bha...@online.microsoft.com> wrote in message

news:EyUafCOhCHA.2232@cpmsftngxa08...

Thomas Zueger

unread,
Nov 19, 2002, 11:55:05 AM11/19/02
to
The problem was an instable network connection. We are sharing the
assemblies on a network drive and the connection was not stable.

Regards
Thomas

"Thomas Zueger" <zue...@all-consulting.ch> wrote in message
news:OzK$T8MgCHA.2116@tkmsftngp08...

Bharat Patel [MS]

unread,
Nov 20, 2002, 12:00:33 PM11/20/02
to
Thomas,

Thank you very much for providing the information regarding the resolution. I
appreciate taking time to write back.

Thanks again!

0 new messages