Thursday, March 18, 2010

Error when running tests: Unable to load one or more of the requested types

Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information..

1. Clean the solution
2. Close Visual studio
3. Delete all the bin en obj folders
4. Try again

Monday, March 15, 2010

Sharepoint configuration wizard fails after sysprep

If you sysprep a machine on which you installed sharepoint and ran the configuration wizard and you try to run it again you get the following error (after you ran the sp_dopserver and sp_addserver stored procedures):

03/05/2010 17:16:12 8 ERR Exception: System.ArgumentNullException: Value cannot be null.
Parameter name: password
at Microsoft.SharePoint.Administration.SPProcessIdentity.Update()
at Microsoft.SharePoint.Administration.SPApplicationPool.Update()
at Microsoft.SharePoint.Administration.SPWebApplication.CreateDefaultInstance(SPWebService service, Guid id, String applicationPoolId, IdentityType identityType, String applicationPoolUsername, SecureString applicationPoolPassword, String iisServerComment, Boolean secureSocketsLayer, String iisHostHeader, Int32 iisPort, Boolean iisAllowAnonymous, DirectoryInfo iisRootDirectory, Uri defaultZoneUri, Boolean iisEnsureNTLM, Boolean createDatabase, String databaseServer, String databaseName, String databaseUsername, String databasePassword, SPSearchServiceInstance searchServiceInstance, Boolean isPaired, Boolean autoActivateFeatures)
at Microsoft.SharePoint.Administration.SPAdministrationWebApplication.CreateDefaultInstance(SqlConnectionStringBuilder administrationContentDatabase, SPWebService adminService, IdentityType identityType, String farmUser, SecureString farmPassword)
at Microsoft.SharePoint.Administration.SPFarm.CreateAdministrationWebService(SqlConnectionStringBuilder administrationContentDatabase, IdentityType identityType, String farmUser, SecureString farmPassword)
at Microsoft.SharePoint.Administration.SPFarm.CreateBasicServices(SqlConnectionStringBuilder administrationContentDatabase, IdentityType identityType, String farmUser, SecureString farmPassword)
at Microsoft.SharePoint.Administration.SPFarm.Create(SqlConnectionStringBuilder configurationDatabase, SqlConnectionStringBuilder administrationContentDatabase, IdentityType identityType, String farmUser, SecureString farmPassword)
at Microsoft.SharePoint.Administration.SPFarm.Create(SqlConnectionStringBuilder configurationDatabase, SqlConnectionStringBuilder administrationContentDatabase, String farmUser, SecureString farmPassword)
at Microsoft.SharePoint.PostSetupConfiguration.ConfigurationDatabaseTask.CreateOrConnectConfigDb()
at Microsoft.SharePoint.PostSetupConfiguration.ConfigurationDatabaseTask.Run()
at Microsoft.SharePoint.PostSetupConfiguration.TaskThread.ExecuteTask()


This is related to the fact that there are allready Application pools created. if you delete the earlier created applicaiton pools and websites you should be able to run the wizard without errors.

Thursday, March 11, 2010

Ax Business Connector .NET Unable to log on to Microsoft Dynamics AX.

LogonFailedException: Unable to log on to Microsoft Dynamics AX.

Method signature
public void LogonAs(
string user,
string domain,
NetworkCredential bcProxyCredentials,
string company,
string language,
string objectServer,
string configuration
);

When using the logon as method of the Business Connector .NET you face a lot off issues. After searching on the net I found that almost everyone forces the bcProxyCredentials but actually this not the way it is supposed to be used.

but here the MSDN documentation contains an error:

bcProxyCredentials
Credentials of the Business Connector Proxy user used to authenticate and enable the use of LogonAs.

You can create a NetworkCredential object with the following code:

System.Net.NetworkCredential creds = new System.Net.NetworkCredential(
ADUserName, ADUserPassword, ADDomain)The NetworkCredential parameters must match the Business Connector Proxy user set in the Business Connector Proxy dialog box: To verify your settings go to the Administration pane, click Setup, click Security, and then select BusinessConnectorProxy.

the part in bold is wrong. If you open the client application got the Administration pane > Security > System Service Accounts and there you can set the Business Connector Proxy accound and you can perform the LogonAs method to imperonate another user.

From the installation guide:

