Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Remoting / September 2004

Tip: Looking for answers? Try searching our database.

Activator.CreateInstance & Remoting

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Patrick Bristow - 27 Sep 2004 20:25 GMT
I had an application that used basic TCP remoting working great.  But when I
tried to use a wrapper interface for my remote object &
Activator.CreateInstance, I couldn't seem to get things working again.  
Here's the code with excess removed:

Server-side:

IChannel channel = new TcpServerChannel( "Archiver",  
Constants.TCPListeningPort);
System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(channel);
RemotingConfiguration.RegisterActivatedServiceType(typeof(Archiver));

Client-side:

IArchiver iarch;
ObjectHandle oh = Activator.CreateInstance
  ( "Archiver", "MSR.LST.ArchiveService.Archiver",
    new Object[]{new UrlAttribute("tcp://localhost:8082")} );
iarch = oh.Unwrap();

Note that on the client-side I'm using an interface wrapper for Archiver,
thus preventing the implementation from being on the client (standard
technique).

What happens is that I get an exception on Activator.CreateInstance saying
assembly "Archiver" cannot be found.  I've also tried a host of other
Activator.CreateInstance overrides with varying params, to no avail.

Help would be greatly appreciated.
Thanks,
-pb
Ken Kolda - 27 Sep 2004 21:21 GMT
I believe you have to supply the fully assembly name (with version, culture,
etc.) when calling Activator.CreateInstance().

Ken

> I had an application that used basic TCP remoting working great.  But when I
> tried to use a wrapper interface for my remote object &
[quoted text clipped - 27 lines]
> Thanks,
> -pb
Robert Jordan - 27 Sep 2004 21:30 GMT
> I believe you have to supply the fully assembly name (with version, culture,
> etc.) when calling Activator.CreateInstance().

That's right.

Activator.CreateInstanceFrom() expects *file* names while
Activator.CreateInstance() expects *assembly* names, which
are different animals.

bye
Rob

> Ken
>
[quoted text clipped - 32 lines]
>>Thanks,
>>-pb
Patrick Bristow - 27 Sep 2004 21:53 GMT
That sounds great, but I can't get it to work.  I changed the Activator call
to be:
Object o = Activator.CreateInstance
 ( "Archiver, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null",
 "MSR.LST.ArchiveService.Archiver",
 new Object[]{new UrlAttribute("tcp://localhost:8082")} );

I got the assembly name programmatically, so it should be correct (is there
another way to get that?).  The exception thrown was:
FileNotFoundException: Message    "File or assembly name Archiver, or one of
its dependencies, was not found."  The call stack indicated was (with some
chopped off the bottom):

    mscorlib.dll!System.Reflection.Assembly.InternalLoad(System.Reflection.AssemblyName
assemblyRef = {System.Reflection.AssemblyName}, bool stringized = true,
System.Security.Policy.Evidence assemblySecurity = <undefined value>,
System.Threading.StackCrawlMark stackMark = LookForMyCaller) Line 1136 + 0x19
bytes    C#
    mscorlib.dll!System.Reflection.Assembly.InternalLoad(string assemblyString
= "Archiver, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null",
System.Security.Policy.Evidence assemblySecurity = <undefined value>,
System.Threading.StackCrawlMark stackMark = LookForMyCaller) Line 1101 + 0x13
bytes    C#
    mscorlib.dll!System.Activator.CreateInstance(string assemblyName =
"Archiver, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null", string
typeName = "MSR.LST.ArchiveService.Archiver", bool ignoreCase = false,
System.Reflection.BindingFlags bindingAttr = 532, System.Reflection.Binder
binder = <undefined value>, System.Object[] args = <undefined value>,
System.Globalization.CultureInfo culture = <undefined value>, System.Object[]
activationAttributes = {Length=1}, System.Security.Policy.Evidence
securityInfo = <undefined value>, System.Threading.StackCrawlMark stackMark =
LookForMyCaller) Line 250 + 0xd bytes    C#
    mscorlib.dll!System.Activator.CreateInstance(string assemblyName =
"Archiver, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null", string
typeName = "MSR.LST.ArchiveService.Archiver", System.Object[]
activationAttributes = {Length=1}) Line 158 + 0x20 bytes    C#
>    ArchiverDotDispose.exe!ArchiverDotDispose.Form1.SetupArchiver() Line 446 + 0x4c bytes    C#

