System.Reflection.ReflectionTypeLoadException in Windows Service

G

Guest

Hello!

I'm experiencing this exception while attempting to examine the public types
on my assembly DLL. Here is the code:

Dim objType As Type
Dim objDLL As Assembly

objDLL = System.Reflection.Assembly.LoadFrom(pathToDLL)

For each objType in objDLL.GetTypes <---- Exception is raised from GetTypes
.... stuff
Next

The same code executes without a problem from a windows forms application,
but not this Windows Service. When I examine the loaderexceptions property,
it contains 1 System.TypeLoadException that simply states "Could not load
type {myType} from Assembly {myAssembly}" etc. The Types array contains 1
RunTime type that contains a reference to a windows form that is a public
member of my Assembly - which is why I bring the question to you. Is there a
problem in general with loading windows forms types from an assembly while
running within a Windows Service, or is there just some sort of dependency
that isn't loading?

Thanks for any assistance!

Zach
 
D

Dmytro Lapshyn [MVP]

Hello Zach,
it contains 1 System.TypeLoadException that simply states "Could not load
type {myType} from Assembly {myAssembly}" etc. The Types array contains 1
RunTime type that contains a reference to a windows form that is a public
member of my Assembly - which is why I bring the question to you.

Actually, this might be a problem, if one of those Windows Form types
contain a static constructor, and this constructor, in turn, attempts some
interaction with the desktop. You might want to examine the InnerException
property of the TypeLoadException you get - it might indicate the real
underlying problem.
 

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