Some components require that the .NET Business Connector be configured to connect to Microsoft Dynamics AX with a proxy account. The use of a proxy enables the .NET Business Connector to connect on behalf of Microsoft Dynamics AX users when authenticating with an AOS instance.

Next you should be able to use the LogonAs method to logon as any valid Axapta user

Edit: if you want to use the user that is running the process as the proxy account pass null to the LogonAs method for the bcProxyCredentials parameter

Friday, March 05, 2010

Booting from a VHD

With windows 7 and windows 2008 it is possible to boot from a hyper-v virtual disk

I usually set up an image with hyper-v and sysprep it then follow these steps to add it to your bootloader

C:\Windows\system32>bcdedit /copy {current} /d "JELLE-DEV"
The entry was successfully copied to {8208ac27-0bca-11df-8dbb-a0ef01535d7b}.

Copy the GUID that is

bcdedit /set {guid} device vhd=[locate]\image.vhd
bcdedit /set {guid} osdevice vhd=[locate]\image.vhd

Wednesday, March 03, 2010

Webcam access in Silverlight 4

Code snippet to show webcam capture in silverlight 4


CaptureDeviceConfiguration.RequestDeviceAccess();
CaptureSource _capture = new CaptureSource();
_capture.VideoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice();
_capture.Start();
VideoBrush videoBrush = new VideoBrush();
videoBrush.Stretch = Stretch.Uniform;
videoBrush.SetSource(_capture);
rectVideo.Fill = videoBrush;
rectVideo.UpdateLayout();


Getting the output and resizing it to have a format of a picture that can be used in a profile


_capture.AsyncCaptureImage(img =>
{
_capture.Stop();
TranslateTransform tt = new TranslateTransform();

tt.Y = -73.5;
tt.X = -125;
WriteableBitmap bitmap = new WriteableBitmap(70, 93);

bitmap.Render(rectVideo, tt);
bitmap.Invalidate();
frameImage.Source = bitmap;
_capture.Start();
});

Friday, February 26, 2010

MVP in asp .net / sharepoint

The view interface



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SharpSoutions.MVP
{
public interface IView
{
Model DataSource { get; set; }
void DataBind();
void UpdateModel();

event EventHandler Saved;
}
}




using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SharpSoutions.MVP.Domain;

namespace SharpSoutions.MVP
{
[Serializable]
public class Model
{
public Person NewPerson { get; set; }

public Title[] Titles { get; set; }
}
}


The presenter



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SharpSoutions.MVP.Domain;
using System.Diagnostics;

namespace SharpSoutions.MVP
{
public class Presenter
{
private Data.IRepository<Title> titleRepository;
private Data.IRepository<Person> personRepository;


public Presenter(Data.IRepository<Title> titleRepository, Data.IRepository<Person> personRepository)
{
Trace.TraceInformation("Begin Presenter.Ctor");
this.titleRepository = titleRepository;
this.personRepository = personRepository;

this.Model = new Model();
this.Model.NewPerson = new Person();
Trace.TraceInformation("End Presenter.Ctor");
}

public Model Model { get; set; }

public IView View { get; set; }

/// <summary>
/// Init populates the "static" data
/// These are the data that is shown in dropdown boxes etc
/// </summary>
/// <param name="mockView"></param>
public void Init(IView view)
{
Trace.TraceInformation("Begin Presenter.Init");
AttachView(view);
this.View.DataSource = this.Model;

this.Model.Titles = this.titleRepository.Query();

this.View.DataBind();
Trace.TraceInformation("End Presenter.Init");
}

public void AttachView(IView view) {
this.View = view;
this.View.Saved += new EventHandler(View_Saved);

}

void View_Saved(object sender, EventArgs e)
{
System.Diagnostics.Trace.TraceInformation("Begin Presenter.View_Saved");
this.Save();
System.Diagnostics.Trace.TraceInformation("End Presenter.View_Saved");
}

public void Save()
{
System.Diagnostics.Trace.TraceInformation("Begin Presenter.Save");
this.View.UpdateModel();

personRepository.Update(this.Model.NewPerson);
System.Diagnostics.Trace.TraceInformation("End Presenter.Save");
}
}
}


The View implementation



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SharpSoutions.MVP.Domain;

