Friday, September 28, 2012

Call GetSalePrice from EPiServer scheduled job

Parts of the EPiServer Commerce API requires that you have an active HttpContext. This will make life hard when you try to call this methods from a scheduled job, one of these methods that require an HttpContext is the "Mediachase.Commerce.Website.Helpers.StoreHelper.GetSalePrice", it checks for a value in the users cookie and if none is found it will take a default value, but if the context does not exist it will just throw an null pointer exception and fail. To fix this I just added the following code to the start of my scheduled job,

if (HttpContext.Current == null)
{
 HttpContext.Current = new HttpContext(new HttpRequest("index.aspx", "http://tempuri.org/index.aspx", string.Empty), new HttpResponse(null));
}

Wednesday, September 19, 2012

Possible solution to build warning "The primary reference "..." could not be resolved because it has an indirect dependency" after installing .NET 4.5


After installing .NET framework 4.5 I started to experience build errors and warnings when building solutions containing projects targeting .NET 3.5 in Visual Studio 2010.

One of the warnings said:
The primary reference "Dropit.Extension, Version=4.1.0.142, Culture=neutral, PublicKeyToken=8fe83dea738b45b7, processorArchitecture=MSIL" could not be resolved because it has an indirect dependency on the framework assembly "System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" which could not be resolved in the currently targeted framework.

This warning isn’t specific for the primary ref assembly mentioned above, it could be any other assembly it seems. 

After playing around with the .csproj-file trying to take control over MSBuild I discovered this workaround:


  1. In VS, try to identify the referenced assembly or assemblies causing the warning and set the specific version to true in the properties pane.
  2. Unload the project that fails to build in Solution Explorer
  3. Right click the unavailable project and then Edit
  4.  Find the ItemGroup and Reference elements of the concerned assemblies, in this case
<ItemGroup>
  ...
  <Reference Include="Dropit.Extension, Version=4.1.0.142, Culture=neutral, PublicKeyToken=8fe83dea738b45b7, processorArchitecture=MSIL">
    <HintPath>..somepath\Dropit.Extension.dll</HintPath>
  </Reference>

and add the SpecificVersion element

<ItemGroup>
  ...
  <Reference Include="Dropit.Extension, Version=4.1.0.142, Culture=neutral, PublicKeyToken=8fe83dea738b45b7, processorArchitecture=MSIL">
    <HintPath>..somepath\Dropit.Extension.dll</HintPath>
    <SpecificVersion>True</SpecificVersion>
  </Reference>

6.       Save and build - and it builds!


Tuesday, September 11, 2012

Access TFS 2010 in Visual Studio 2008

For anyone working with Visual Studio 2008 and want to connect to a TFS 2010 server here is a quick guide to getting it to work,


  1. Install Visual Studio 2008
  2. Install Visual Studio 2008 SP1
  3. Install Team Explorer 2008
  4. Install Visual Studio Team System 2008 Service Pack 1 Forward Compatibility Update for Team Foundation Server 2010
  5. Reinstall Visual Studio 2008 SP1
  6. Done!

To access a collection other then the default you have to get the url for that collection this can be done by checking the properties of the collection in Visual Studio 2010, there will be a url field there.