Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
393 views
in Technique[技术] by (71.8m points)

c# - Web deployment task failed. (The type initializer for 'Microsoft.Web.Deployment.DeploymentManager' threw an exception.)

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:SourceProjectsSimpleTest.TestUnitTest1.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:

HKLMSoftwareMicrosoftIIS Extensionsmsdeploy3extensibility
HKLMSoftwareWow6432NodeMicrosoftIIS Extensionsmsdeploy3extensibility

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

The problem registry key is installed by SQL.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...