-
May 14th, 2013, 03:16 PM
#1
"No valid exports were found that match the constraint" in Release, but not Debug
Hello all. I am using VS2010 with .NET 4
I have some code that looks in a directory for any dlls and then finds the one that contains the correct exports and reads it in.
The code is below:
Code:
var catalog = new AggregateCatalog();
_container = new CompositionContainer(catalog);
string exePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string roofcalcPath = Path.Combine(exePath, "roofcalc");
if (Directory.Exists(roofcalcPath))
{
try
{
// where to find the calculator DLL
try
{
catalog.Catalogs.Add(new DirectoryCatalog(roofcalcPath));
}
catch (ReflectionTypeLoadException rtle)
{
Type[] err = rtle.Types;
}
// Load calculator DLL, create and store reference to object instances
// that are marked Import in this class.
_container.ComposeParts(this);
}
catch (System.ComponentModel.Composition.ChangeRejectedException)
{
// expected exception of calculator DLL is not present in the directory
Calculator = null;
}
}
The dll that I'm trying to load implements the proper interface
Code:
[Export(typeof(IRoofCalc))]
public class GPiStructHelper : IRoofCalc
{
/// <summary>
/// Call this from iStruct to pass in the structural data and
/// return a list of reaction loads to be further processed by iStruct
/// </summary>
/// <param name="structureData"></param>
/// <returns></returns>
ResultData IRoofCalc.CalculateReactions(StructureData structureData)
{
//convert iStruct data to GP data
GPHelperClass.ImportData(structureData);
//Design each member
List<GPRoofMember> rfMembers = new List<GPRoofMember>();
List<GPColumnBracing> cols = new List<GPColumnBracing>();
List<GPStrongback> strgbks = new List<GPStrongback>();
foreach (KeyValuePair<long, GPObject> gpObject in StaticGPiStructHelper.StructuralItems)
{
if (gpObject.Value is GPRoofMember)
{
GPRoofMember target = gpObject.Value as GPRoofMember;
rfMembers.Add(target);
}
if (gpObject.Value is GPStrongback)
{
GPStrongback stbk = gpObject.Value as GPStrongback;
if (!stbk.IsWall)
strgbks.Add(stbk);
}
if (gpObject.Value is GPColumnBracing)
{
GPColumnBracing col = gpObject.Value as GPColumnBracing;
if (col.GetOwner() == 0)
cols.Add(col);
}
}
foreach(GPRoofMember target in rfMembers)
if (!target.IsDesigned)
target.Design();
//Transfer loads for strongbacks and bracing
foreach (GPStrongback stbk in strgbks)
{
stbk.TransferLoads();
}
foreach(GPColumnBracing col in cols)
{
col.TransferLoads();
}
//convert data from GP to iStruct
return GPHelperClass.ExportData();
}
Sample IRoofCalc.CalcWithData(Sample samp)
{
return null;
}
string IRoofCalc.Hello()
{
string msg = "Not implemented";
return msg;
}
}
It works perfectly and is able to read the dll and perform the functions when I use the DEBUG version of the dll, however when I use the RELEASE version I get the following error message
The composition remains unchanged. The changes were rejected because of the following error(s): The composition produced a single composition error. The root cause is provided below. Review the CompositionException.Errors property for more detailed information.
1) No valid exports were found that match the constraint '((exportDefinition.ContractName == "StructuredDesign.RoofCalcInterface.IRoofCalc") AndAlso (exportDefinition.Metadata.ContainsKey("ExportTypeIdentity") AndAlso "StructuredDesign.RoofCalcInterface.IRoofCalc".Equals(exportDefinition.Metadata.get_Item("ExportTypeIdentity"))))', invalid exports may have been rejected.
Resulting in: Cannot set import 'GPAddonTestHarness.Host.Calculator (ContractName="StructuredDesign.RoofCalcInterface.IRoofCalc")' on part 'GPAddonTestHarness.Host'.
Element: GPAddonTestHarness.Host.Calculator (ContractName="StructuredDesign.RoofCalcInterface.IRoofCalc") --> GPAddonTestHarness.Host
Please help me figure out what the heck is going on.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|