Vinay Pandey
Vinay Pandey

Reputation: 1179

Reflecting on class with property of type defined in deparate assembly

I have following WCF class:

namespace BusinessServices.Exposure.Data
{
    [DataContract]
    public class RiskItemBO : ExposureBO
    {
        [DataMember]
        public RiskItemBusinessService RiskItemBusinessService { get; set; }
    }
}

The RiskItemBusinessService is a class which is defined in some other DLL and consists of String, Int and Short variables. I have methods to generate random values for these data types.

I have following questions:

I am using Type.GetProperties() to get all the properties within a class, which does give me the name of the property RiskItemBusinessService, however, when I try to do PropertyInfo.PropertyType, I get FileNotFoundException (RiskItemBusinessService, is in a different DLL). For this, I am catching the exception and loading the DLL into the catch clause, but still, when I try to do PropertyInfo.SetValue I again get the FileNotFoundException even though I have just loaded the DLL using Assembly.LoadFile.

Upvotes: 3

Views: 237

Answers (1)

Steve Py
Steve Py

Reputation: 34783

This is likely a case were you will want to utilize reused assemblies in your service reference on the client.

Essentially, as John was pointing out, you add a reference to the assembly containing RiskItemBusinessService. Then you go to the Service Reference configuration and enable the option to reuse referenced types, and for specific references, ticking the assembly you just added. This re-generates the service reference without the proxies for types specified. From here your services will be constructung variables from the assembly references so you should be able to use it as you would any other type. enter image description here

Upvotes: 2

Related Questions