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();
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.