New Posts New Posts RSS Feed: KnowType resolution failing during design time
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

KnowType resolution failing during design time

 Post Reply Post Reply
Author
mikedfox View Drop Down
Newbie
Newbie


Joined: 29-Apr-2010
Posts: 21
Post Options Post Options   Quote mikedfox Quote  Post ReplyReply Direct Link To This Post Topic: KnowType resolution failing during design time
    Posted: 02-Sep-2011 at 7:00am
I have "borrowed" the design time model from the example that IdeaBlade put out called "ClientUI_DevForceIntegration".
 
I have used it in a silverlight app, and it worked great.
 
Now I'm trying to implement it in a WPF app and I get a wierd error at design time.
 
Error in line 1 position 444. Element 'http://schemas.microsoft.com/2003/10/Serialization/Arrays:anyType' contains data
from a type that maps to the name 'http://schemas.datacontract.org/2004/07/DomainModel.Model:ITLUser'. The deserializer has
no knowledge of any type that maps to this name. Consider using a DataContractResolver or add the type corresponding to 'ITLUser'
to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding it to the list of known types passed to DataContractSerializer.
 
ITLUser is an entity in my DevForce datamodel, so it should automatically be a know type. I have even tried marking the ITLUser partial class as a known type, to no avail.
 
The strange thing is that if I comment out the
DomainModel.EntityManagerFactory.UseRealEntityManager();
line, and actually run the program, it deserializes correctly. Its only at design time that it breaks. 
Actually, at design time, I just get no data, I have to hook a second instance of Studio up and debug 
design time to see the error. The error comes when I call
_entityMgr.CacheStateManager.RestoreCacheState(dataStream, new RestoreStrategy(truetrueMergeStrategy.OverwriteChanges), truefalse);
 
Any help? I'm just going to do without design time dat for now. :(
 
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post Posted: 06-Sep-2011 at 5:04pm
Hi mikedfox;

I'm a bit confused here. Please see my thoughts below. Since you said you "borrowed" the design time logic from the ClientUI sample, I'm gonna have to assume that your logic is very similar if not the same.

The strange thing is that if I comment out the

DomainModel.EntityManagerFactory.UseRealEntityManager();

line, and actually run the program, it deserializes correctly.

There's actually no serialization/deserialization process here if you comment out UseRealEntityManager. If you look at the ClientUI sample, if you don't invoke the UseRealEntityManager method, you'll actually end up with design time EntityManager where its DefaultQueryStrategy is set to CacheOnly and it's populating the EntityManager by means of an xml file. 

I guess at this point, I have to stop and ask, how are you populating your design time EntityManager?

_entityMgr.CacheStateManager.RestoreCacheState(dataStream, new RestoreStrategy(truetrueMergeStrategy.OverwriteChanges), truefalse);

Why do you need to call the above line at design time?

I have used it in a silverlight app, and it worked great.

Are you just porting the SL app to WPF? If so, if you look at the ClientUI sample, both of its WPF and SL implementations are using the same Repository class so if one works the other should work as well. Unless of course, you're implementing an entirely different app.


Edited by DenisK - 06-Sep-2011 at 5:04pm
Back to Top
mikedfox View Drop Down
Newbie
Newbie


Joined: 29-Apr-2010
Posts: 21
Post Options Post Options   Quote mikedfox Quote  Post ReplyReply Direct Link To This Post Posted: 08-Sep-2011 at 6:16am
sorry, my mistake. I forgot which parts I "borrowed".
 
 
I'm using the factory pattern from the example. When I actually implement the cache, I'm loading a saved version of my repository, rather than a hand coded xml.
 
So when I run the program with certain parameters, it creates a repository, loads sample data from all the tables, and then writes a copy of the repository entity manager using
 
_entityMgr.CacheStateManager.SaveCacheState(fs, truefalse);
then when I start up, my XXFactoryFromCache class calls 
_entityMgr.CacheStateManager.RestoreCacheState(dataStream, new RestoreStrategy(truetrueMergeStrategy.OverwriteChanges), truefalse);
that call is failing with a known type error at design time, but works if I make it use the XXFactoryFromCache at run time.
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post Posted: 08-Sep-2011 at 4:21pm
mikedfox;

Thanks for the clarification. It turns out that this is a bug. For now, you can use the following workaround.

static DesignEntityManagerFactory() {
      // Register the model's assembly name among probed assemblies
      // Must be called BEFORE the first EM creation else
      // GetDesignEntityCacheState fails w/ deserialization exception
#if SILVERLIGHT
      IdeaBlade.Core.IdeaBladeConfig.Instance.ProbeAssemblyNames
          .Add(typeof(IntersoftSampleEntities).Assembly.FullName);
#else
      CompositionHost.SearchFolders.Add(
        Path.GetDirectoryName(Assembly.GetAssembly(typeof(IntersoftSampleEntities)).Location)
        );
#endif
    }

Notice how we're adding to the CompositionHost.SearchFolders in desktop vs adding the domain model assembly name in SL. Ideally, we shouldn't have to do this.


Edited by DenisK - 08-Sep-2011 at 4:21pm
Back to Top
mikedfox View Drop Down
Newbie
Newbie


Joined: 29-Apr-2010
Posts: 21
Post Options Post Options   Quote mikedfox Quote  Post ReplyReply Direct Link To This Post Posted: 13-Sep-2011 at 1:19pm
You guys rock! That was it.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down