XamlParseException when debugging WPF application with Visual Studio 2015 - wpf

I'm working on a WPF application I used to debug with VS 2012.
Since I switched to Visual Studio 2015, I don't manage to debug it any more. At runtime I get System.Windows.Markup.XamlParseException and the application crashes.
To be noted that the compiled executable runs correctly when launched by double-clicking on its icon. I can even debug it in VS 2015 by attaching the process after it's been launched.
In my application I make use of xceed.wpf.toolkit.
The exception is:
System.Windows.Markup.XamlParseException occurred
HResult=-2146233087
LineNumber=58
LinePosition=15
Message='Initialization of 'Xceed.Wpf.Toolkit.BusyIndicator' threw an exception.' Line number '58' and line position '15'.
Source=PresentationFramework
StackTrace:
at System.Windows.Markup.XamlReader.RewrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri)
at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
at [...].InitializeComponent()
InnerException:
HResult=-2146233088
LineNumber=0
LinePosition=0
Message=Initialization of 'Xceed.Wpf.Toolkit.Core.VersionResourceDictionary' threw an exception.
Source=System.Xaml
StackTrace:
at MS.Internal.Xaml.Runtime.ClrObjectRuntime.InitializationGuard(XamlType xamlType, Object obj, Boolean begin)
at System.Xaml.XamlObjectWriter.Logic_EndInit(ObjectWriterContext ctx)
at System.Xaml.XamlObjectWriter.WriteEndObject()
at System.Xaml.XamlServices.Transform(XamlReader xamlReader, XamlWriter xamlWriter, Boolean closeWriter)
at System.Windows.SystemResources.ResourceDictionaries.LoadDictionary(Assembly assembly, String assemblyName, String resourceName, Boolean isTraceEnabled)
at System.Windows.SystemResources.ResourceDictionaries.LoadThemedDictionary(Boolean isTraceEnabled)
at System.Windows.SystemResources.FindDictionaryResource(Object key, Type typeKey, ResourceKey resourceKey, Boolean isTraceEnabled, Boolean allowDeferredResourceReference, Boolean mustReturnDeferredResourceReference, Boolean& canCache)
at System.Windows.SystemResources.FindResourceInternal(Object key, Boolean allowDeferredResourceReference, Boolean mustReturnDeferredResourceReference)
at System.Windows.StyleHelper.GetThemeStyle(FrameworkElement fe, FrameworkContentElement fce)
at System.Windows.FrameworkElement.UpdateThemeStyleProperty()
at System.Windows.FrameworkElement.OnInitialized(EventArgs e)
at System.Windows.FrameworkElement.TryFireInitialized()
at MS.Internal.Xaml.Runtime.ClrObjectRuntime.InitializationGuard(XamlType xamlType, Object obj, Boolean begin)
InnerException:
HResult=-2146232800
Message=Cannot locate resource 'xceed.wpf.toolkit;v2.1.0.0;themes/xceed.wpf.toolkit;v2.1.0.0;component/themes/aero/brushes_normalcolor.xaml'.
Source=PresentationFramework
StackTrace:
at MS.Internal.AppModel.ResourcePart.GetStreamCore(FileMode mode, FileAccess access)
at System.IO.Packaging.PackagePart.GetStream(FileMode mode, FileAccess access)
at System.IO.Packaging.PackWebResponse.CachedResponse.GetResponseStream()
at System.IO.Packaging.PackWebResponse.get_ContentType()
at MS.Internal.WpfWebRequestHelper.GetContentType(WebResponse response)
at MS.Internal.WpfWebRequestHelper.GetResponseStream(WebRequest request, ContentType& contentType)
at System.Windows.ResourceDictionary.set_Source(Uri value)
at Xceed.Wpf.Toolkit.Core.VersionResourceDictionary.System.ComponentModel.ISupportInitialize.EndInit()
at MS.Internal.Xaml.Runtime.ClrObjectRuntime.InitializationGuard(XamlType xamlType, Object obj, Boolean begin)
InnerException:
Note also that the involved component, Xceed.Wpf.Toolkit.dll (in the correct version, v2.1.0.0), IS present in the output directory, just close to the application's compiled executable.
Any suggestion to make the application to work using the VS 2015 integrated debugger?
Thanks!

