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

Loading assembly dynamically and using it

KK
Hi all
Can anybody help me what's going wrong here and how to correct it.
Code is as follows....

System::Object * GetObjectFromAssembly()
{
Assembly * pMyAssembly = Assembly::Load("MyAssembly");
Type * pMyType = pMyAssembly->GetType("MyNameSpace.MyClass");
System::Object * pRet = pMyType->CreateInstance();
pMyAssembly = 0;
return pRet;
}

Here i'm getting the error as "pRet is disposed." How to create object from
Assembly at runtime and use it?

Thanks and Regards
Krishna
Nov 22 '05 #1
2 1529
Krishna,

The following sample is from a VB.NET project I just deployed.
Unfortunately it is not in C++ but perhaps you can glean some ideas.
IReport is an abstract interface I defined that is known by the the caller
and is implemented by the dynamically loaded assembly.
Friend Class ReportProxy
Friend ReportAssembly As String
Friend ReportNamespace As String

Public Function Report() As IReport
Dim hdl As System.Runtime.Remoting.ObjectHandle
hdl = Activator.CreateInstance(ReportAssembly, ReportNamespace)
Return CType(hdl.Unwrap, MyCom.General.Reporting.IReport)
End Function
End Class
"KK" <kr*****@lucidindia.net> wrote in message
news:es**************@TK2MSFTNGP11.phx.gbl...
Hi all
Can anybody help me what's going wrong here and how to correct it.
Code is as follows....

System::Object * GetObjectFromAssembly()
{
Assembly * pMyAssembly = Assembly::Load("MyAssembly");
Type * pMyType = pMyAssembly->GetType("MyNameSpace.MyClass");
System::Object * pRet = pMyType->CreateInstance();
pMyAssembly = 0;
return pRet;
}

Here i'm getting the error as "pRet is disposed." How to create object from Assembly at runtime and use it?

Thanks and Regards
Krishna

Nov 22 '05 #2
-----Original Message-----
Hi all
Can anybody help me what's going wrong here and how to correct it.Code is as follows....

System::Object * GetObjectFromAssembly()
{
Assembly * pMyAssembly = Assembly::Load ("MyAssembly"); Type * pMyType = pMyAssembly->GetType ("MyNameSpace.MyClass"); System::Object * pRet = pMyType->CreateInstance();
pMyAssembly = 0;
return pRet;
}

Here i'm getting the error as "pRet is disposed." How to create object fromAssembly at runtime and use it?

Thanks and Regards
Krishna
.

Hey are there any overloads of the CreateInstance that
take void as a parameter, I didn't see one in the
documentations? Also is CreateInstance returning a new
Object or just a plain pointer? I remember getting a
similiar error like yours awhile back. I skimmed my code
and realized that the returning function only returned a
plain pointer not a new one. I saw your post and thought
maybe you did the same mistake as me. Hope this maybe
helps!!
Nov 22 '05 #3

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

Similar topics

2
by: Foehammer | last post by:
Hello, I'm trying to load an assembly dynamically using an app domain. This is a proof-of-concept for a larger project, so please excuse the lame class names. TestLib is the dll where all the...
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...
9
by: Ender | last post by:
I have an application that I would like third party developers to be able to create Plug-ins that will be dynamically loaded into our application to extend functionality. I have utilized the...
4
by: J.Marsch | last post by:
Building a large app where we want to be able to ship updated icons like patches/assign different "skins", etc. So, I'm looking at storing sets of related icons in assemblies that will be loaded...
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...
3
by: Tim Mavers | last post by:
I have created a DLL (class library) in .NET that I need to dynamically load from my ASP.NET application. I am trying to use Assembly.Load(...) to load the file, which is in the /bin directory...
1
by: John F | last post by:
Hello all, When dynamically loading classes through reflection using Assembly.LoadFrom I have the following questions: 1) Once you load an assembly it doesn't appear you can unload it. If you...
0
by: Ashok Mistry | last post by:
Hi all, I have a problem in loading Assembly dynamically through the Reflection. I want to Load an assembly, say, Main.dll. The Main.dll is dependent on a DLL, say Abc.dll, which is placed in...
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: Smithers | last post by:
Using 3.5, I am stuck in attempting to: 1. Dynamically load an assembly 2. Instantiate a class from that assembly (the client code is in a different namespace than the namespace of the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.