473,480 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Reflection error

Hi,

I am running the following vb code.
I am trying to dymanically load my assembly at runtime and run a method in it.

Dim ad As AppDomain
Dim i as myinterface

ad = AppDomain.CreateDomain("xxxx")

i= ad.CreateInstanceFromAndUnwrap("C:\ImportWS.dll",
"ImportWS.ImportWS")
But I get the following error:

An unhandled exception of type 'System.TypeLoadException' occurred in
mscorlib.dll

Additional information: Could not load type ImportWS from assembly ImportWS,
Version=1.0.2148.39870, Culture=neutral, PublicKeyToken=null because the
format is invalid.

I am referencing Excel in my assembly but little else.

Can anybody shed some light on this.

Thanks
Tim

--
Tim Marsden
Nov 23 '05 #1
3 1432
Hi Tim,

Is there any circular dependencies in the type ImportWS in your assembly?
If yes, Please do not use circular dependencies. If that still doesn't
help, could you attach the whole reflection code and the simple assembly
code that can reproduce the problem in your post? Also which version of
VS.NET are you using?

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 23 '05 #2
Hi Kevin
Thanks for you intrest.

Things have moved on a little since I first posted.
I have managed to get my application to load assemblies dynamically
using CreateInstanceAndUnwrap if the assembly is found using probing,
i.e it is in the same folder as my calling application.
However if I move it and use CreateInstanceFromAndUnwrap I get a
SearilizationException saying the assemblie cannot be found.
I know the assemby is OK because I have no trouble loading it in the
same AppDomain, the trouble only occurs if I create a new AppDomain
and try to use CreateInstanceFromAndUnwrap to load it into the new
AppDomain.

Do I need to set up access permissions?

The problem is I am running the code from a Excel addin, so when I
create the new Appdomain it has a basedirectory of "c:\Program
File\Microsoft Office\Office". If I placed my assembly to be loaded in
the "\Office" directory it works, but I do not want to do this, I want
to be able to place it where I want. I have tried creating the new
AppDomain with a specific BaseDirectory but this does not work either.

I have search high and low for the answer but can find any vb.net
examples. I am not to faililiar with security permissions so not sure
if these are an issue.

Regards
Tim

On Sat, 19 Nov 2005 05:00:51 GMT, v-****@online.microsoft.com (Kevin
Yu [MSFT]) wrote:
Hi Tim,

Is there any circular dependencies in the type ImportWS in your assembly?
If yes, Please do not use circular dependencies. If that still doesn't
help, could you attach the whole reflection code and the simple assembly
code that can reproduce the problem in your post? Also which version of
VS.NET are you using?

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 23 '05 #3
Hi Tim,

Are you loading the assembly using a reletive path or an absolute one? This
seems to be a path issue. You can also use AppDomain.AssemblyResolve event
to check what is going wrong. Also if this is code is running in an Excel
addin, I suggest you post in the office develop newsgroup.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 23 '05 #4

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

Similar topics

4
2155
by: Tim Werth | last post by:
I am trying to use reflection to add an event handler for the RowUpdated event of the OracleDataAdapter object (ODP.NET), but the same thing can be said for SqlDataAdapter if you only use...
1
2588
by: Mike Malter | last post by:
I am just starting to work with reflection and I want to create a log that saves relevant information if a method call fails so I can call that method again later using reflection. I am...
1
2363
by: Pieter Breed | last post by:
Hi All, I am trying to use the attribute/reflection system to as much potential as I can think of, but I've run into a snag. I would appreciate it if someone would point me in the right...
16
1414
by: ALI-R | last post by:
I have defined a public enum in my assembly and I am trying to have access to it through reflection: Type theType = Type.GetType("MyAssemblyName.ParameterTypeEnum"); but I get this error: ...
3
4186
by: trevorelbourne | last post by:
Hi, I am having trouble accessing the elements of an array using reflection. This is the code I am having trouble with: FieldInfo Fields = Obj.GetType().GetFields(); foreach (FieldInfo fi in...
2
7747
by: Jeff | last post by:
I am trying to dynamically load an assembly via reflection and then invoke a method of that assembly that will populate a custom type collection passed into the method byref. I am able to...
2
1606
by: Jason | last post by:
Hello, I"m trying to invoke a method using reflection on a DLL that is already within a project. However, I"m having a few problems and didn't know if anyone has any bright ideas. Please note,...
17
2290
by: raylopez99 | last post by:
What good is C# Reflection, other than to find out what types are in an assembly? And to dynamically invoke methods in an assembly (.dll or .exe)? Also, bonus question, can you use Reflection...
5
4271
by: Klaudiusz Bryja | last post by:
Hi, This is for NetCF 2.0. I need to create event handling code which using reflection. I have some parameters in XML which describe how event should be handled. I have code to create...
0
1682
by: Gustavo Arriola | last post by:
Hola a todos! Estoy intentando ejecutar un método usando Reflection. El código es el siguiente: public static void SoapHandler(Exception Error) { try { Type assemblyType;
0
7046
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6908
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7048
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
7088
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...
1
6741
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...
0
4485
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2997
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
183
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.