Unable to activate Windows Store app: The App.exe process started, but the activation request failed with error ‘The app didn’t start.

Hi,
if you happen at least once to receive this unpleasant message:

“Unable to activate Windows Store app: The App.exe process started, but the activation request failed with error ‘The app didn’t start.

that not allows you to start the Store App, here the possible causes:

1) Download assemblies via Nuget
Nuget in the Windows Store Apps will try to add an app.config in the project, but Windows Store Apps don’t need App.Config.

Solution
Remove App.Config and Deploy App.

2) Change the Package Name in the manifest

Solution
Uninstall App from the Start Screen, delete bin/obj folder and files and then Deploy App.

3) In All other cases

Solution
Uninstall App from the Start Screen, delete bin/obj folder and files and then Deploy App.

Enjoy
Maurizio

Adding SettingsData support to ViewModel with MVVM Light in WinRT

In the previous Post, I have spoken about a solution for DialogMessaging service. Now I would you like propose another solution for read and write data from the LocalSettings or RoamingSettings using IOC design pattern and MVVM Light toolkit.

So, Let’s start with the definition of an Interface that allows the support to the Local/Remote Settings.

	
public interface ISettingsDataService
{
	T GetItem<T>(string container, string id);

	IEnumerable GetItems<T>(string container);

	void SetValue<T>(string container, string id, T data);

	IEnumerable GetEntities<T>(string container)
		where T: new()

	void SetEntity<T>(string conatiner, T entity)
		where T: new()		
}

Now we have to move to the implementation:

public class SettingsDataService: ISettingsDataService
{
	private ApplicationDataContainer settingsContainer;

	public SettingsStoreService(ApplicationDataContainer applicationDataContainer) 
	{
		this.settingsContainer = applicationDataContainer; 
	}	 

	public T GetItem<T>(string container, string id)
	{
		if (container == null)
			throw new ArgumentNullException("Container cannot be null.");

		if (id == null)
			throw new ArgumentNullException("Id cannot be null");

		ApplicationDataContainer dataContainer = 
				settingsContainer.CreateContainer(container, ApplicationDataCreateDisposition.Always);

		var value = dataContainer.Values.ContainsKey(id)? dataContainer.Values[id]: null;
		if (value == null) return default(T);
		return (T)value;
	}

	public IEnumerable GetItems<T>(string container) 
	{
		if (container == null)
			throw new ArgumentNullException("Container cannot be null");

		ApplicationDataContainer dataContainer = 
			settingsContainer.CreateContainer(container, ApplicationDataCreateDisposition.Always);

		var values = new List();
		foreach (var value in dataContainer.Values)
			values.Add((T)value.Value);
		return values;
	}

	public IEnumerable GetEntities<T>(string container) where T : new()
	{
		if (container == null) 
		throw new ArgumentNullException("Container cannot be null");

		ApplicationDataContainer dataContainer = 
		settingsContainer.CreateContainer(container, ApplicationDataCreateDisposition.Always);

		var values = new List();	 
		foreach (var compositeValue in dataContainer.Values)
		{
			var entity = CreateEntity((ApplicationDataCompositeValue)compositeValue.Value);
			values.Add(entity);
		}
		return values;	 
	}

	public void SetValue<T>(string container, string id, T value)
	{	 
		if (container == null)
			throw new ArgumentNullException("Container cannot be null");

		if (string.IsNullOrEmpty(id)) 
			throw new ArgumentNullException("Id cannot be null");

		if (value == null)
			throw new ArgumentNullException("Value cannot be null");

		ApplicationDataContainer dataContainer = 
			settingsContainer.CreateContainer(container, ApplicationDataCreateDisposition.Always);
		dataContainer.Values[id] = value;	 
	}

	public void SetEntity<T>(string container, string id, T value) where T : new()
	{
		if (container == null)	 
			throw new ArgumentNullException("Container cannot be null");

		if (string.IsNullOrEmpty(id)) 
			throw new ArgumentNullException("Id cannot be null");

		if (value == null)		 
			throw new ArgumentNullException("Value cannot be null");

		ApplicationDataContainer dataContainer = 
			settingsContainer.CreateContainer(container, ApplicationDataCreateDisposition.Always);

		ApplicationDataCompositeValue compositeValue = GetCompositeValue(value); 
		dataContainer.Values[id] = compositeValue;	 
	} 

	private T CreateEntity<T>(ApplicationDataCompositeValue compositeValue) 
		where T : new()
	{
		var entity = new T(); 
		if (entity != null) 
		{ 
			foreach (var keyValue in compositeValue)
				entity.GetType().GetRuntimeProperty(keyValue.Key).SetValue(entity, keyValue.Value);

		} 
		return entity;	 
	}

	private ApplicationDataCompositeValue GetCompositeValue(object entity)
	{
		var compositeValue = new ApplicationDataCompositeValue();
		var entitySerializable = entity.GetType()
									   .GetRuntimeProperties()
									   .Where(p => p.PropertyType.GetTypeInfo()
									   .IsSerializable
		foreach (var property in entitySerializable))
			compositeValue[property.Name] = entity.GetType().GetRuntimeProperty(property.Name).GetValue(entity);
		return compositeValue; 
	}  
}

