473,773 Members | 2,306 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 2491
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
15371
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
6120
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
10850
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
5089
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
8200
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
975
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
22148
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
5339
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
9621
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
9454
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10039
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8937
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...
1
7463
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6717
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
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3610
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2852
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.