namespace SharpSoutions.MVP.Web
{
public partial class View : System.Web.UI.UserControl, IView
{


public Model DataSource{
get {
if (ViewState["d"] != null) {
return (Model)ViewState["d"];
}

return null;
}

set {
ViewState["d"] = value;
}
}

public override void DataBind()
{
System.Diagnostics.Trace.TraceInformation("Begin View.Databind");
base.DataBind();

TitleDropDown.DataSource = this.DataSource.Titles;
if (this.DataSource.NewPerson.Title != null) {
TitleDropDown.SelectedValue = this.DataSource.NewPerson.Title.Id.ToString();
}

TitleDropDown.DataTextField = "Name";
TitleDropDown.DataValueField = "Id";
TitleDropDown.DataBind();

nameTextbox.Text = this.DataSource.NewPerson.Name;
System.Diagnostics.Trace.TraceInformation("End View.Databind");
}


public void UpdateModel()
{
System.Diagnostics.Trace.TraceInformation("Begin View.UpdateModel");
this.DataSource.NewPerson.Name = nameTextbox.Text;
ListItem selectedTitle = TitleDropDown.SelectedItem;
this.DataSource.NewPerson.Title = new Title { Id = int.Parse(selectedTitle.Value), Name = selectedTitle.Text };
System.Diagnostics.Trace.TraceInformation("End View.UpdateModel");
}

public event EventHandler Committed;

protected void SaveButton_Click(object sender, EventArgs e)
{
System.Diagnostics.Trace.TraceInformation("Begin View.SaveButton_Click");

if (this.Saved != null) {
this.Saved(this, EventArgs.Empty);
}
System.Diagnostics.Trace.TraceInformation("End View.SaveButton_Click");
}


public event EventHandler Saved;
}
}

Sunday, January 31, 2010

Windows 7 RDP with blank password

I have a windows 7 HTPC setup atr home that is not part of my domain (in orderr if it reboots it reboots all by its self and dont ask for a password or ALT+CTRL+DELETE

but I wanted to work on it with RDP. But when I connected I gotr the following error:
"Logon failure: user account restriction. Possible reasons are blank passwords not allowed, logon hour restrictions, or a policy restriction has been enforced.". Even

Solution:
run secpol.msc /s and then under Security Settings -> Local Policies -> Security Options set the Accounts: Limit local account use of blank passwords to console logon only to disabled

Tuesday, January 19, 2010

Developer Interview question samples

FizzBuzz example.

A fizzbuzz is a small code sample/program that can be given to a developer to test his skills and knowledge about certain subjects


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1 {
public class ClassA {
public override string ToString() {
return "Hello from class A";
}
}

public class ClassB : ClassA {
public override string ToString() {
return "Hello from class B";
}
}

public class ClassC : ClassB {
public override string ToString() {
return "Hello from class C";
}
}

class Program {
static void Main(string[] args) {

ClassA first = new ClassC();
ClassC second = new ClassC();
ClassB third = (ClassB)second;
ClassA fourth = (ClassA)third;
object fifth = (object)fourth;

Console.WriteLine("1: " + first.ToString());
Console.WriteLine("2: " + second.ToString());
Console.WriteLine("3: " + third.ToString());
Console.WriteLine("4: " + fourth.ToString());
Console.WriteLine("5: " + fifth.ToString());
Console.ReadLine();
}


}
}

Thursday, December 17, 2009

Heading to 2010

Soon we will be in 2010... and microsoft gave us some early new years presents...

Currently playing around with:
  • Team Foundation Server 2010
  • Visual Studio 2010
  • Sharepoint 2010
  • Office 2010

All looks quite neat and some really cool features have been implemented... Top 5 things i like...
- Linked workitems in TFS
- Improved reporting in TFS
- Support for TDD in VSTS
- Improved support for sharepoint development in VSTS
- BCS in sharepoint 2010

Friday, September 11, 2009

Is code coverage usefull for measuring software quality?

There is a lot of debate going on how much percentage should be attained. But first however is code coverage a good measurement or quality? In my personal opinion it is very usefull if an historical trend is kept. if coverage drops over time this migt be an indicator of issues tha are arising somewhere else... not enough time, quick and dirty hacks,...

But how much is enough? this like almost everything in software development is offcourse it depends. I think it largely depends on the type of application you are building, if it is ver largely dependant on workflows and long running processes the significance is going to be less then when you are doing a lot of calculations. And offcourse code coverage does not cover 1 thing which is quite important and usually the root of all evil: missing requirements :)