I realize it was a while ago that you posted your question, but since I recently had a cache problem of my own (and wish these boards were more active!), I figured I'd see if I could help at all.It appears you're doing or have done most of the same things my program does - the main difference I see in the code you use and what I do (I'm on the Win32 version) is that I create and open the cache before synchronizing with FeatureLayerSyncAgents.I remember I was getting the same error as you a while ago when I started developing with the 10 SDK - I fixed it but don't recall the details.Anyway, here's what my code does - I've omitted parts and clipped out some stuff, but you should be able to see the main procedures (sorry it's messy, don't have time to streamline it to make it clear.)Good luck
private void frmMain_Load(object sender, EventArgs e) {
// Specify the mobileservice URL
CacheStoragePath = String.Format(@"{0}\GPS_Cache", Common.GetDataRootPath());
//Setup the layer sync object
InitializeSyncMaster();
//If we're going to create a new map cache, archive the previous one so we don't ever delete data on accident
CacheOpenMode mode = MapHelpers.GetCacheOpenMode();
//set security credentials to connect to the mobile service
ConfigureServiceConnectionSecurity(this.mobileServiceConnection1);
//download or initialize / open the map cache
InitializeCache(this.mobileServiceConnection1, this.mobileCache1, CacheStoragePath, mode);
mobileCache1.Open();
//if we don't have any data in the cache start downloading
if (mobileCache.IsEmpty) {
IsInitializingData = true;
BeginDownloadData(true);
}
}
private CredentialCache ConfigureServiceConnectionSecurity(MobileServiceConnection serviceConnection) {
mobileServiceConnection1.WebClientProtocolType = WebClientProtocolType.BinaryWebService;
//OMITTED CODE WHERE I SET UP MY USER CREDENTIALS
NetworkCredential credentials = new NetworkCredential(String.Format(@"{0}\{1}", serverID, serverLoginUser), serverLoginPassword);
CredentialCache credentialscache = new CredentialCache();
serviceConnection.Url = Common.GetConfigValue("MobileServiceURL");
credentialscache.Add(new Uri(Common.GetConfigValue("MobileServiceURL")), "Basic", credentials);
serviceConnection.WebClientProtocol.Credentials = credentialscache;
return credentialscache;
}
private void InitializeSyncMaster() {
SyncMaster = new MobileCacheSyncAgent(mobileCache1);
SyncMaster.MapDocumentConnection = mobileServiceConnection1;
SyncMaster.ProgressChanged += SyncMaster_ProgressChanged;
SyncMaster.StateChanged += SyncMaster_StateChanged;
this.SyncResults = new SyncResults(this.SyncMaster);
}
public void BeginDownloadData(bool initializeSyncAgents) {
if (initializeSyncAgents) {
SetupSyncAgents();
}
if (this.mobileServiceConnection1.IsValid) {
SyncMaster.BeginDownloadExtent(map1.GetFullExtent(), 0, 0, DownloadExtent, Guid.NewGuid());
}
}
public void SetupSyncAgents(List<string> LayersToSync) {
this.DisplayedNotConnectedErrorMessage = false;
if (SyncMaster.SyncAgents != null && SyncMaster.SyncAgents.Count() > 0) {
this.SyncResults.SyncResultsDataTable.Rows.Clear();
SyncMaster.SyncAgents.Clear();
}
foreach (string layerName in LayersToSync) {
Layer l = this.mobileCache.Layers[layerName];
if (l is FeatureLayer) {
var fl = (FeatureLayer)l;
FeatureLayerSyncAgent agent = new FeatureLayerSyncAgent(fl);
agent.ProgressChanged += FeatureLayerAgent_ProgressChanged;
if (Common.IsLayerValidForProjectFilter(agent)) {
agent.DownloadFilter = new QueryFilter(String.Format("ProjectID = {0}", Common.ProjectID));
}
agent.MapDocumentConnection = this.mobileServiceConnection1;
agent.SynchronizationDirection = SyncDirection.DownloadOnly;
SyncMaster.SyncAgents.Add(agent);
}
if (l is RasterLayer) {
var rl = (RasterLayer)l;
RasterLayerSyncAgent agent = new RasterLayerSyncAgent(rl);
agent.Extent = this.map1.GetExtent();
agent.MapDocumentConnection = this.mobileServiceConnection1;
SyncMaster.SyncAgents.Add(agent);
}
}
if (LayersToSync.Count() > 0) {
this.SyncResults.InitializeList();
}
}
public void SetupSyncAgents() {
var layers = new List<string>();
foreach (Layer l in this.mobileCache1.Layers) {
if (!Common.IsSurveyCoverageMode || (Common.IsSurveyCoverageMode && l.Name != Layers.ARCH_SurveyCoverage )) {
layers.Add(l.Name);
}
}
SetupSyncAgents(layers);
}
private void InitializeCache(MobileServiceConnection serviceConnection, MobileCache cache, string cacheStoragePath, CacheOpenMode mode) {
if (cache != null && cache.IsOpen) {
cache.Close();
}
//location of cache files
cache.StoragePath = cacheStoragePath;
try {
this.ConfigureServiceConnectionSecurity(serviceConnection);
switch (mode) {
case CacheOpenMode.Create:
ArchiveMapCache();
cache.DeleteCache();
serviceConnection.CreateCache(cache);
break;
case CacheOpenMode.CreateNew:
if (cache.CacheExists) {
throw new NotSupportedException("Values for CacheOpenMode must be Create, Open, or CreateOrOpen");
}
break;
case CacheOpenMode.OpenOrCreate:
if (!cache.CacheExists) {
serviceConnection.CreateCache(cache);
Log.Write(String.Format("Program was set to CacheOpenMode.OpenOrCreate but not cache file was found at {0}. Downloading a new cache.", this.CacheStoragePath));
}
break;
case CacheOpenMode.Open:
if (!cache.CacheExists) {
serviceConnection.CreateCache(cache);
Log.Write(String.Format("Program was set to CacheOpenMode.Open but no map cache was found at {0}. Downloading a new cache.", this.CacheStoragePath));
}
break;
}
} catch (WebException ex) {
}
}