I disabled the
Debugging | General | Enable UI Debugging Tools for XAML
option and everything started working again.

You may want to check this
And use the pack:... syntax.
Turns out there's an issue in the Toolkit that makes things go wrong only with VS2015 but not with previous versions.
Still have to understand the differences between the latest and previous verions of VS but at least this patch works.

Related

Hangfire Recurring Jobs Break

I've got a HangFire setup in a .NET Core app. I've got several recurring jobs that are set to run every 15 minutes. In the Set table, when the scheduling is working correctly, you can see the next run time in Epoch format:
However, seemingly at random, the scheduling seems to die, looking more like this instead:
As per #Satpal's suggestion, I connected the dashboard and that has shed some more light on the situation.
System.TypeLoadException
Could not load type 'X.API.Controllers.YController' from assembly 'X.API, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
System.TypeLoadException: Could not load type 'X.API.Controllers.YController' from assembly 'X.API, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
at System.Reflection.RuntimeAssembly.GetType(QCallAssembly assembly, String name, Boolean throwOnError, Boolean ignoreCase, ObjectHandleOnStack type, ObjectHandleOnStack keepAlive, ObjectHandleOnStack assemblyLoadContext)
at System.Reflection.RuntimeAssembly.GetType(String name, Boolean throwOnError, Boolean ignoreCase)
at Hangfire.Common.TypeHelper.TypeResolver(Assembly assembly, String typeName, Boolean ignoreCase)
at System.TypeNameParser.ResolveType(Assembly assembly, String[] names, Func`4 typeResolver, Boolean throwOnError, Boolean ignoreCase, StackCrawlMark& stackMark)
at System.TypeNameParser.ConstructType(Func`2 assemblyResolver, Func`4 typeResolver, Boolean throwOnError, Boolean ignoreCase, StackCrawlMark& stackMark)
at System.TypeNameParser.GetType(String typeName, Func`2 assemblyResolver, Func`4 typeResolver, Boolean throwOnError, Boolean ignoreCase, StackCrawlMark& stackMark)
at System.Type.GetType(String typeName, Func`2 assemblyResolver, Func`4 typeResolver, Boolean throwOnError)
at Hangfire.Common.TypeHelper.DefaultTypeResolver(String typeName)
at Hangfire.Storage.InvocationData.DeserializeJob()
I know that the method being called by the recurring job is available and working currently, as manually rescheduling one of the failed jobs has worked as expected. My suspicion is the methods are unavailable when deploying updates - the period in which the app service is restarting is maybe enough for the jobs to fail, and die. I believe this is supported by a section I found in Hangfire's documentation, where it notes that:
background processing will be stopped after 10 retry attempts with increasing delay modifier
Two questions that I have regarding this are:
What is the best way to be notified of job failure? A quick google seems to suggest adding logging to Hangfire and using an error log event to trigger an email? Is there a better way?
Is there a way to automatically retrigger recurring jobs that've been stopped due to job failure?
Thanks!

Azure AD Connect installation - System.Security.SecurityException: Requested registry access is not allowed

I had to reinstall Azure AD Connect after server formatting and I get the following error, using Custom settings:
[ERROR] A terminating unhandled exception occurred.
Exception Data (Raw): System.AggregateException: One or more errors occurred. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Security.SecurityException: Requested registry access is not allowed.
at System.ThrowHelper.ThrowSecurityException(ExceptionResource resource)
at Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable)
at Microsoft.Identity.Health.Common.FileUploader.GetHealthAgentInstallPath()
at Microsoft.Identity.Health.Common.FileUploader..ctor(UploadSourcePolicy agent, Action`1 logLine)
at Microsoft.Online.Deployment.Types.Utility.AutoUpgradeEligibilityProvider..ctor()
--- End of inner exception stack trace ---
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.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
at Microsoft.Online.Deployment.Framework.ProviderRegistry.CreateInstance[TProvider]()
at Microsoft.Online.Deployment.OneADWizard.UI.WizardPages.PerformConfigurationPageViewModel.ExecuteAutoUpgradeCheck()
at Microsoft.Online.Deployment.OneADWizard.UI.WizardPages.PerformConfigurationPageViewModel.BackgroundInitialize(Object obj)
at System.Threading.Tasks.Task.Execute()
--- End of inner exception stack trace ---
---> (Inner Exception #0) System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Security.SecurityException: Requested registry access is not allowed.
at System.ThrowHelper.ThrowSecurityException(ExceptionResource resource)
at Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable)
at Microsoft.Identity.Health.Common.FileUploader.GetHealthAgentInstallPath()
at Microsoft.Identity.Health.Common.FileUploader..ctor(UploadSourcePolicy agent, Action`1 logLine)
at Microsoft.Online.Deployment.Types.Utility.AutoUpgradeEligibilityProvider..ctor()
--- End of inner exception stack trace ---
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.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
at Microsoft.Online.Deployment.Framework.ProviderRegistry.CreateInstance[TProvider]()
at Microsoft.Online.Deployment.OneADWizard.UI.WizardPages.PerformConfigurationPageViewModel.ExecuteAutoUpgradeCheck()
at Microsoft.Online.Deployment.OneADWizard.UI.WizardPages.PerformConfigurationPageViewModel.BackgroundInitialize(Object obj)
at System.Threading.Tasks.Task.Execute()<---
Do you have any idea about the origin of the problem?
Thank you.
Bertrand
Found the answer here and here
That's about the registry key to give permission to:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ADHealthAgent\Sync
Make sure you are logged into the VM as the tenant cloud administrator and also ensure that you explicitly run Powershell as an administrator if you are installing through Powershell. Also, check that you are installing the latest version of AAD Connect.
The Admin account for the server needs to have registry access privileges. In your system settings on the VM make sure to add your account as an admin.
See also these troubleshooting steps for this error.

Could not load file or assembly 'CMS.OutputFilter' or one of its dependencies opening index.html in browser from VS2013

This problem occurs when my source files are on my E drive, but not when they are in my C: MyDocuments folder.
I am working through Deborah Kurata's AngulaJS Line of Business Applications course on Pluralsight.
I have the following Index.html open in VS2013
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8"/>
<title>Acme Product Management</title>
<script src="js/angular.js"></script>
</head>
<body ng-app>
</body>
</html>
When I right click the code and select
view in browser (Chrome)
I get the following error
This seems to relate to Kentico, which I do have installed.
How do I fix it?
Server Error in '/' Application.
Could not load file or assembly 'CMS.OutputFilter' or one of its dependencies. The system cannot find the file specified.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IO.FileNotFoundException: Could not load file or assembly 'CMS.OutputFilter' or one of its dependencies. The system cannot find the file specified.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Assembly Load Trace: The following information can be helpful to determine why the assembly 'CMS.OutputFilter' could not be loaded.
WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
Stack Trace:
[FileNotFoundException: Could not load file or assembly 'CMS.OutputFilter' or one of its dependencies. The system cannot find the file specified.]
System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type) +0
System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName) +70
System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark) +39
System.Type.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase) +37
System.Web.Compilation.BuildManager.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase) +65
System.Web.Configuration.ConfigUtil.GetType(String typeName, String propertyName, ConfigurationElement configElement, XmlNode node, Boolean checkAptcaBit, Boolean ignoreCase) +38
[ConfigurationErrorsException: Could not load file or assembly 'CMS.OutputFilter' or one of its dependencies. The system cannot find the file specified.]
System.Web.Configuration.ConfigUtil.GetType(String typeName, String propertyName, ConfigurationElement configElement, XmlNode node, Boolean checkAptcaBit, Boolean ignoreCase) +348
System.Web.Configuration.ConfigUtil.GetType(String typeName, String propertyName, ConfigurationElement configElement, Boolean checkAptcaBit) +19
System.Web.Configuration.Common.ModulesEntry.SecureGetType(String typeName, String propertyName, ConfigurationElement configElement) +39
System.Web.Configuration.Common.ModulesEntry..ctor(String name, String typeName, String propertyName, ConfigurationElement configElement) +42
System.Web.HttpApplication.BuildIntegratedModuleCollection(List`1 moduleList) +158
System.Web.HttpApplication.GetModuleCollection(IntPtr appContext) +950
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +82
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +336
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296
[HttpException (0x80004005): Could not load file or assembly 'CMS.OutputFilter' or one of its dependencies. The system cannot find the file specified.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9931916
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34249
Web.config files are like CSS files, they inherit one another. So if your AngularJS website is an application below your main Kentico site within IIS, it's inheriting those values in the web.config file of the Kentico site. In the web.config file of the AngularJS site, you need to add
<remove name="XHtmlModule"/>
In the <system.webServer><modules> node. This will tell your AngularJS project to not inherit that module.

DNN exception on Site Settings or Host Settings pages "Could not load file or assembly 'protobuf-net"

I upgraded my DNN from version 7.0.0 to 7.1.1. After that I'm getting an exception every time that I enter page Site Settings or Host Settings of DNN in my site. The exception is:
Could not load file or assembly 'protobuf-net, Version=2.0.0.447, Culture=neutral, PublicKeyToken=257b51d87d2e4d67' or one of its dependencies. The system cannot find the file specified.
Here is the full Inner Exception:
DotNetNuke.Services.Exceptions.PageLoadException: Could not load file or assembly 'protobuf-net, Version=2.0.0.447, Culture=neutral, PublicKeyToken=257b51d87d2e4d67' or one of its dependencies. The system cannot find the file specified.
---> System.IO.FileNotFoundException: Could not load file or assembly 'protobuf-net, Version=2.0.0.447, Culture=neutral, PublicKeyToken=257b51d87d2e4d67' or one of its dependencies. The system cannot find the file specified.
at System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type)
at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
at System.ModuleHandle.ResolveTypeHandle(Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg)
at System.Reflection.CustomAttribute.IsCustomAttributeDefined(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, RuntimeType attributeFilterType, Boolean mustBeInheritable)
at System.Reflection.CustomAttribute.IsDefined(RuntimeType type, RuntimeType caType, Boolean inherit)
at System.ComponentModel.Composition.AttributedModel.AttributedModelDiscovery.CreatePartDefinitionIfDiscoverable(Type type, ICompositionElement origin)
at System.ComponentModel.Composition.Hosting.TypeCatalog.get_PartsInternal()
at DotNetNuke.ExtensionPoints.SafeDirectoryCatalog..ctor(String directory)
at DotNetNuke.ExtensionPoints.ExtensionPointManager.get_MefCompositionContainer()
at DotNetNuke.ExtensionPoints.ExtensionPointManager.ComposeParts(Object[] attributeParts)
at DotNetNuke.ExtensionPoints.EditPagePanelExtensionControl.OnInit(EventArgs e)
at System.Web.UI.Control.InitRecursive(Control namingContainer)
at System.Web.UI.Control.InitRecursive(Control namingContainer)
at System.Web.UI.Control.InitRecursive(Control namingContainer)
at System.Web.UI.Control.AddedControl(Control control, Int32 index)
at System.Web.UI.Control.EnsureChildControls()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) --- End of inner exception stack trace ---
I have already searched everything about protobuf-net and DNN but I have not found anything.
Anyone know anything about it?
EDIT
Finally, problem solved. The problem was a module that I installed that reference the protobuf-net. The module calls ZeneXa Newsletter Autoresponder. Somehow this module is not compatible with DNN versions newer than 7.0.0. I contacted the module for more information about that.
I have absolutely no knowledge of how DNN is making use of this, but at the simplest level you could try adding a reference to an appropriate version of protobuf-net (probably from NuGet is the simplest), and see if it works. This can be done via the UI or in the package manager console:
PM> Install-Package protobuf-net
If the problem is actually "fusion", then a binding redirect may help - for example, to redirect everything to r668 (assuming you are using protobuf-net r668):
<dependentAssembly>
<assemblyIdentity name="protobuf-net" publicKeyToken="257b51d87d2e4d67"
culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.0.0.668" newVersion="2.0.0.668" />
</dependentAssembly>

What causes a TypeLoadException on Migrate.exe for EF6?

I'm trying to run EF's migrate.exe from the command line as part of our build process. This is my actual command:
migrate.exe Hydrogen.Data.dll /startupConfigurationFile:..\..\..\Hydrogen.Web\Web.config
/verbose
And it continually throws this exception:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.TypeInitializationException: The type initializer for 'System.Data.Entity.SqlServer.SqlProviderServices' threw an exception. ---> System.TypeLoadException: Method 'ExecuteAsync' in type 'System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy' from assembly 'EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' does not have an implementation.
at System.Data.Entity.SqlServer.SqlProviderServices..ctor()
at System.Data.Entity.SqlServer.SqlProviderServices..cctor()
--- End of inner exception stack trace ---
at System.Data.Entity.SqlServer.SqlProviderServices.get_Instance()
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[] index)
at System.Data.Entity.Config.ProviderServicesFactory.GetInstance(Type providerType)
at System.Data.Entity.Internal.AppConfig.<.ctor>b__2(ProviderElement e)
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at System.Data.Entity.Internal.AppConfig.<.ctor>b__1()
at System.Lazy`1.CreateValue()
at System.Lazy`1.LazyInitValue()
at System.Data.Entity.Internal.AppConfig.get_DbProviderServices()
at System.Data.Entity.Config.AppConfigDependencyResolver.RegisterDbProviderServices()
at System.Data.Entity.Config.AppConfigDependencyResolver.GetServiceFactory(Type type, String name)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at System.Data.Entity.Config.AppConfigDependencyResolver.GetService(Type type, Object key)
at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
at System.Data.Entity.Config.CompositeResolver`2.GetService(Type type, Object key)
at System.Data.Entity.Config.IDbDependencyResolverExtensions.GetService[T](IDbDependencyResolver resolver, Object key)
at System.Data.Entity.DbContext.InitializeLazyInternalContext(IInternalConnection internalConnection, DbCompiledModel model)
at Hydrogen.Data.HydrogenData..ctor() in c:\code\Hydrogen\Hydrogen.Data\HydrogenData.cs:line 18
--- End of inner exception stack trace ---
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.Activator.CreateInstance(Type type)
at System.Data.Entity.Infrastructure.DbContextInfo.<CreateActivator>b__2()
at System.Data.Entity.Infrastructure.DbContextInfo..ctor(Type contextType, DbProviderInfo modelProviderInfo, AppConfig config, DbConnectionInfo connectionInfo)
at System.Data.Entity.Infrastructure.DbContextInfo..ctor(Type contextType, DbConnectionInfo connectionInfo)
at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration, DbContext usersContext)
at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration)
at System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.Run()
at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
at System.Data.Entity.Migrations.Console.Program.Run()
at System.Data.Entity.Migrations.Console.Program.Main(String[] args)
ERROR: Exception has been thrown by the target of an invocation.
When I run Update-Database from within Visual Studio everything works fine, so I know the migrations themselves are working.
This is on a SQL Server database.
I just ran into this today. This can happen when you used the wrong sets of DLL when you run migrate.exe.
In my case, I used the .Net 4.5 version in migrate.exe but compiled my project using .Net 4.0's version.
After changing the dlls the problem went away.

Resources