473,405 Members | 2,272 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,405 software developers and data experts.

Dynamically Load Assembly (Windows Service)

I'm attempting to dynamically load an assembly from a windows service.
However, i'm having problems when the service runs... he is the line of
code that causes the error:

dim loAssembly as Assembly = Assembly.LoadFrom("SomeDLL.dll")

I have a test windows Form that i use when developing services... this
way i can run the service in debug mode. If i run as a windows form,
the code executes fine and the assembly loads. However, when i compile
and run as a windows service, the above line of code does not execute.

I'm guessing that while a windows service, the app is running in a
different context -- but i'm not sure. Any help would be appreciated.

Thanks!

Nov 21 '05 #1
3 3503

dercon wrote:
and run as a windows service, the above line of code does not

execute.

What does this mean? Are you getting an exception? Can you post any
exceptions generated?

A little more information is needed.

Does your service run under an account that has sufficient priveleges
to load the assembly?

Nov 21 '05 #2
I fixed the initial issue... turns out that since the application is
running as a service, its base directory is the /windows/system32
directory so it was not finding the dll. I simply passed in the full
path to the dll and i was able to load the assembly.

However, a new issue has surfaced... i can load the assembly but i
can't create a class from the dll...

dim moDLL as SomeNamespace.SomeClass
loAssembly = Assembly.LoadFrom("C:\sswork\MyDLL.dll)
'The following line fails to create.
moDLL = loAssembly.CreateInstance("SomeNamespace.SomeClass ")

I'm getting the following error when i attempt to create my class
instance:
System.InvalidCastException: Specified cast is not valid.

However, if i start the service and attach it to the development
environment, if i manually create instance (using the command window)
the code works fine.

Any ideas?

Nov 21 '05 #3
Off the top of my head, it appears you are not casting the result of
the CreateInstance call to your class type. CreateInstance returns
Object so you would have to cast the object to your class:

moDLL = DirectCast(loAssembly.CreateInstance("SomeClass"), SomeClass)

Nov 21 '05 #4

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

Similar topics

1
by: Benjamin | last post by:
Hi, I'm currently writing a Web Services that interacts with a database. To allow me to use not just one database provider (for example, I could use MS Access, SQL Server or MySQL), the Web...
7
by: Ollie Riches | last post by:
I am trying to dynamically load an assembly that has a reference to 'Interop.WMEncoderLib.dll' which is a PIA to the windows media player DRM components. When I run the code from a console...
1
by: M. Fitzgerald | last post by:
Our migration from ASP to ASP.NET will be a slow one. In themeantime, I have constructed a .NET assembly and registered itas a COM object for use in out classic ASP pages. One of thethings this...
2
by: brian.gabriel | last post by:
I have a core web service that acts as a gateway for several third party web services. Each one of the third party web services has it's own "interface" class derived from a main interface. When...
7
by: RSS | last post by:
Hi everyone, I have an app that uses some DLL's that are shared across couple applications. There are reasons existing that prevent me from putting them in to the GAC. Each of these app's at some...
6
by: Dan Dorey | last post by:
I actually have two questions here, but I'll start by giving an outline of what I'm trying to do. I'm building an app with a simple plugin architecture (all in the same app domain). I have each...
2
by: Jeff | last post by:
Hey asp.net 2.0 My asp.net 2.0 project has got a assembly load problem: Some of my web.config settings: <membership defaultProvider="AH_MembershipProvider" userIsOnlineTimeWindow="15">
2
by: Smithers | last post by:
I have a Windows Forms application that implements a plug-in architecture whereby required assemblies are identified and loaded dynamically. Here are the relevant classes: A = application =...
2
by: David Thielen | last post by:
So we have moved our app from .NET version 2.X in IIS6 to a Windows 2008 Server running IIS7. We have copied all files to the Windwardreports\apps directory and that apps directory has been...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.