Robert Jordan
9/27/2004 11:28:00 PM
Patrick Bristow wrote:
> 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.
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
>
> "Ken Kolda" wrote:
>
>
>>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
>>
>>
>>"Patrick Bristow" <PatrickBristow@discussions.microsoft.com> wrote in
>>message news:1AD13E7A-7121-4302-A9D1-4F2724DDC134@microsoft.com...
>>
>>>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.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>,
>>>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
>>>
>>>
>>>"Robert Jordan" wrote:
>>>
>>>>Ken Kolda wrote:
>>>>
>>>>
>>>>>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
>>>>>
>>>>>
>>>>>"Patrick Bristow" <PatrickBristow@discussions.microsoft.com> wrote in
>>>>>message news:BA5F3D14-1A0E-4287-AAB5-CFFDE1F7E9D9@microsoft.com...
>>>>>
>>>>>
>>>>>>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
>>>>>
>>>>>
>>>>>
>>
>>