81

I am getting the following error when I use web deploy from visual studio 2010. Web deployment task failed. (The type initializer for 'Microsoft.Web.Deployment.DeploymentManager' threw an exception.)

I suddenly started getting this error! I published my website many many times with all the same settings, but suddenly it started to give me this error. Could it be something in the website properties? I am using asp.net and have Windows 7 and publishing to Windows Server R2. Please help!

coder
  • 877
  • 2
  • 10
  • 11

11 Answers11

123

Okay, so I hit this problem and none of these answers worked for me. I boiled it down to a single line of code, namely:

var deploymentOptions = new Microsoft.Web.Deployment.DeploymentBaseOptions();

If you don't manually pass this to DeploymentManager it will internally instantiate this object. Even more interesting was that this code would run fine for me as the only line of a console app while it failed if I put it into a unit test (kicked off with vstest).

Here's the full body of the exception:

System.TypeInitializationException occurred
  HResult=-2146233036
  Message=The type initializer for 'Microsoft.Web.Deployment.DeploymentManager' threw an exception.
  Source=Microsoft.Web.Deployment
  TypeName=Microsoft.Web.Deployment.DeploymentManager
  StackTrace:
       at Microsoft.Web.Deployment.DeploymentManager.GetLinkExtensions()
       at Microsoft.Web.Deployment.DeploymentBaseOptions..ctor()
       at SimpleTest.Test.UnitTest1.TestMethod1() in f:\Source\Projects\SimpleTest.Test\UnitTest1.cs:line 12
  InnerException: System.TypeInitializationException
       HResult=-2146233036
       Message=The type initializer for 'Microsoft.Web.Deployment.BuiltInTypesCache' threw an exception.
       Source=Microsoft.Web.Deployment
       TypeName=Microsoft.Web.Deployment.BuiltInTypesCache
       StackTrace:
            at Microsoft.Web.Deployment.BuiltInTypesCache.get_Factories()
            at Microsoft.Web.Deployment.DeploymentProviderFactoryCollection.LoadFromRegistry()
            at Microsoft.Web.Deployment.DeploymentProviderFactoryCollection..ctor()
            at Microsoft.Web.Deployment.DeploymentManager.LoadDeploymentManagerSettings()
            at Microsoft.Web.Deployment.DeploymentManager..cctor()
       InnerException: Microsoft.Web.Deployment.DeploymentException
            HResult=-2146233088
            Message=The provider 'Microsoft.Data.Tools.Schema.MsDeploy.MsDeployProviderFactory' could not be loaded.
            Source=Microsoft.Web.Deployment
            StackTrace:
                 at Microsoft.Web.Deployment.DeploymentProviderFactory.Create(Type type)
                 at Microsoft.Web.Deployment.BuiltInTypesCache.InspectTypesForWebDeployAttributes(IEnumerable`1 types, String dllName)
                 at Microsoft.Web.Deployment.BuiltInTypesCache..cctor()
            InnerException: Microsoft.Web.Deployment.DeploymentException
                 HResult=-2146233088
                 Message=The type 'Microsoft.Data.Tools.Schema.MsDeploy.MsDeployProviderFactory' could not be loaded. The configuration settings may not be valid.
                 Source=Microsoft.Web.Deployment
                 StackTrace:
                      at Microsoft.Web.Deployment.ReflectionHelper.CreateInstance[T](Type type, Object[] constructorArguments)
                      at Microsoft.Web.Deployment.DeploymentProviderFactory.Create(Type type)
                 InnerException: System.TypeInitializationException
                      HResult=-2146233036
                      Message=The type initializer for 'Microsoft.Data.Tools.Schema.MsDeploy.MsDeployProviderBaseProviderFactory' threw an exception.
                      Source=mscorlib
                      TypeName=Microsoft.Data.Tools.Schema.MsDeploy.MsDeployProviderBaseProviderFactory
                      StackTrace:
                           at System.Runtime.Remoting.RemotingServices.AllocateUninitializedObject(RuntimeType objectType)
                           at System.Runtime.Remoting.Activation.ActivationServices.CreateInstance(RuntimeType serverType)
                           at System.Runtime.Remoting.Activation.ActivationServices.IsCurrentContextOK(RuntimeType serverType, Object[] props, Boolean bNewObj)
                           at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
                           at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
                           at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
                           at System.Activator.CreateInstance(Type type, Boolean nonPublic)
                           at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark& stackMark)
                           at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
                           at System.Activator.CreateInstance(Type type, Object[] args)
                           at Microsoft.Web.Deployment.ReflectionHelper.CreateInstance[T](Type type, Object[] constructorArguments)
                      InnerException: System.IO.FileNotFoundException
                           HResult=-2147024894
                           Message=Could not load file or assembly 'Microsoft.Data.Tools.Schema.Sql, Version=10.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
                           Source=Microsoft.Data.Tools.Schema.DbSqlPackage
                           FileName=Microsoft.Data.Tools.Schema.Sql, Version=10.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
                           FusionLog=""
                           StackTrace:
                                at Microsoft.Data.Tools.Schema.MsDeploy.MsDeployProviderBaseProviderFactory..cctor()
                           InnerException:

After talking to the team in Microsoft that owns this component I learned a simple solution:

Look for a key in the registry under the following paths that points the the problem assembly and delete it:

HKLM\Software\Microsoft\IIS Extensions\msdeploy\3\extensibility
HKLM\Software\Wow6432Node\Microsoft\IIS Extensions\msdeploy\3\extensibility

(After cleaning up the registry, remember to restart Visual Studio)

The problem registry key is installed by SQL.

NiceGuyAlberto
  • 402
  • 4
  • 6
Victor
  • 1,627
  • 2
  • 12
  • 16
  • 14
    This worked for me as well. I wish I could give you 1000 points for this. I was getting an exception on Associate Changesets and Workitem for Azure Continuous Deployments. `Could not load file or assembly 'Microsoft.Data.Tools.Schema.Sql, Version=10.3.0.0` I actually asked a question about it here: http://serverfault.com/questions/524848/msbuild-failing-on-build-looking-for-older-version-of-microsoft-data-tools-schem – Gabe Jul 23 '13 at 21:05
  • 2
    Exactly! Thanks @Victor. Interesting that recently I've uninstalled all SQL 2012 related stuff. But these registry keys persisted. – Vertigo Sep 02 '13 at 12:12
  • 2
    @Vertigo: Yesterday I also uninstalled lots of SQL Server 2012 stuff because I have SQL Server 2014 installed... didn't think this could break Web Deployment. :D In my case I reinstalled Web Deploy 3.5 and also deleted these 2 registry keys. Restarted VS 2013 and now it's working again. – Leniel Maccaferri Aug 14 '14 at 00:00
  • 6
    I had the same scenario as Leniel, issue after uninstalling SQL Server 2012. I removed the keys they restarted VS, and it worked. Did not need to reinstall Wed Deploy. – CodeGrue Sep 04 '14 at 16:55
  • 1
    This fixed IIS Import Application for me. Thanks a ton!! – Keith Hill Feb 08 '15 at 06:41
  • Those two Registry folders were empty on my Windows 8.1 machine. :/ – krillgar Feb 09 '15 at 23:48
  • Thanks, this also fixed my problem here. – John-Philip Jun 30 '15 at 13:37
  • Incredible! Thanks a lot. – Yet Another Code Maker Aug 03 '15 at 16:43
  • I can't access to the paths from my W7 machine. Anyone can help plz ? – ben Sep 10 '15 at 15:03
  • Thanks, had same problem after sql server 2014 install. – Gracie Sep 18 '15 at 09:43
  • It works.Thanks a lot.I have restarted the machine after `regedit`.Then only it worked. – Sampath Jun 14 '16 at 00:17
  • Just hit this same problem - deleting those reg keys then restart worked for me – wysinawyg Aug 04 '16 at 13:28
  • This fixed my problem. I needed to restart Visual Studio after I deleted those keys. Thanks! – johnnyRose Apr 12 '17 at 23:50
  • Yet another days. And I've faced the same problem again. But the solution still works. – Vertigo Mar 11 '23 at 22:30
60

For me, I restarted Visual Studio and rebuilt the project and I was able to publish again (I didn't see this answer suggested and it worked for me). Maybe this is your step one before trying other answers on this question.

alexk
  • 1,254
  • 1
  • 11
  • 16
26

I had the same problem but installing SQL 2012 and changing the registry didn't fix it. After reinstalling Web Deploy 3.5 on my development machine things got straightened out.

demoncodemonkey
  • 11,730
  • 10
  • 61
  • 103
Ryan
  • 4,602
  • 8
  • 37
  • 43
  • This worked really well. I had uninstalled SQL 2012 as well after installing 2014 since the last time it worked. I was unable to find any of those registry keys when looking. – krillgar Feb 10 '15 at 00:40
25

Just uninstall Microsoft dbsqlpackage provider. Go to "Programs and Features". It is no longer used.

Josh
  • 2,142
  • 2
  • 23
  • 20
code5
  • 4,434
  • 2
  • 31
  • 24
5

I re-installed Web Deployment 3.5 to make it work on windows 8.1. Couldn't find the files in the registry.

sindrem
  • 1,211
  • 5
  • 24
  • 45
2

I was able to resolve this error by reinstalling SQL Server. I reinstalled SQL 2012 Express, from MSDN, with this file name.

only 940 mb download. Seems to have repaired whatevrer I jacked up by all the manual uninstalls last week.

en_sql_server_2012_express_edition_with_tools_with_sp1_x64.exe

I hope that helps.

ScottCate
  • 2,365
  • 7
  • 21
  • 35
  • 1
    I also did some manual uninstalls of SQL Server related stuff and had the same problem. I ran the repair sequence of VS2012 and everything went back to normal. – AlexB Sep 19 '13 at 12:50
1

I seem to be suffering the same problem, but only when running locally on IIS Express (my IIS 8 instance runs this code fine).

When I track the exception down the stack (three inner exceptions). It appears that the actual exception is the following:

Could not load file or assembly 'Microsoft.Data.Tools.Schema.Sql, Version=10.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.":"Microsoft.Data.Tools.Schema.Sql, Version=10.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

The weird thing with this is that this DLL appears to reside @ C:\Program Files (x86)\Microsoft SQL Server\110\DAC\bin\Microsoft.Data.Tools.Utilities.dll but I actually have this DLL sitting there.

It is also strange this this is only happening whenever i try to initialise a new DeploymentBaseOptions. Before I do anything with it (so I am not making any SQL calls, and haven't even set any properties on it.

Thoughts?

Doug
  • 6,460
  • 5
  • 59
  • 83
  • 2
    There is a dependancy on SQL somewhere. My web deploy was working fine forever, and I just uninstalled a bunch of SQL stuff. Then this exact error started happening. – ScottCate Feb 10 '13 at 15:44
  • Look for a solution from @Victor below. I've also uninstalled all SQL 2012 stuff. Seems DAC injects itself into MSDeply. – Vertigo Sep 02 '13 at 12:15
1

I already had SSMS 2014 and this didn't seem to cause any issue with publishing in VS. The issue arose for me later after installing the SQL Server 2014 database engine.

The registry entries referred to by Victor were blank. Reinstalling VS2012 fixed the problem.

1

Doing a "repair" of my SQL Server installation fixed the problem for me.

vidalsasoon
  • 4,365
  • 1
  • 32
  • 40
1

Maybe you need to run aspnet_regiis at the visual studio command prompt.

Stephen__T
  • 2,004
  • 3
  • 25
  • 48
  • Yes, I believe you can run it locally and point it to the IIS you need. – Stephen__T Jun 15 '11 at 19:47
  • that didn't work. any other suggestions? the complete error is: C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(3588,5): Error : Web deployment task failed. (The type initializer for 'Microsoft.Web.Deployment.DeploymentManager' threw an exception.) – coder Jun 16 '11 at 09:36
  • This error comes before it even attempts to connect to the web hosting server, because invalid login credentials don't make a difference. So it must be something at my end. – coder Jun 16 '11 at 10:19
0

Reinstalling Web Deploy from "Package Manager Console" and restarting visual studio worked for me!!

NuGet\Install-Package Microsoft.Web.Deployment
Samra
  • 1,815
  • 4
  • 35
  • 71