SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When i try to add a masterpage to a web application using the following code :

$MasterPage = "C:\test.master"
$MasterPageName = [System.IO.Path]::GetFileName($masterpage);
$SpWebApp = Get-SpWebApplication $Url
$Spsite = $spWebApp.sites[0]
$web = $spSite.OpenWeb();

#Check if the page is already there. 
$MasterPagelist = ($web).Lists |? {$_.Title -eq "Galerie met basispagina's"}
$item = $MasterPagelist.items |? {$_.Name -eq $MasterPageName}
$BaseMasterItem = $MasterPagelist.items |? {$_.Name -eq $BaseMasterPageName}

if($item -ne $null)
    Delete-MasterPage $MasterPageName $spSite

$MasterPagelist.RootFolder.Files.Add($MasterPageName, [System.IO.File]::ReadAllBytes($MasterPage)) | out-null; 

i get the following error:

Exception calling "Add" with "2" argument(s): ""
At line:1 char:37
+ $MasterPagelist.RootFolder.Files.Add <<<< ("test", $MasterPageBytes)
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

The weird thing is that the error does not actually contain any usefull information. On my development farm this code works just fine, on my production farm it does not.

Any ideas on what could cause this behaviour?

share|improve this question
up vote 0 down vote accepted

It turns out that this error is being caused by Microsoft Forefront Security, when I go to Central admin -> Security -> Manage antivirus settings, and from there I turn of the virus scan on uploaded documents this error no longer occurs.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.