Click here to Skip to main content
15,912,897 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
GeneralRe: Windows Service OR Console Application AS Windows Scheduler Task Pin
Vipul Mehta8-Oct-07 18:03
Vipul Mehta8-Oct-07 18:03 
AnswerRe: Windows Service OR Console Application AS Windows Scheduler Task Pin
mariano.mazzieri8-Oct-07 4:19
mariano.mazzieri8-Oct-07 4:19 
GeneralRe: Windows Service OR Console Application AS Windows Scheduler Task Pin
Vipul Mehta8-Oct-07 17:51
Vipul Mehta8-Oct-07 17:51 
GeneralRe: Windows Service OR Console Application AS Windows Scheduler Task Pin
Dave Kreskowiak8-Oct-07 17:59
mveDave Kreskowiak8-Oct-07 17:59 
GeneralRe: Windows Service OR Console Application AS Windows Scheduler Task Pin
Vipul Mehta8-Oct-07 18:32
Vipul Mehta8-Oct-07 18:32 
QuestionVirtual Memory Problem Pin
mariano.mazzieri8-Oct-07 2:14
mariano.mazzieri8-Oct-07 2:14 
Questionreflection issue Pin
Tauseef A7-Oct-07 23:04
Tauseef A7-Oct-07 23:04 
QuestionBug: AppDomain needs to load Assembly twice Pin
Doomii7-Oct-07 21:18
Doomii7-Oct-07 21:18 
This is a problem that occurs when developing with .Net Framework 2.0 (coding and debugging in VC++ 2005 Express and VC# 2005 Express):

1. Create a normal Windows SDK Console application that loads a DLL using LoadModule() and calls a function (lets call it "load") on the loaded dll.
Lets call the application "App".

2. Create the dll to be loaded: A C++ .Net class library which implements the given "load" function. "load" loads a pure .Net assembly (eg written in C#), takes a static method from it and calls it. It also needs to provide a sample ref class with a method, named ClassA and MethodA.
Lets call this library "PluginA".

3. Create a .Net Class Library in Visual C#, add PluginA to the reference list and implement the static method which will be called by PluginA. In the method it should use ClassA and call MethodA on it.
Lets call the C# lib "PluginB".

4. Ensure that all 3 projects are in different folder. Eg.:
App in App,
PluginA in App/Plugin
PluginB in App/Plugin/DotNet

What happens:
App loads PluginA
PluginA loads PluginB
PluginA and PluginB are now in the same AppDomain and PluginA's Assembly-object contains the desired type ClassA (I checked).

The Problem:
PluginB will still try to load the referenced PluginA again and fail when trying to access ClassA if PluginA is not in PluginB's working directory.
If PluginA is in PluginB's working-directory, PluginB will load PluginA again and AppDomain.CurrentDomain.GetAssemblies() will contain PluginA's Assembly Object twice.

Conclusion?
If 2 Assemblies are in the same AppDomain, they should both be able to use each other's types without having to reload them - Why is this not the case?

This seems to be a bug and MS doesn't seem to have a bugtracker...

-- edit:

It doesn't matter if PluginA uses Assembly.Load(byte[]), Assembly.LoadFrom(string) or Assembly.LoadFile(string), if PluginA is signed or not doesn't seem to play a role either.

PluginB's MethodA of ClassA (C++/CLI) contains:
array^ asms = AppDomain::CurrentDomain->GetAssemblies();
Console::WriteLine("Current assemblies:");
for (int i = 0; i < asms->Length; i++) {
Assembly^ as = asms[i];
Console::WriteLine(as->GetName());
}

When called by PluginB, the output is the following:

Current assemblies:
mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
PluginA, Version=1.0.2837.29213, Culture=neutral, PublicKeyToken=a740aaa0a688231e
msvcm80d, Version=8.0.50608.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
PluginB, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
PluginA, Version=1.0.2837.29052, Culture=neutral, PublicKeyToken=a740aaa0a688231e


Where the second PluginA Assembly object has been loaded by PluginB, after I copied PluginA again to the working directory. If I do not copy PluginA, PluginB (when PluginA uses Assembly.Load(byte[]) for loading) will throw the following exception (Standard windows Console output, thus badly formatted - sorry):


##########################################################################

Failed loading assembly: System.Reflection.TargetInvocationException: Exception
has been thrown by the target of an invocation. ---> System.IO.FileNotFoundExcep
tion: Could not load file or assembly 'PluginA, Version=1.0.2837.29052, Culture=
neutral, PublicKeyToken=a740aaa0a688231e' or one of its dependencies.
File name: 'PluginA, Version=1.0.2837.29052, Culture=neutral, PublicKeyToken=a74
0aaa0a688231e'
at PluginB.Class1..ctor()

=== Pre-bind state information ===
LOG: User = DOMINIK\Domi
LOG: DisplayName = PluginA, Version=1.0.2837.29052, Culture=neutral, PublicKeyTo
ken=a740aaa0a688231e
(Fully-specified)
LOG: Appbase = file:///d:/Projects/C++/test/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : PluginB, Version=1.0.0.0, Culture=neutral, PublicKeyToken=
null.
===
LOG: This bind starts in default load context.
LOG: No application configuration file found.
LOG: Using machine configuration file from C:\WINDOWS\Microsoft.NET\Framework\v2
.0.50727\config\machine.config.
LOG: Post-policy reference: PluginA, Version=1.0.2837.29052, Culture=neutral, Pu
blicKeyToken=a740aaa0a688231e
LOG: Attempting download of new URL [...]



I also posted this behavior at: Microsoft forums
AnswerRe: Bug: AppDomain needs to load Assembly twice Pin
originSH8-Oct-07 3:28
originSH8-Oct-07 3:28 
GeneralRe: Bug: AppDomain needs to load Assembly twice Pin
Doomii8-Oct-07 5:41
Doomii8-Oct-07 5:41 
GeneralRe: Bug: AppDomain needs to load Assembly twice Pin
originSH8-Oct-07 6:23
originSH8-Oct-07 6:23 
GeneralRe: Bug: AppDomain needs to load Assembly twice Pin
Doomii8-Oct-07 8:18
Doomii8-Oct-07 8:18 
GeneralRe: Bug: AppDomain needs to load Assembly twice Pin
originSH8-Oct-07 10:08
originSH8-Oct-07 10:08 
QuestionDisplay Properties Pin
bfinighan7-Oct-07 18:21
bfinighan7-Oct-07 18:21 
GeneralRe: Display Properties Pin
Paul Conrad31-Dec-07 9:26
professionalPaul Conrad31-Dec-07 9:26 
Questionnew features of .net framework 2.0 at higher level Pin
mukkanti0076-Oct-07 22:37
mukkanti0076-Oct-07 22:37 
AnswerRe: new features of .net framework 2.0 at higher level Pin
Pete O'Hanlon7-Oct-07 9:07
mvePete O'Hanlon7-Oct-07 9:07 
GeneralRe: new features of .net framework 2.0 at higher level Pin
mukkanti0077-Oct-07 21:17
mukkanti0077-Oct-07 21:17 
GeneralRe: new features of .net framework 2.0 at higher level Pin
lmoelleb8-Oct-07 2:03
lmoelleb8-Oct-07 2:03 
QuestionHow to write propect a Drive .... Pin
Gopi Ramanathan5-Oct-07 20:50
Gopi Ramanathan5-Oct-07 20:50 
QuestionIs there any.... Pin
MMaines20055-Oct-07 16:49
MMaines20055-Oct-07 16:49 
AnswerRe: Is there any.... Pin
lmoelleb6-Oct-07 1:26
lmoelleb6-Oct-07 1:26 
GeneralRe: Is there any.... Pin
George L. Jackson6-Oct-07 5:00
George L. Jackson6-Oct-07 5:00 
QuestionMaking a menu-like form. Pin
chaiguy13375-Oct-07 15:56
chaiguy13375-Oct-07 15:56 
AnswerRe: Making a menu-like form. Pin
chaiguy13375-Oct-07 16:17
chaiguy13375-Oct-07 16:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.