Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add-Migration: The type initializer for 'System.Net.ServicePointManager' threw an exception

I'm trying to do an Entity Framework code-first migration in an Azure Mobile Service. I have the project running locally and add this new class to my model:

using Microsoft.WindowsAzure.Mobile.Service;
using System;

namespace VCollectAPI.DataObjects
{
    public class TagEdit : EntityData
    {
        public string EditedTagId { get; set; }
        public string SourceTagName { get; set; }
        public string ResultingTagName { get; set; }
        public DateTime TimeOfEdit { get; set; }
    }
}

I also add this property to my VCollectAPIContext:DbContext class

public DbSet<TagEdit> TagEdits { get; set; }

and add a line to my TagDomainManager:EntityDomainManager class

if (changedItems.Contains("Name"))
{
    _context.TagEdits.Add(new TagEdit { EditedTagId = current.Id, SourceTagName = current.Name, ResultingTagName = update.Name, TimeOfEdit = DateTime.UtcNow });
    current.Name = update.Name;
}

At the PMC (Package Manager Console) I then run the command

Add-Migration RecordingTagEdits -Verbose

I expect that to make the migration scaffolding the schema update to add the new table. Instead I get the error "The type initializer for 'System.Net.ServicePointManager' threw an exception."

What am I doing wrong and how do I fix it?

The full error trace is:

System.TypeInitializationException: The type initializer for 'System.Net.ServicePointManager' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.Net.ComNetOS' threw an exception. ---> System.Configuration.ConfigurationErrorsException: The element may only appear once in this section. (C:\TFS\HXDMSRC\VisualCollections\Development\VCollectAPI\tmp140.tmp line 16) at System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult) at System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject) at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject) at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject) at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject) at System.Configuration.BaseConfigurationRecord.GetSection(String configKey) at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName) at System.Configuration.ConfigurationManager.GetSection(String sectionName) at System.Configuration.PrivilegedConfigurationManager.GetSection(String sectionName) at System.Diagnostics.DiagnosticsConfiguration.Initialize() at System.Diagnostics.DiagnosticsConfiguration.get_Sources() at System.Diagnostics.TraceSource.Initialize() at System.Net.Logging.InitializeLogging() at System.Net.Logging.get_On() at System.Net.ComNetOS..cctor() --- End of inner exception stack trace --- at System.Net.ServicePointManager..cctor() --- End of inner exception stack trace --- at System.Net.ServicePointManager.EnsureStrongCryptoSettingsInitialized() at Microsoft.VisualStudio.Platform.VsAppDomainManager.InitializeNewDomain(AppDomainSetup appDomainInfo) at System.AppDomain.CreateAppDomainManager() at System.AppDomain.Setup(Object arg) at System.AppDomain.nCreateDomain(String friendlyName, AppDomainSetup setup, Evidence providedSecurityInfo, Evidence creatorsSecurityInfo, IntPtr parentSecurityDescriptor) at System.AppDomainManager.CreateDomainHelper(String friendlyName, Evidence securityInfo, AppDomainSetup appDomainInfo) at System.AppDomainManager.CreateDomain(String friendlyName, Evidence securityInfo, AppDomainSetup appDomainInfo) at System.AppDomain.InternalCreateDomain(String friendlyName, Evidence securityInfo, AppDomainSetup info) at System.AppDomain.CreateDomain(String friendlyName, Evidence securityInfo, AppDomainSetup info) at System.Data.Entity.Migrations.Design.ToolingFacade..ctor(String migrationsAssemblyName, String contextAssemblyName, String configurationTypeName, String workingDirectory, String configurationFilePath, String dataDirectory, DbConnectionInfo connectionStringInfo) at System.Data.Entity.Migrations.MigrationsDomainCommand.GetFacade(String configurationTypeName, Boolean useContextWorkingDirectory) at System.Data.Entity.Migrations.AddMigrationCommand.Execute(String name, Boolean force, Boolean ignoreChanges) at System.Data.Entity.Migrations.AddMigrationCommand.<>c__DisplayClass2.<.ctor>b__0() at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command) The type initializer for 'System.Net.ServicePointManager' threw an exception.

like image 553
dumbledad Avatar asked Aug 22 '15 09:08

dumbledad


2 Answers

Check you web.config , maybe have some parameter duplicate.

like image 167
Victor Hugo Cornejo Calderon Avatar answered Nov 01 '22 17:11

Victor Hugo Cornejo Calderon


I had next inner exception, which means my connectionStrings section was upper than configSections:

Only one <configSections> element allowed per config file and if present must be the first child of the root <configuration> element

like image 34
Maxim Zhukov Avatar answered Nov 01 '22 15:11

Maxim Zhukov