I am trying to use the ServiceModelEx library from IDesign. When I try to call:
InProcFactory.CreateInstance();
from with in a WCF Service (basically calling WCF Service B from WCF Service A), I get the following error:
Could not find dynamic assembly
The code that is failing is:
internal static Assembly[] GetWebAssemblies()
{
Debug.Assert(IsWebProcess());
List<Assembly> assemblies = new List<Assembly>();
if(Assembly.GetEntryAssembly() != null)
{
throw new InvalidOperationException("Can only call in a web assembly");
}
foreach(ProcessModule module in Process.GetCurrentProcess().Modules)
{
assemblies.Add(Assembly.LoadFrom(module.FileName));
if (module.ModuleName.StartsWith("App_Code.") && module.ModuleName.EndsWith(".dll"))
{
assemblies.Add(Assembly.LoadFrom(module.FileName));
}
if (module.ModuleName.StartsWith("App_Web_") && module.ModuleName.EndsWith(".dll"))
{
assemblies.Add(Assembly.LoadFrom(module.FileName));
}
}
if (assemblies.Count == 0)
{
throw new InvalidOperationException("Could not find dynamic assembly");
}
return assemblies.ToArray();
}
The assemblies are not pre-fixed with App_Web or App_Code because this is not a web site or a web application (it is a WCF Service). The code does work, however, if I call it from a web site, web application or EXE. Is this by deisgn?
That's the generic resolver falling over. It tries to do it's best to discover all assemblies that might have data contracts in them, but it's something of an arms race as different hosting environments (particularly IIS variants) popup. The introduction of dynamic code has also made life more difficult.
If you use the latest ServiceModelEx (SME) it has fixes to address this. Just make sure you use the latest .NET version (currently 4.6.1) in the download since the older .NET version downloads of SME (e.g. 4.0 and earlier) won't have these fixes. You can downgrade the .NET version (within limits) if needed. E.g. I took the 4.6.1 version down to 4.5.2.
Note: this is only needed if you're using data contract inheritance via the Generic Resolver. If you don't need this feature and it's causing you issues you can just comment out the offending code.