Any suggestions?

Thanks,
-pb

> > I believe you have to supply the fully assembly name (with version, culture,
> > etc.) when calling Activator.CreateInstance().
[quoted text clipped - 44 lines]
> >>Thanks,
> >>-pb
Ken Kolda - 27 Sep 2004 22:43 GMT
Now that I look at the error I realize I gave you irrelevant advice. If you
want to use CAOs without the implementation on the client, the only way I
know of to do that is using the Factory model (i.e. have an SAO which
returns CAO instances from its methods). The problem with
Activator.CreateInstance() is that it the overload you're using:

Activator.CreateInstance(assemblyName, typeName, attributes)

is equivalent to calling this sequence of code:

Assembly a = Assembly.Load(assemblyName);
Type t = a.GetType(typeName);
Activator.CreateInstance(t, attributes);

This is clearly not what you wanted because you don't want the client to
load the type.

Ken

> That sounds great, but I can't get it to work.  I changed the Activator call
> to be:
[quoted text clipped - 8 lines]
> its dependencies, was not found."  The call stack indicated was (with some
> chopped off the bottom):

mscorlib.dll!System.Reflection.Assembly.InternalLoad(System.Reflection.Assem
blyName
> assemblyRef = {System.Reflection.AssemblyName}, bool stringized = true,
> System.Security.Policy.Evidence assemblySecurity = <undefined value>,
> System.Threading.StackCrawlMark stackMark = LookForMyCaller) Line 1136 + 0x19
> bytes C#
>   mscorlib.dll!System.Reflection.Assembly.InternalLoad(string
assemblyString
> = "Archiver, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null",
> System.Security.Policy.Evidence assemblySecurity = <undefined value>,
[quoted text clipped - 14 lines]
> activationAttributes = {Length=1}) Line 158 + 0x20 bytes C#
> > ArchiverDotDispose.exe!ArchiverDotDispose.Form1.SetupArchiver() Line 446
+ 0x4c bytes C#

> Any suggestions?
>
[quoted text clipped - 50 lines]
> > >>Thanks,
> > >>-pb
Patrick Bristow - 28 Sep 2004 00:05 GMT
Ahh... how bizarre...  you see, I just rewrote the object so that it uses an
interface published in a seperate assembly.  I've been doing work on this
project for most of a month now just using a CAO and "new'ing" the instances.
By call stack I had verified that it was creating the objects on the server,
so I knew it was all working fine.  But since I want to do it "right", I
really can't do it w/o a seperate SAO for a class factory?  Wow... that's a
pain.

Ok, thanks so much.
-pb

> Now that I look at the error I realize I gave you irrelevant advice. If you
> want to use CAOs without the implementation on the client, the only way I
[quoted text clipped - 120 lines]
> > > >>Thanks,
> > > >>-pb
Robert Jordan - 28 Sep 2004 00:27 GMT
> Ahh... how bizarre...  you see, I just rewrote the object so that it uses an
> interface published in a seperate assembly.  I've been doing work on this
[quoted text clipped - 3 lines]
> really can't do it w/o a seperate SAO for a class factory?  Wow... that's a
> pain.

You can generate class stubs (empty implementations) for
your CAOs with soapsuds.exe (SDK tool). The stubs allow
you "new'ing" the CAOs w/out deploying the full implementation
on the client.

However, I find SAO + class factory a much cleaner approach.

bye
Rob

> Ok, thanks so much.
> -pb
[quoted text clipped - 148 lines]
>>>>>>Thanks,
>>>>>>-pb

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.