Reflection in a Windows Service & WCF
-
Hi, I am trying to run the following code in a dynamically loaded WCF service hosted in a Windows Service. It seems I can't load types because of the following exception: Could not load file or assembly 'APLUGINASSEMBLY, Version=1.4.0.0, Culture=neutral, PublicKeyToken=ddd7975916a1e051' or one of its dependencies. The system cannot find the file specified. Here is the list of the referenced assemblies: mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089Viveo.Data, Version=1.4.0.0, Culture=neutral, PublicKeyToken=ddd7975916a1e051 NavigationProvider, Version=1.0.0.0, Culture=neutral, PublicKeyToken=nullSystem.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 Please note that the very same code works fine when I run the WCF Service from Visual Studio. :doh: Thanks.
protected static void AnalysePlugins(Assembly[] Assemblies)
{
foreach (Assembly anAssembly in Assemblies)
{
try
{
foreach (Type aType in anAssembly.GetExportedTypes())
{
try
{
if (aType.GetInterface("ANINTERFACE") != null)
{
//Retrieves the name of each navigation
string theNavigationName = (string)aType.InvokeMember("Name", BindingFlags.GetProperty, null, aType.GetConstructor(new Type[]{}).Invoke(new object[]{}), null);
//Fills the data structures that keep reference of the navigation/type/assembly
NavigationRepository[theNavigationName] = aType;
PluginRepository[aType] = anAssembly;
}
}
catch(Exception ex)
{
Trace.WriteLine(aType + " could not have its name queried");
}
}
}
catch (Exception ex)
{System.Diagnostics.EventLog.WriteEntry("BusinessServer", ex.Message); System.Diagnostics.EventLog.WriteEntry("BusinessServer", string.Concat(anAssembly.GetReferencedAssemblies())); } } }
-
Hi, I am trying to run the following code in a dynamically loaded WCF service hosted in a Windows Service. It seems I can't load types because of the following exception: Could not load file or assembly 'APLUGINASSEMBLY, Version=1.4.0.0, Culture=neutral, PublicKeyToken=ddd7975916a1e051' or one of its dependencies. The system cannot find the file specified. Here is the list of the referenced assemblies: mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089Viveo.Data, Version=1.4.0.0, Culture=neutral, PublicKeyToken=ddd7975916a1e051 NavigationProvider, Version=1.0.0.0, Culture=neutral, PublicKeyToken=nullSystem.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 Please note that the very same code works fine when I run the WCF Service from Visual Studio. :doh: Thanks.
protected static void AnalysePlugins(Assembly[] Assemblies)
{
foreach (Assembly anAssembly in Assemblies)
{
try
{
foreach (Type aType in anAssembly.GetExportedTypes())
{
try
{
if (aType.GetInterface("ANINTERFACE") != null)
{
//Retrieves the name of each navigation
string theNavigationName = (string)aType.InvokeMember("Name", BindingFlags.GetProperty, null, aType.GetConstructor(new Type[]{}).Invoke(new object[]{}), null);
//Fills the data structures that keep reference of the navigation/type/assembly
NavigationRepository[theNavigationName] = aType;
PluginRepository[aType] = anAssembly;
}
}
catch(Exception ex)
{
Trace.WriteLine(aType + " could not have its name queried");
}
}
}
catch (Exception ex)
{System.Diagnostics.EventLog.WriteEntry("BusinessServer", ex.Message); System.Diagnostics.EventLog.WriteEntry("BusinessServer", string.Concat(anAssembly.GetReferencedAssemblies())); } } }
I found out! It works when I load the assemblies using LoadFrom instead of LoadFile (it is in a function that I have not provided).