473,672 Members | 3,969 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

AppDomain / Assembly Bug or what's wrong?

The following is a basic example of how this system works:

C:\MyApp\Applic ation1.exe
C:\MyApp\MyMoni tor.exe

In SQL Server, we keep an EXE (Application1.e xe) file stored as
binary.

I read this out of SQL Server into a byte[] array (through
MyMonitor.exe) and then pass to a function for Version.

Here's the kicker.. As soon as the function loads the binary image
retreieved from SQL Server, it *locks* the local "Application1.e xe"
running out of the same directory.

I'm puzzled by 2 things:

1) why does the local Application1.ex e get locked when I'm loading a
secondary app domain with a byte array from SQL?

2) Let's say technically it's a bug, and it's using the
"Application1.e xe" from the local folder--then why is it not released
when I unload the secondary application domain?

When I terminate "MyMonitor. exe" I can then copy a newer build over
the existing "Application1.e xe" file. If I comment out the section
that deals with loading the Byte[] array, I can copy a newer build
over the existing file. However, my design is flawed in some way or
this is a bug.

Any help appreciated.
Here's the GetAssemblyVers ion Function:

pprivate string GetAssemblyVers ion(byte[] inBytes)
{
string strVersion = "";

try
{
AppDomain secDomain = AppDomain.Creat eDomain("Second aryDomain",
null, null);

int iStart = 0;
int iStop = 0;

secDomain.Load( inBytes);

Assembly[] oList = secDomain.GetAs semblies();
iStart = oList[0].FullName.Index Of("Version") + 8;
iStop = oList[0].FullName.Index Of(",", iStart);

strVersion = oList[0].FullName.Subst ring(iStart, (iStop - iStart));

AppDomain.Unloa d(secDomain);

}
catch (Exception e1)
{
MessageBox.Show ("Error encountered Reading Assembly Info: " +
e1.ToString());
}

return strVersion;
}
Nov 16 '05 #1
1 2486
You have to load the assembly from within the context of the 2nd appdomain -
in your snippet you are loading it while executing in the default appdomain.
You need to create a class derived from MarshalByRefObj and call a method in
it that will actually load the assembly. Do not pass a reference back to the
default appdomain because that will force it to load the assembly in that
appdomain.

This link explains this and has sample code on how to do it.

http://www.gotdotnet.com/team/clr/AppdomainFAQ.aspx

Another option is write code that will examine the bytes that make up the PE
file header info and parse it yourself.

"Cider123" <ci******@hotma il.com> wrote in message
news:55******** *************** ***@posting.goo gle.com...
The following is a basic example of how this system works:

C:\MyApp\Applic ation1.exe
C:\MyApp\MyMoni tor.exe

In SQL Server, we keep an EXE (Application1.e xe) file stored as
binary.

I read this out of SQL Server into a byte[] array (through
MyMonitor.exe) and then pass to a function for Version.

Here's the kicker.. As soon as the function loads the binary image
retreieved from SQL Server, it *locks* the local "Application1.e xe"
running out of the same directory.

I'm puzzled by 2 things:

1) why does the local Application1.ex e get locked when I'm loading a
secondary app domain with a byte array from SQL?

2) Let's say technically it's a bug, and it's using the
"Application1.e xe" from the local folder--then why is it not released
when I unload the secondary application domain?

When I terminate "MyMonitor. exe" I can then copy a newer build over
the existing "Application1.e xe" file. If I comment out the section
that deals with loading the Byte[] array, I can copy a newer build
over the existing file. However, my design is flawed in some way or
this is a bug.

Any help appreciated.
Here's the GetAssemblyVers ion Function:

pprivate string GetAssemblyVers ion(byte[] inBytes)
{
string strVersion = "";

try
{
AppDomain secDomain = AppDomain.Creat eDomain("Second aryDomain",
null, null);

int iStart = 0;
int iStop = 0;

secDomain.Load( inBytes);

Assembly[] oList = secDomain.GetAs semblies();
iStart = oList[0].FullName.Index Of("Version") + 8;
iStop = oList[0].FullName.Index Of(",", iStart);

strVersion = oList[0].FullName.Subst ring(iStart, (iStop - iStart));

AppDomain.Unloa d(secDomain);

}
catch (Exception e1)
{
MessageBox.Show ("Error encountered Reading Assembly Info: " +
e1.ToString());
}

return strVersion;
}

Nov 16 '05 #2

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

Similar topics

0
372
by: Vineeth Karinta | last post by:
i am trying to load a Windows Form Assembly at run time to a seprate AppDomain. I don't want that this Assembly to be loaded in the Caller Domain, so i used the metho CreateInstanceFromAndUnwrap instead of AppDomain.Load(.. // I am passing the Control's parent through the constructor argumen Object args1 = new Object {this} AppDomainSetup info = new AppDomainSetup() info.ApplicationBase = "file:///" + System.Environment.CurrentDirectory...
5
15361
by: Chris | last post by:
Hi I have a scenario where I've created another AppDomain to dynamically load a DLL(s) into. In this newly loaded DLL I want to call a static method on a class. The problem arise is that I have the same class/static method definition statictly linked to my EXE and when I call InvokeMember(...), even though I got the Type from the new AppDomain, it calls the static method that I am staticly linked to and not the static method in the dynamicly...
4
6097
by: Mirano | last post by:
Hi everybody. I load an assembly into another AppDomain, not a default one. As there is no way to unload the assembly, I need to unload the domain. This is where the app hangs. The problem is this assembly has references to one dll, currently not performing any work. I tried this: 1. Setting the assembly to null, 2. Implementing a ClassFactory and returning an interface of the object,
2
10845
by: Lauren Hines | last post by:
Hello, I have read numerous post stating that the only way to unload an assembly (DLL in my case) is to create a separate AppDomain, load the assembly, then unload it by calling AppDomain.Unload. When trying to delete the DLL file I get an exception that access is denied. When trying to copy over the DLL file, I get an exception that it is being used by another process.
8
5085
by: A. Elamiri | last post by:
Hello, I created a small app which acts as a services manager. I basically drop a DLL in a Services folder and set the frequency through the application for how often do I want the code in the assembly to run (scheduler). I created a seperate AppDomain here is the code: .... AppDomainSetup ads = new AppDomainSetup(); string path =
6
8192
by: Wal Turner | last post by:
Hi there. There are various snippets on forums regarding issues with AppDomain.Unload and how it just doesnt work. Fortunately, I got it working with the base case, after much fiddling. Consider this 5 line program: AppDomain domain = AppDomain.CreateDomain("MyDomain"); domain.CreateInstance("TempDLL", "TempDLL.Class1"); MessageBox.Show("try deleting file now"); //cant delete file AppDomain.Unload(domain);
0
965
by: marfi95 | last post by:
Hi all, I'm writing some code to automatically update my application when changes have been made. I had it all working by using the LoadFrom method of an assembly and checking the version information, etc... until I realized that was actually locking the files on the common drive where the updated app is located. I know the solution to this is to load the assembly into another appdomain, then check and unload it, but I can't seem to...
3
22135
by: Frank Uray | last post by:
Hi all I have a problem with loading a assembly ... I am trying to do the following: - I have a directory with a dll (assembly) in it (not the currect dir.) - I am trying to load this assembly, run a method in it, and than close it. The question would be: How is the right way to do it ????
4
5337
by: illegal.prime | last post by:
Hi all, I'm getting unexpected results when trying to preload assemblies into an AppDomain I'm creating. Upon creation of the AppDomain - I attach an AssemblyResolve to both my current AppDomain and the new AppDomain I create. I copy all the assemblies/dlls into a new directory and then try loading them all into the new AppDomain using the following: private void LoadAssembliesFromDirectory(AppDomain appDomain, string directory)
0
8503
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8945
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8696
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7472
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5720
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4239
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4439
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2092
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1836
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.