We have a project that watches a folder of C# files and (re)compiles and (re)loads the resulting assembly whenever those files are changed. If I try to use a class in these C# files as a type parameter to RepoDB's Query
, or Insert
, etc. functions, I get an error similar to this:
[A]MyNamespace.MyModelClass cannot be cast to [B]MyNamespace.MyModelClass. Type A originates from 'DynamicallyRecompiledAssembly001, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' in the context 'LoadFrom' at location 'C:\Path\DynamicallyRecompiledAssembly001.dll'. Type B originates from 'DynamicallyRecompiledAssembly002, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' in the context 'Default' at location 'C:\Path\DynamicallyRecompiledAssembly002.dll'.
Is there anything I can do to make RepoDB "forget" about the previous version of the type and switch to the new version of the type?
I've tried using the new file
access modifier on the class because I had hoped the name of the class that gets generated would change after each compilation and that whatever RepoDB does to keep track of types would treat the types as different, but that didn't work: The classes still had the same name and I got the same error. I thought maybe I could remove the old class from the RepoDB.ClassMapper
from the class's static constructor, but I'm not sure how to remove it when at the time the static constructor runs, I don't have a reference to the previously-defined type any more.
EDIT:
I tried adding this with the hope that at least one of these caches held the mapping for the class, but I'm still getting the same error:
[RepoDb.Attributes.Map(TableName)]
public class MyTable
{
static MyTable()
{
RepoDb.ClassMapper.Clear();
RepoDb.TypeMapper.Clear();
RepoDb.PrimaryMapper.Clear();
RepoDb.IdentityMapper.Clear();
RepoDb.PropertyMapper.Clear();
//RepoDb.DbSettingMapper.Clear(); // broke RepoDb
RepoDb.ClassHandlerMapper.Clear();
RepoDb.PropertyHandlerMapper.Clear();
// RepoDb.StatementBuilderMapper.Clear(); // also broke RepoDb
RepoDb.PropertyValueAttributeMapper.Clear();
RepoDb.TypeMapCache.Flush();
RepoDb.ClassMappedNameCache.Flush();
RepoDb.PropertyMappedNameCache.Flush();
}
// ...
}