My main project loads libraries with devices and creates instances for them. After publishing in the Debug mode, the project works fine, the problem appears when it is published in the Release mode. I don't know why, but it doesn't wait for the objects it creates to initialize.
Here is a code snippet:
try
{
AssemblyName name = AssemblyName.GetAssemblyName(module);
Type[] iLoadTypes = (from t in Assembly.Load(name).GetExportedTypes()
where !t.IsInterface && !t.IsAbstract
where typeof(IDevice).IsAssignableFrom(t)
select t).ToArray();
if (iLoadTypes.Length > 0)
{
IDevice[] instantiatedDevices =
iLoadTypes.Select(t => (IDevice)Activator.CreateInstance(t)).ToArray();
foreach (var device in instantiatedDevices)
{
Devices.Add(device);
}
}
iLoadTypes = (from t in Assembly.Load(name).GetExportedTypes()
where !t.IsInterface && !t.IsAbstract
where typeof(IDeviceToolProvider).IsAssignableFrom(t)
select t).ToArray();
IDeviceToolProvider[] instantiatedProviders =
iLoadTypes.Select(t => (IDeviceToolProvider)Activator.CreateInstance(t)).ToArray();
foreach (var provider in instantiatedProviders)
{
var device = Devices.Find(dev => dev.GetType() == provider.DeviceType);
if (device == null)
continue;
provider.Device = device;
if (!DeviceToolProviders.ContainsKey(device))
DeviceToolProviders[device] = new List<IDeviceToolProvider>();
DeviceToolProviders[device].Add(provider);
provider.Initialize();
}
}
catch (Exception ex)
{
}
And one of the objects that are created:
public class WZWCDeviceTesterToolProvider : IDeviceToolProvider
{
internal static readonly UserSettingEntry<ConnectionDescriptorBuilder> ConnectorDescriptorBuilderEntry =
UserSettingEntry.Register("ConnectorDescriptorBuilderEntry", typeof(WZWCDeviceTesterToolProvider),
new UserSettingEntryMetadata<ConnectionDescriptorBuilder>());
public string Name { get { return "WZW"; } }
...
public void Initialize()
{
}
}
And it didnt wait for properties ConnectorDescriptorBuilderEntry
. I did a test and added this initialization to the Initialize()
method but it wasn't initialized right there either. And it happens only after some time.
I don't know how, but it worked before, I took over this project from someone else. I didn't change anything in the main project. I just added a new device. It does not throw any errors during initialization. And it eventually initializes everything. There is no asynchronicity here.
Net 4.5
I don't know if the amount of code posted is enough to solve my problem, but maybe someone can tell me where to look for a solution and why it works on Debug and not on Release?