0
votes

The Servicecontract & OperationContract looks like below:

[ServiceContract]
public interface IAssemblyResolver
{

    [OperationContract]
    Assembly LoadAssembly(AssemblyLoadRequest loadRequest);
    // TODO: Add your service operations here
}

While returning type Assembly, i get below error in trace log:

There was an error while trying to serialize parameter http://tempuri.org/:LoadAssemblyResult. The InnerException message was 'Type 'System.Reflection.RuntimeAssembly' with data contract name 'RuntimeAssembly:http://schemas.datacontract.org/2004/07/System.Reflection' is not expected. Consider using a DataContractResolver if you are using DataContractSerializer or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to the serializer.'. Please see InnerException for more details.

On Client Side I get below error:

Additional information: An error occurred while receiving the HTTP response to http://localhost:8769/AssemblyResolverService.svc. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.

1
Do you want to return dll binary? - Wojtpl2
Please explain what you're trying to do. This sounds like it's not going to work. If you want your WCF service to host DLLs for clients, you'll need to stream the DLL and its dependencies to the client. - CodeCaster
I wanted to load a Assembly from a shared location and simply return that. - Amit
Yes, that part is clear. But that's not going to work. An Assembly instance is tied to the AppDomain it's loaded in, being the AppDomain your service runs in. Your client has a different AppDomain. What problem are you trying to solve by doing this? - CodeCaster
We have some server process running & it depends on certain dll's which we decide at run time and to load those dll's we need to use a service which can provide the assembly. First we try to load that locally if not available then we would use this service putting this handler. AppDomain.CurrentDomain.AssemblyResolve += resolver.LoadAssembly; Does this make sense now ? - Amit

1 Answers

0
votes

You need to manually serialize Assembly to string using Assembly.FullName and return it. For deserialize string to Assembly use Assembly.Load method.

Server example:

string LoadAssembly(AssemblyLoadRequest loadRequest)
{
    return ....Assembly.FullName;
}

Using on client side:

Assembly.Load(LoadAssembly(....));

If you need to serialize assembly as file (if it is not exists on client side), you can try this:

Server example:

byte[] LoadAssembly(AssemblyLoadRequest loadRequest)
{
    return File.ReadAllBytes(....Assembly.Location);
}

Using on client side:

var assembly = Assembly.Load(LoadAssembly(....));

But if you load assembly from byte array, you need to use reflection for work with types from this assembly.