[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Luis F. Rodas

1/22/2008 3:02:00 PM

Hi all,

I am using Assembly.LoadFrom( ) to load an assembly:

Assembly as =
Assembly.LoadFrom("C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll");

I noted 'CodeBase' and 'Location' properties from 'as' variable display the
GAC path, that is, the assembly was loaded from GAC and not from path
"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\". Questions:

1) Why ?

2) I need load some assemblies (they are installed on GAC too) from original
path (e.g. C:\Program Files\MyProgram\MyControls\MyAssembly.dll) and not
from GAC. Any way ?

Best Regards,
Luis F.
(Indusoft Team)


7 Answers

v-lliu

1/23/2008 7:00:00 AM

0

Hi Luis,

I performed several tests on this issue and the result I got is that as
long as a strong-named assembly is added to the GAC, the Load or LoadFrom
or LoadFile method of the Assembly class always loads and returns the
assembly cached in the GAC, no matter whether there's the same assembly
file in the same path of the executable.

So the Runtime always checks the GAC to search for the required assembly
first and then check the application directory if there's no matching in
the GAC. This is behavior is by design and unfortunately we have no chance
to change it.

The workaround to your problem is to uninstall your assembly from the GAC
and copy the assembly file to the application directory(if necessary).

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default....
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/de....
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

schneider

1/23/2008 7:53:00 PM

0

Also note:

LoadFrom: .NET caches the assembly, so if the assembly was already loaded
earlier (assembly with no strong name) it returns the first assembly loaded
(hashed by name?), regardless of version number. The path is basically
ignored.
This method also looks for and loads all dependant assembly items.

http://msdn2.microsoft.com/en-us/library/100...

Also Load and/or LoadFile only loads the specified assembly, and not the
related/dependant items, which can cause problems.

Eric Schneider


"Linda Liu[MSFT]" <v-lliu@online.microsoft.com> wrote in message
news:eb%23DT2YXIHA.4200@TK2MSFTNGHUB02.phx.gbl...
> Hi Luis,
>
> I performed several tests on this issue and the result I got is that as
> long as a strong-named assembly is added to the GAC, the Load or LoadFrom
> or LoadFile method of the Assembly class always loads and returns the
> assembly cached in the GAC, no matter whether there's the same assembly
> file in the same path of the executable.
>
> So the Runtime always checks the GAC to search for the required assembly
> first and then check the application directory if there's no matching in
> the GAC. This is behavior is by design and unfortunately we have no chance
> to change it.
>
> The workaround to your problem is to uninstall your assembly from the GAC
> and copy the assembly file to the application directory(if necessary).
>
> Hope this helps.
> If you have any question, please feel free to let me know.
>
> Sincerely,
> Linda Liu
> Microsoft Online Community Support
>
> ==================================================
> Get notification to my posts through email? Please refer to
> http://msdn.microsoft.com/subscriptions/managednewsgroups/default....
> ications.
>
> Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
> where an initial response from the community or a Microsoft Support
> Engineer within 1 business day is acceptable. Please note that each follow
> up response may take approximately 2 business days as the support
> professional working with you may need further investigation to reach the
> most efficient resolution. The offering is not appropriate for situations
> that require urgent, real-time or phone-based interactions or complex
> project analysis and dump analysis issues. Issues of this nature are best
> handled working with a dedicated Microsoft Support Engineer by contacting
> Microsoft Customer Support Services (CSS) at
> http://msdn.microsoft.com/subscriptions/support/de....
> ==================================================
>
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>


Luis F. Rodas

1/24/2008 12:14:00 PM

0

Hi Linda and Eric,

Thanks for your replies!

I would like to know how Visual Studio 2005 gets the original directories
from some assemblies, such as: System.Design.dll, System.Windows.Forms.dll.
I saw this in the 'References/Properties/Path'. Also probably Visual Studio
loads these asssemblies from the original directories.

Again thanks and best regards!

Luis F.
(Indusoft Team)

