[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ms-dotnet-language-devs
Subject:    Re: Another silly question
From:       Nick Robinson <nicholasrobinson () YAHOO ! CO ! UK>
Date:       2003-07-14 19:09:09
[Download RAW message or body]

Hi Serge,

I think the root of my problem is how I have gone about doing what I am
trying to do.  Using Emit I used a Type loaded from the second assembly to
get me a MethodInfo on a method call.  Loading an instance of a type from
the second library, still seems to invoke the method on the class of the
same name in the calling assembly.  I am building a proxy basically, but it
fails to work due to this problem.  However all I do is rename the source
assembly to something like Foo.dll to _foo.dll.  I dont change anything in
the manifest or metadata to do with _foo.dll.  I then create a new class and
assembly, mirroring whats in _foo.  But when a method is invoked on say
FooBar loaded from Foo.dll, I daisy chain the call to the instance I loaded
to _foo.dll.  Now the instance is definitely the one loaded during
construction (i.e. to _foo.dll) when I invoke callvirt with the MethodInfo
object I have obtained from _foo.dll during the creation of my emit code.
However this still seems to call back into Foo.dll instead of _foo.dll - the
chain doesnt work.

I kinda got this working in an evening working through the help in .NET and
then purchased your book and John Goughs.  I have left this for a while as I
need to work on something else, but I am curious about this.  When I looked
in the IL I could see that both the name of the class in Foo and that in
_foo was the same, so other than having a different instance on the stack at
the right time, I couldnt see how else the assemblies were being resolved.
This is my first time touching the emit or IL so you must forgive me if I
have doing something stupid.  Maybe I should knock out some code that
highlights my problem - the current stuff is at work so I will have to wait.

Thanks,

Nick.

> -----Original Message-----
> From: Compiler Developers for .NET
> [mailto:DOTNET-LANGUAGE-DEVS@DISCUSS.MICROSOFT.COM]On Behalf Of Serge
> Lidin
> Sent: 14 July 2003 18:05
> To: DOTNET-LANGUAGE-DEVS@DISCUSS.MICROSOFT.COM
> Subject: Re: Another silly question
>
>
> AssemblyRefs with the same name but different versions (or
> cultures, or public key tokens) are different AssemblyRefs, so
> TypeRefs scoped to these AssemblyRefs are considered different.
> ILASM and Reflection.Emit allow to reference same-name classes
> from same-name different-version assemblies. CLR Loader treats
> different-version assemblies as different assemblies, so there's
> no problem there either.
>
> Thanks,
> Serge
>
> -----Original Message-----
> From: Compiler Developers for .NET
> [mailto:DOTNET-LANGUAGE-DEVS@DISCUSS.MICROSOFT.COM]On Behalf Of Mitch
> Denny
> Sent: Saturday, July 12, 2003 11:07 PM
> To: DOTNET-LANGUAGE-DEVS@DISCUSS.MICROSOFT.COM
> Subject: Re: Another silly question
>
>
> Nick,
>
> That is a heck of a challenge. Off the top of my head I don't
> think that you
> can do it because the type resolver (from my understanding) once it has
> identified the assembly as a source for the type, it won't bother look for
> others. Actually, I wondered a year ago whether a feature worth adding to
> the runtime was the ability to specify specific assemblies and versions
> inline with the newobj calls. I suspect that there would be an efficiency
> issue there, both with runtime execution and binary size. It would be
> interesting to have this capability in C#:
>
>         [Hint("MyLib, Version=1.0.0.0")]ICat cat = new Cat();
>         [Hint("MyLib, Version=2.0.0.0")]ICat cat = new Cat();
>
> You can imagine all the complications it would introduce however!
>
> ----------------------------------------
> - Mitch Denny
> - mitch.denny@monash.net
> - http://www.monash.net
> - +61 (414) 610141
> -
>
> -----Original Message-----
> From: Compiler Developers for .NET
> [mailto:DOTNET-LANGUAGE-DEVS@DISCUSS.MICROSOFT.COM] On Behalf Of Nicholas
> Robinson
> Sent: Thursday, 10 July 2003 11:54 PM
> To: DOTNET-LANGUAGE-DEVS@DISCUSS.MICROSOFT.COM
>
> Hi,
>
> I have two assemblies that are named differently, but internally they are
> the same.  For example, if I have an assembly called Foo.dll, I may have a
> foo_backup.dll.  However there may be a type in both named such as
> Foo.SomeClass.  If in Foo I try to create a new instance of Foo.SomeClass
> from the foo_backup.dll, I cant seem to achieve it without resorting to
> reflection.  I would very much like to create a SomeClass instance inside
> Foo using newobj, which instantiates the type in foo_backup.dll.
> Currently
> I get stack overflow, because the type resolver is obviously
> looking at Foo
> inside foo.dll and creating a new version of it.  Since during
> construction
> I want to creeate a reference to the type in foo_backup.dll, I can never
> instantiate the class without the stack overflow error.  I have
> been racking
> my brain and cannot think of how to solve this without reflection, which I
> dont want to do if I dont have to.
>
> Thanks for any advice,
>
> Nick.
>
>
>
> ________________________________________________________________________
> Want to chat instantly with your online friends?  Get the FREE Yahoo!
> Messenger http://uk.messenger.yahoo.com/
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic