Hi,
I am getting the following error when saving a business object.
"Unable to cast object of type 'Library.FormatParameters' to type 'Csla.BusinessBase`1[Library.FormatParameters]'."
I am loading the DLL that contains the business object at run time as I need a pluggable type architecture. My DalManager is attached. It works to read in the business object but fails when I try to save the changes.
I found this post that is quite old but I do not know if this is the same problem and if so where the solution is in the new books.
http://forums.lhotka.net/forums/t/3732.aspx
using System;
using System.Reflection;
namespace DataAccess.Mock
{
public class DalManager : DataAccess.IDalManager
{
private static string _typeMask = typeof(DalManager).FullName.Replace("DalManager", @"{0}");
Assembly ass = null;
public T GetProvider<T>() where T : class
{
var typeName = string.Format(_typeMask, typeof(T).Name.Substring(1));
if (typeName.Contains("FormatParameters"))
{
// Load assembly
ass = Assembly.LoadFile(@"C:\Dev\B4B\Formats\XYZ\XYZViews\bin\Debug\XYZViews.DLL");
// Create DAL instance.
AppDomain.CurrentDomain.Load(ass.GetName());
// Create instance of formatparametersview class.
Type dalType = ass.GetType("DataAccess.SQL.FormatParametersDal");
if (dalType == null)
throw new NotImplementedException(typeName);
dynamic dal = Activator.CreateInstance(dalType);
//var type = Type.GetType(typeName);
if (dal != null)
{
// Assign connection string.
dal.ConnectionString = "Server=server;Database=TEST6;Uid=User;Pwd=XX;";
// return object.
return dal as T;
}
else
throw new NotImplementedException(typeName);
}
else
{
var type = Type.GetType(typeName);
if (type != null)
return Activator.CreateInstance(type) as T;
else
throw new NotImplementedException(typeName);
}
}
public void Dispose()
{ }
}
}
Copyright (c) Marimer LLC