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

AppDomain / Assembly Bug or what's wrong?

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

C:\MyApp\Application1.exe
C:\MyApp\MyMonitor.exe

In SQL Server, we keep an EXE (Application1.exe) 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.exe"
running out of the same directory.

I'm puzzled by 2 things:

1) why does the local Application1.exe 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.exe" 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.exe" 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 GetAssemblyVersion Function:

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

try
{
AppDomain secDomain = AppDomain.CreateDomain("SecondaryDomain",
null, null);

int iStart = 0;
int iStop = 0;

secDomain.Load(inBytes);

Assembly[] oList = secDomain.GetAssemblies();
iStart = oList[0].FullName.IndexOf("Version") + 8;
iStop = oList[0].FullName.IndexOf(",", iStart);

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

AppDomain.Unload(secDomain);

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

return strVersion;
}
Nov 16 '05 #1
1 2474
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******@hotmail.com> wrote in message
news:55**************************@posting.google.c om...
The following is a basic example of how this system works:

C:\MyApp\Application1.exe
C:\MyApp\MyMonitor.exe

In SQL Server, we keep an EXE (Application1.exe) 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.exe"
running out of the same directory.

I'm puzzled by 2 things:

1) why does the local Application1.exe 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.exe" 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.exe" 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 GetAssemblyVersion Function:

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

try
{
AppDomain secDomain = AppDomain.CreateDomain("SecondaryDomain",
null, null);

int iStart = 0;
int iStop = 0;

secDomain.Load(inBytes);

Assembly[] oList = secDomain.GetAssemblies();
iStart = oList[0].FullName.IndexOf("Version") + 8;
iStop = oList[0].FullName.IndexOf(",", iStart);

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

AppDomain.Unload(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
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...
5
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...
4
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...
2
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....
8
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...
6
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...
0
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...
3
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,...
4
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...
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: 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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
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,...

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.