And then, we need to register this service when the app starts.
So, define the following method in the ViewModelLocator class:

public class ViewModelLocator
{
	public ViewModelLocator()
	{
		 ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
		 if (!ViewModelBase.IsInDesignModeStatic)
		 { 
			Registers();
		 } 
	}

	public void Registers()
	{
		SimpleIoc.Default.Register(() => new SettingsDataService(ApplicationData.Current.LocalSettings));
	}
}

In the viewmodel, where we need the SettingsDataService we use dependency injection in this way:

public class MainViewModel: ViewModelBase
{
	public MainViewModel(ISettingsDataService settingsDataService)
	{
		//Get a simple value from the LocalStore using ISettingsDataService
		var title = settingsDataService.GetItem<string>("ContainerStoreApp", "TitleApp");

		//Set a simple Entity
		MyClass c = new MyClass();
		c.MyProperty = "MyValue";
		c.MyComplexProperty = "MyComplexProperty";

		settingsDataService.SetEntity<MyClass>("ContainerStoreApp", c);
	}
}

In this way we are able to interact with the SettingsData using IOC and MVVM Light.

Enjoy
Maurizio

Adding DialogMessaging support to ViewModel with MVVM Light in WinRT

In this post I would like to propose a simple solution for DialogMessaging on the UI using MVVM Light Toolkit.

The idea is to use the power of IOC pattern included in the MVVM Light Tookit available free from NuGet.

First of all we need an Interface that allows to define the support to DialogMessaging.
Here an example:

public interface IDialogMessageService
{
	Task ShowAsync(string title, string message);	

	Task ShowAsync(string title, string message, IEnumerable commands);
}

Now we have to move to the implementation:

public class DialogMessageService: IDialogMessageService
{
	public async Task ShowAsync(string title, string message)
	{
		await ShowAsync(title, message, null);
	}

	public async Task ShowAsync(string title, string message, IEnumerable commands)
	{
		var messageDialog = new MessageDialog(message, title);
		if(commands != null)
		{
			foreach(var command in commands)
				messageDialog.Commands(command);
		}
		await messageDialog.ShowAsync();
	}	
}

And then, we need to register this service when the app starts.

So, define the following method in the ViewModelLocator class:

public class ViewModelLocator
{
	public ViewModelLocator()
	{
	     ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
             if (!ViewModelBase.IsInDesignModeStatic)
             { 
		 Registers();
             } 
        }

	public void Registers()
	{
		SimpleIoc.Default.Register<IDialogMessageService, DialogMessageService>();
	}
}

In the viewmodel, where we need the DialogMessageService we use dependency injection in this way:

public class MainViewModel: ViewModelBase
{
	public ICommand ShowMessageCommand{ get; private set;}

	public MainViewModel(IDialogMessageService dialogMessageService)
	{		
		this.ShowMessageCommand = new RelayCommand( async() => 
		{
			await dialogMessageService.ShowAsync("Title", "Hello", null);	
		});
	}
}

And at the end we can use the communication from View - ViewModel with MVVM Design Pattern simply. 🙂

Enjoy
Maurizio

70-485 Advanced Windows Store App Development Using C#

Hi,
2 day ago, i have just passed exam 70-485 Advanced Windows Store Development Using C#, last step to archieve credit MCSD Windows Store Apps Using C#.

For this exam should have a minimum of experience on developing Windows-based applications, including a minimun of experience developing applications for a touch-enabled interface/platform.

Main topic arguments:

  • Experience designing and developing the Process Lifetime Management (PLM) for Windows Store apps
  • Experience managing and securing app data for a Windows Store solution
  • Experience planning and designing user interaction solutions based on requirements
  • Experience with the full development life cycle of Windows Store apps
  • Experience designing and developing asynchronous solutions
  • Experience creating apps that conform to the Windows Store app guidelines

The exam includes 45/46 questions between drap-drop, multiple, single response, my general opinion this exam is not easy, should be prepared for achievement goal.

See you ….
Maurizio

70-484 Essentials of Developing Windows Store Apps Using C#

Hi,
2 day ago, i have just passed exam 70-484 Essentials of Developing Windows Store Apps Using C#, second step to archieve credit MCSD Windows Store Apps Using C#.

For this exam should have a minimum of experience on developing Windows-based applications, including a minimun of experience on developing applications for a touch-enabled interface/platform.
Main topic arguments:

  • Experience designing and developing Windows Store apps that access local and remote data and services, including Windows Azure
  • Experience designing the various layers of an app for separation of concerns
  • Experience planning and designing user interaction solutions based on requirements
  • Experience designing and developing asynchronous solutions
  • Experience creating apps that conform to the Windows Store app guidelines

The exam includes 40 questions between drap-drop, multiple, single response.

Bye Bye
Maurizio