Question

I've been struggling with a problem for the past couple days and haven't found a solution.

I have an Visual Studio solution with 2 projects, the first one is a DLL with my business objects and logic, the other project is my WinForm application, and a reference dependency on the first project.

I initially wrote the business objects with Attribute LINQ mapping and everything was working fine. Then I thought I would try external mapping. I followed a few different guides on how it should work; however, everytime I ran the code in my solution I would get a InvalidOperationException: Mapping Problem: Cannot find type 'Org.Example.System.Material' from mapping, when the WinForm attempts to create the DataContext object.

After trying different configurations in the XML file I placed a copy of the class into my GUI solution under a different namespace and it worked. My question is, is it not possible to map an object in a class library or if it is how is it accomplished.

Samples

dbmap.xml

<Database xmlns="http://schemas.microsoft.com/linqtosql/mapping/2007" Name="Gravel_Dev"><Table Name="dbo.Materials" Member="Material">
<Type Name="Org.Example.System.Material">
  <Column Name="MaterialID" Member="MaterialID" Storage="mMaterialID" DbType="UniqueIdentifier NOT NULL" IsDbGenerated="true" IsPrimaryKey="true"/>
  <Column Name="Code" Member="Code" Storage="mMaterialCode" DbType="Char(4)"/>
  <Column Name="Description" Member="Description" Storage="mDescription" DbType="VarChar(50)"/>
  <Column Name="UnitPrice" Member="UnitPrice" Storage="mUnitPrice" DbType="Decimal(5,2)"/>
</Type>

WinForm Loading

XmlMappingSource mapping = XmlMappingSource.FromUrl("dbmap.xml");
mContext = new DataContext(Properties.Settings.Default.dbConn, mapping);
reloadTable();
Was it helpful?

Solution

I think the problem you might be getting is that the assembly/class library containing your classes hasn't been loaded into memory at this stage?

Try accessing a class in the library before instantiating the data context to see if that works.

OTHER TIPS

I have the same problem. We have a mapping file which maps different assemblies and we get the mapping error since all assemplies are not loaded in memory. What are the different solutions to this problem?

I have read that is is possible to reference a type in a different assembly using the AssemblyQualifiedName of the type. But we did not get it to work. If this is possible can you give an example of what this would look like?

Another solution, I suppose, is to have one mapping file for each assembly and give the datacontext the correct mapping file at runtime.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top