I am using following code to perform generic delete by name of entity and key id.
I have used this code in SharePoint 2010 and worked fine, but not working on SharePoint Foundation 2013.
This solution is developed and tested on standalone SharePoint 2013 server but never had issue like this. Project upgrade to 2013 was successful in Visual studio 2013 and works without any issue. I had these kind of errors before because of Sandbox assembly somehow get hooked in VS project but you can delete in post build events and it works fine
I have looked everywhere but this dll has no referrence, SharePoint Foundation 2013 is installed on "Windows Server 2012 r2" with SP1 and Dec 2013 CUs.
Any help will be much appreciated...
using (var ctx = new ProjectNameObjects()) { var name = typeof(T).Name; var container = ctx.MetadataWorkspace.GetEntityContainer(ctx.DefaultContainerName, DataSpace.CSpace); string entitySetName = (from meta in container.BaseEntitySets where meta.ElementType.Name == name select meta.Name).First();
Object entity = null;
IEnumerable<KeyValuePair<string, object>> entityKeyValues = new KeyValuePair<string, object>[] {
new KeyValuePair(idFieldName, entityId) };
var key = new EntityKey(string.Format("ProjectNameObjects.{0}", entitySetName), entityKeyValues);
if (ctx.TryGetObjectByKey(key, out entity))
{
ctx.DeleteObject(entity);
ctx.SaveChanges();
return true;
}
}
Loader Exception: System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information. at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module) at System.Reflection.RuntimeModule.GetTypes() at System.Reflection.Assembly.GetTypes() at System.Data.Metadata.Edm.ObjectItemConventionAssemblyLoader.LoadTypesFromAssembly() at System.Data.Metadata.Edm.ObjectItemAssemblyLoader.Load() at System.Data.Metadata.Edm.AssemblyCache.LoadAssembly(Assembly assembly, Boolean loadReferencedAssemblies, KnownAssembliesSet knownAssemblies, EdmItemCollection edmItemCollection, Action1 logLoadMessage, Object& loaderCookie, Dictionary
2& typesInLoading, List1& errors) at System.Data.Metadata.Edm.ObjectItemCollection.LoadAssemblyFromCache(ObjectItemCollection objectItemCollection, Assembly assembly, Boolean loadReferencedAssemblies, EdmItemCollection edmItemCollection, Action
1 logLoadMessage) at System.Data.Metadata.Edm.ObjectItemCollection.ImplicitLoadAllReferencedAssemblies(Assembly assembly, EdmItemCollection edmItemCollection) at System.Data.Metadata.Edm.MetadataWorkspace.ImplicitLoadAssemblyForType(Type type, Assembly callingAssembly) at System.Data.Metadata.Edm.MetadataWorkspace.ImplicitLoadFromEntityType(EntityType type, Assembly callingAssembly) at System.Data.Objects.ObjectContext.TryGetObjectByKey(EntityKey key, Object& value) at ProjectName.UI.Phase2.Common.DAL.Delete[T](Object entityId, String idFieldName, String msgPrefix, ProjectNameLabel lbl) Could not load file or assembly 'Microsoft.Office.Server.UserProfiles.Synchronization, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies.