Reflection error

G

Guest

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
 
K

Kevin Yu [MSFT]

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."
 
T

Tim Marsden

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
 
K

Kevin Yu [MSFT]

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."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top