"schneider" <eschneider.news.ms@starkinvestments.com> wrote in message
news:OF%23fNmfXIHA.4272@TK2MSFTNGP05.phx.gbl...
> Also note:
>
> LoadFrom: .NET caches the assembly, so if the assembly was already loaded
> earlier (assembly with no strong name) it returns the first assembly
> loaded (hashed by name?), regardless of version number. The path is
> basically ignored.
> This method also looks for and loads all dependant assembly items.
>
> http://msdn2.microsoft.com/en-us/library/100...
>
> Also Load and/or LoadFile only loads the specified assembly, and not the
> related/dependant items, which can cause problems.
>
> Eric Schneider
>
>
> "Linda Liu[MSFT]" <v-lliu@online.microsoft.com> wrote in message
> news:eb%23DT2YXIHA.4200@TK2MSFTNGHUB02.phx.gbl...
>> Hi Luis,
>>
>> I performed several tests on this issue and the result I got is that as
>> long as a strong-named assembly is added to the GAC, the Load or LoadFrom
>> or LoadFile method of the Assembly class always loads and returns the
>> assembly cached in the GAC, no matter whether there's the same assembly
>> file in the same path of the executable.
>>
>> So the Runtime always checks the GAC to search for the required assembly
>> first and then check the application directory if there's no matching in
>> the GAC. This is behavior is by design and unfortunately we have no
>> chance
>> to change it.
>>
>> The workaround to your problem is to uninstall your assembly from the GAC
>> and copy the assembly file to the application directory(if necessary).
>>
>> Hope this helps.
>> If you have any question, please feel free to let me know.
>>
>> Sincerely,
>> Linda Liu
>> Microsoft Online Community Support
>>
>> ==================================================
>> Get notification to my posts through email? Please refer to
>> http://msdn.microsoft.com/subscriptions/managednewsgroups/default....
>> ications.
>>
>> Note: The MSDN Managed Newsgroup support offering is for non-urgent
>> issues
>> where an initial response from the community or a Microsoft Support
>> Engineer within 1 business day is acceptable. Please note that each
>> follow
>> up response may take approximately 2 business days as the support
>> professional working with you may need further investigation to reach the
>> most efficient resolution. The offering is not appropriate for situations
>> that require urgent, real-time or phone-based interactions or complex
>> project analysis and dump analysis issues. Issues of this nature are best
>> handled working with a dedicated Microsoft Support Engineer by contacting
>> Microsoft Customer Support Services (CSS) at
>> http://msdn.microsoft.com/subscriptions/support/de....
>> ==================================================
>>
>> This posting is provided "AS IS" with no warranties, and confers no
>> rights.
>>
>
>


schneider

1/24/2008 4:46:00 PM

0

I think you would need to use the Load or LoadFile method, but then you
would need to load all the dependencies also.
Basically create your own LoadFrom functionality. Maybe not loading your
assembly into GAC is the answer.

Schneider


"Luis F. Rodas" <support@indusoft.com> wrote in message
news:OXEB9eQXIHA.4140@TK2MSFTNGP04.phx.gbl...
> Hi all,
>
> I am using Assembly.LoadFrom( ) to load an assembly:
>
> Assembly as =
> Assembly.LoadFrom("C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll");
>
> I noted 'CodeBase' and 'Location' properties from 'as' variable display
> the GAC path, that is, the assembly was loaded from GAC and not from path
> "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\". Questions:
>
> 1) Why ?
>
> 2) I need load some assemblies (they are installed on GAC too) from
> original path (e.g. C:\Program Files\MyProgram\MyControls\MyAssembly.dll)
> and not from GAC. Any way ?
>
> Best Regards,
> Luis F.
> (Indusoft Team)
>


v-lliu

1/28/2008 8:12:00 AM

0

Hi Luis,

Thank you for your reply!

Open a WinForm application project in VS and right click on the project
item in the Solution Explorer and choose Add Reference command, which will
open the Add Reference dialog.

In the Add Reference dialog, the assemblies shown in the .NET tab are all
retrieved from the original directories by VS, not from GAC.

However, when the WinForm application is run, all the referenced assemblies
that have been cached in the GAC are loaded from the GAC, instead of from
the original directories.

If you have anything unclear, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

Luis F. Rodas

1/29/2008 10:48:00 AM

0

Hi Linda,

Do you have any idea how VS gets the original directories in the Add
Reference dialog ? In my program I would like to display the path of the
controls from the original directories too.

Best Regards,
Luis F.
(Indusoft Team)


"Linda Liu[MSFT]" <v-lliu@online.microsoft.com> wrote in message
news:eGj4$VYYIHA.4200@TK2MSFTNGHUB02.phx.gbl...
> Hi Luis,
>
> Thank you for your reply!
>
> Open a WinForm application project in VS and right click on the project
> item in the Solution Explorer and choose Add Reference command, which will
> open the Add Reference dialog.
>
> In the Add Reference dialog, the assemblies shown in the .NET tab are all
> retrieved from the original directories by VS, not from GAC.
>
> However, when the WinForm application is run, all the referenced
> assemblies
> that have been cached in the GAC are loaded from the GAC, instead of from
> the original directories.
>
> If you have anything unclear, please feel free to let me know.
>
> Sincerely,
> Linda Liu
> Microsoft Online Community Support
>


v-lliu

1/31/2008 10:30:00 AM

0

Hi Luis,

Thank you for your reply!

> Do you have any idea how VS gets the original directories in the Add
Reference dialog ?

IMO, VS searches the assemblies file in some specific directories. So the
original directories are shown in the Add Reference dialog. Note that the
assemblies are not loaded when they are referenced by VS.

> In my program I would like to display the path of the controls from the
original directories too.

The only suggestion I can make is to remove your assembly from GAC. Then
you load the assembly from the original directory.

Sincerely,
Linda Liu
Microsoft Online Community Support