[C# VS2010] Loading dlls into new appdomain exclusively

Trips

Well-known member
Joined
Aug 7, 2010
Messages
2,788
<div style="color:#000000; font-family:Verdana,Arial,Helvetica,sans-serif; font-size:100%; background-color:#ffffff; margin:8px
<div style="color:Black; background-color:White
<pre style="font-size:11px; border:1px solid #d0d0d0 <span style="font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; font-size:13px; white-space:normal; color:#333333; line-height:16px 1.
Im doing all of this so that the .dlls wont get locked and I can recompile even after I loaded assemblies. Now, I read somewhere that you can simply load an assembly as a byte[], and that can take care of that too. However, with that solution I get the same "being used by another process" error with the .pdb debug files. I just load the assembly, as far as I know I dont touch the debug files. Why are they still locked?
Example: This log at the end doesnt make sense to me: I have set the applicationbase and privatebinpath, why is it set to defaults again? And even stranger: Why does it attempt to load from the CORRECT url, and FAIL?
My best guess is, that the Load itself actually worked, but for some reason the main application appdomain also tries to load the assembly?? The whole reason Im using a marshalbyrefobject is that, that doesnt happen. I create this RemoteLoader by calling mainapplicationdomain.CreateInstanceAndUnwrap(Assembly.GetExecutingAssembly(), "MyNamespace.RemoteLoader").

<span style="white-space:pre public class RemoteLoader : MarshalByRefObject
<span style="white-space:pre {
<span style="white-space:pre public Assembly Load(string assemblyName)
<span style="white-space:pre {
<span style="white-space:pre return Assembly.Load(File.ReadAllBytes(assemblyName));
<span style="white-space:pre }
}

<span style="font-family:monospace; font-size:11px; white-space:pre <span style="color:#000000; font-family:Times New Roman; line-height:normal; white-space:normal; font-size:medium
<pre><pre>*** Assembly Binder Log Entry (25.06.2010 @ 17:32:02) ***

The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.

Assembly manager loaded from: C:WindowsMicrosoft.NETFrameworkv4.0.30319clr.dll
Running under executable C:Program Files (x86)Microsoft Visual Studio 10.0Common7IDEdevenv.exe
--- A detailed error log follows.

=== Pre-bind state information ===
LOG: User = MyPC-PCMyUser
LOG: Where-ref bind. Location = C:UsersMyUserDocumentsVisual Studio 2010ProjectsConsoleApplication1ConsoleApplication1binDebugConsoleApplication1.dll
LOG: Appbase = file:///C:/Program Files (x86)/Microsoft Visual Studio 10.0/Common7/IDE/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = NULL
Calling assembly : (Unknown).
===
LOG: This bind starts in LoadFrom load context.
WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load().
LOG: Using application configuration file: C:Program Files (x86)Microsoft Visual Studio 10.0Common7IDEdevenv.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:WindowsMicrosoft.NETFrameworkv4.0.30319configmachine.config.
LOG: Attempting download of new URL file:///C:/Users/MyUser/Documents/Visual Studio 2010/Projects/ConsoleApplication1/ConsoleApplication1/bin/Debug/ConsoleApplication1.dll.
LOG: All probing URLs attempted and failed.[/code]
[/code]
A small convenience question: [/code]
<pre style="font-size:11px; border:1px solid #d0d0d0 <span style="font-family:Verdana,Arial,Helvetica,sans-serif; white-space:normal; font-size:7px <span style="font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; font-size:13px; color:#333333; line-height:16px Im looking for an easier way to order .NET to look through ALL subdirectories of the application base. Is that possible somehow? Or better yet through all bindebug folders. As of right now, I think I need to specify every single project folder I want it to search through as a relative path to privatebinpath. (which is only working through Assembly.Load not AppDomain.CurrentDomain.Load for some reason btw) <div style="color:Black; background-color:White <pre style="font-size:11px; border:1px solid #d0d0d0 <span style="font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; font-size:13px; white-space:normal; color:#333333; line-height:16px <div style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:black; background-color:white; padding:0px; margin:0px; border:0px initial initial <pre style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; list-style-type:none; text-decoration:none; word-wrap:break-word; padding:0px; margin:0px; border:0px none initial AppDomainSetup newSetup = <span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial new AppDomainSetup();
newSetup.ApplicationBase = solutionFolder;
newSetup.PrivateBinPath = <span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:#a31515; padding:0px; margin:0px; border:0px initial initial "ConsoleApplication1/bin/Debug;"+
<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:#a31515; padding:0px; margin:0px; border:0px initial initial "ConsoleApplication1/bin/Debug/";[/code]

[/code]

[/code]



View the full article
 

Similar threads

K
Replies
0
Views
237
Khan345
K
D
Replies
0
Views
159
Drew1903
D
D
Replies
0
Views
110
Donald Uko
D
Back
Top