Related
I have Asp.Net MVC 5 application using Code First Entity Framework 6 linked to MySQL database.
When I created the database first time, it works fine. But when I make a change to the model then add migration. An error shows after (Update-Database).
This is the error:
PM> Update-Database
System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at MySql.Data.MySqlClient.MySqlConnectionStringBuilder.<>c.<.cctor>b__2_7(MySqlConnectionStringBuilder msb, MySqlConnectionStringOption sender)
at MySql.Data.MySqlClient.MySqlConnectionStringBuilder.get_Item(String keyword)
at MySql.Data.MySqlClient.MySqlConnectionStringBuilder.GetConnectionString(Boolean includePass)
at MySql.Data.MySqlClient.MySqlConnection.get_ConnectionString()
at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.<GetConnectionString>b__12(DbConnection t, DbConnectionInterceptionContext`1 c)
at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget, TInterceptionContext, TResult](TTarget target, Func`3 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.GetConnectionString(DbConnection connection, DbInterceptionContext interceptionContext)
at System.Data.Entity.Internal.InternalConnection.GetStoreConnectionString(DbConnection connection)
at System.Data.Entity.Internal.InternalConnection.OnConnectionInitialized()
at System.Data.Entity.Internal.EagerInternalConnection..ctor(DbContext context, DbConnection existingConnection, Boolean connectionOwned)
at System.Data.Entity.DbContext..ctor(DbConnection existingConnection, Boolean contextOwnsConnection)
at System.Data.Entity.Migrations.History.HistoryContext..ctor(DbConnection existingConnection, String defaultSchema)
at MySql.Data.Entity.MySqlHistoryContext..ctor(DbConnection existingConnection, String defaultSchema)
at code_first_mysql.Migrations.Configuration.<>c.<.ctor>b__0_0(DbConnection conn, String schema) in C:\Users\User\Documents\Tree\New Backend\code first mysql\Migrations\Configuration.cs:line 16
at System.Data.Entity.Migrations.History.HistoryRepository.CreateContext(DbConnection connection, String schema)
at System.Data.Entity.Migrations.History.HistoryRepository.<GetUpgradeOperations>d__16.MoveNext()
at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source)
at System.Data.Entity.Migrations.DbMigrator.UpdateInternal(String targetMigration)
at System.Data.Entity.Migrations.DbMigrator.<>c__DisplayClassc.<Update>b__b()
at System.Data.Entity.Migrations.Infrastructure.MigratorScriptingDecorator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
at System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)
at System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update(String targetMigration)
at System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update(String targetMigration)
at System.Data.Entity.Migrations.Infrastructure.MigratorScriptingDecorator.ScriptUpdate(String sourceMigration, String targetMigration)
at System.Data.Entity.Migrations.Design.ToolingFacade.ScriptUpdateRunner.Run()
at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner)
at System.Data.Entity.Migrations.Design.ToolingFacade.ScriptUpdate(String sourceMigration, String targetMigration, Boolean force)
at System.Data.Entity.Migrations.UpdateDatabaseCommand.<>c__DisplayClass2.<.ctor>b__0()
at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
The given key was not present in the dictionary.
These are my MySQL Configuration Classes:
internal sealed class Configuration : DbMigrationsConfiguration<ApplicationDbContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = false;
SetSqlGenerator("MySql.Data.MySqlClient", new MySqlMigrationSqlGenerator());
SetHistoryContextFactory("MySql.Data.MySqlClient", (conn, schema) => new MySqlHistoryContext(conn, schema));
CodeGenerator = new MySqlMigrationCodeGenerator();
}
protected override void Seed(ApplicationDbContext context)
{}
}
public class MySqlConfiguration: DbConfiguration
{
public MySqlConfiguration()
{
SetHistoryContext("MySql.Data.MySqlClient", (conn, schema) => new MySqlHistoryContext(conn, schema));
}
}
public class MySqlHistoryContext : HistoryContext
{
public MySqlHistoryContext(DbConnection existingConnection, string defaultSchema) : base(existingConnection, defaultSchema)
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<HistoryRow>().Property(h => h.MigrationId).HasMaxLength(100).IsRequired();
modelBuilder.Entity<HistoryRow>().Property(h => h.ContextKey).HasMaxLength(200).IsRequired();
}
}
public class MySqlInitializer : IDatabaseInitializer<ApplicationDbContext>
{
public void InitializeDatabase(ApplicationDbContext context)
{
if (!context.Database.Exists())
{
// if database did not exist before - create it
context.Database.Create();
}
else
{
// query to check if MigrationHistory table is present in the database
var migrationHistoryTableExists = ((IObjectContextAdapter)context).ObjectContext.ExecuteStoreQuery<int>(
string.Format(
"SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = '{0}' AND table_name = '__MigrationHistory'", "mydb"));
// if MigrationHistory table is not there (which is the case first time we run) - create it
if (migrationHistoryTableExists.FirstOrDefault() == 0)
{
context.Database.Delete();
context.Database.Create();
}
}
}
}
As you see from the first lines of the error,
MySql.Data.MySqlClient.MySqlConnectionStringBuilder.<>c.<.cctor>b__2_7(MySqlConnectionStringBuilder
msb, MySqlConnectionStringOption sender)
at MySql.Data.MySqlClient.MySqlConnectionStringBuilder.get_Item(String
keyword)
the error has to do with the ConnectionString. The problem is the ConnectionString contains keys that can't be read.
Try to clean up the ConnectionString so that it has only
server
user id
password
database
In my case, the ConnectionString had an extra key integrated security. When this was removed Update-Database started working fine. Depending on your case however, this might and might not be the key that caused the error.
So again my proposed and guaranteed solution, go through ConnectionString and simplify it so that it contains only the 4 keys mentioned above.
Bug 75172
It is a bug reported in version 6.9.4,but I review it in 6.9.11.
Don't apply the newest mysql tools
Close Visual studio 2017
Uninstall mysql-for-visualstudio 2.0.5 Then, install mysql-for-visualstudio 1.2.8
Uninstall mysql-connector-net-8.0.17 Then, install mysql-connector-net-6.9.10.
Find the mysql.data.dll, MySql.Data.Entity.EF6.dll in
%Program Files (x86)%\MySQL\MySQL Connector Net 6.9.10\Assemblies\v4.5
Add to reference
Open nuget in references, downgrade EntityFramework 6 to EntityFramework 5
This worked for me: Close your visual studio and
go to this folder
C:\Users[youruser]\AppData\Roaming\Microsoft\VisualStudio\16.0_befcda98\ServerExplorer
And then delete the file DefaultView.SEView
Open your visual studio and try again.
Here is db initialization code:
using (MyDbContext db = new MyDbContext("Data Source=isostore:/my_db.sdf"))
{
if (!db.DatabaseExists())
{
db.CreateDatabase();
}
}
Code works great on debug version, but after publish to the windows phone store it fails.
StackTrace:
The database file cannot be found. check the path to the database. [ Data Source = C:\Data\Users\DefApps\AppData\{A1F26781-AA93-432A-AD80-B02825C3BBA8}\Local\my_db.sdf ]
at System.Data.SqlServerCe.SqlCeConnection.Open(Boolean silent)
at System.Data.SqlServerCe.SqlCeConnection.Open()
at System.Data.Linq.SqlClient.SqlConnectionManager.UseConnection(IConnectionUser user)
at System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query, QueryInfo queryInfo, IObjectReaderFactory factory, Object[] parentArgs, Object[] userArgs, ICompiledSubQuery[] subQueries, Object lastResult, Boolean isCompiledQuery)
at System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query, QueryInfo[] queryInfos, IObjectReaderFactory factory, Object[] userArguments, ICompiledSubQuery[] subQueries, Boolean isCompiledQuery)
at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query)
at System.Data.Linq.DataQuery`1.System.Linq.IQueryProvider.Execute[S](Expression expression)
at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source)
at MyApp.Models.SomeModel.restoreObjectData()
Thanks for help.
You need to copy the database to the isostore folder, if you use the SQL CE Toolbox DataConntext, you can use code like:
if (!db.DatabaseExists())
{
db.CreateIfNotExists();
}
Sorry guys, I found a problem. I wrote database initialization code here.
public App()
{
// Show graphics profiling information while debugging.
if (System.Diagnostics.Debugger.IsAttached)
{
db.create();
}
When using the same MVC 3 & C# code along with copies of the same MySql 5.5 database on 2 different MySql installations. One works perfectly while the other one fails with an "Object must implement IConvertible" error. When I run the query against my local PC's MySql installation the query always works perfectly, but when I try querying from local PC's Visual Studio 2010 to a copy of the same database at my Internet Service Provider's MySql installation then I receive an error "Object must implement IConvertible". The only thing I change in the code is the ConnectionString's Server Name in the web.config, otherwise the code & database are exactly the same. NOTE: All other queries to the ISP's MySql installation work perfectly only this one particular query doesn't work.
After trying to troubleshoot this for several days I'm convinced that the error message "Object must implement IConvertible" has nothing to do with what is actually happening and I'm also under the impression that the MySql configuration at my ISP may somehow be causing this issue for the following reasons:
If this were truly an "Object must implement IConvertible" issue within the code then the issue would persist in the code and happen no matter which DB installation I hit.
I've completely dropped & recreated the DB at the ISP from my local PC's working copy however still receive the same exactly error.
MOST INTERESTINGLY is that the query has 3 nested IEnumerable lists that are all setup in the same way as IEnumerables and if I comment out any 1 of these nested lists in the query then the query runs successfully against the ISP's DB. It doesn’t matter which nested list gets commented out, only that there are 2 or less nested lists and then the query to the DB at ISP works. This is what leads me to the conclusion that MySql’s configuration at the ISP may be limiting my queries in some way, as I do not have this problem when querying my local PC's MySql installation. The error message really doesn’t appear to apply to what is actually happening. Again, all the other queries to the ISP's MySql installation work perfectly, however none of them contain more than 2 nested IEnumerable lists where this particular query contains 3?
Query Error "Object must implement IConvertible"
Server Error in '/' Application.
________________________________________
Object must implement IConvertible.
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.InvalidCastException: Object must implement IConvertible.
Source Error:
Line 392:
Line 393:
Line 394: var query =
Line 395: (from p in db.products
Line 396: where p.ClientId == clientId
Source File: C:\Users\JR\Documents\Visual Studio 2010\Projects\Subversion\ReservarMVC\ReservarMVC\Models\ProductRepository.cs Line: 394
Stack Trace:
[InvalidCastException: Object must implement IConvertible.]
System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider) +9528453
MySql.Data.Entity.EFMySqlDataReader.ChangeType(Object sourceValue, Type targetType) +566
MySql.Data.Entity.EFMySqlDataReader.GetValue(Int32 ordinal) +231
System.Data.Common.Internal.Materialization.ErrorHandlingValueReader`1.GetValue(DbDataReader reader, Int32 ordinal) +215
System.Data.Common.Internal.Materialization.Shaper.GetColumnValueWithErrorHandling(Int32 ordinal) +46
lambda_method(Closure , Shaper ) +180
System.Data.Common.Internal.Materialization.Coordinator`1.ReadNextElement(Shaper shaper) +170
System.Data.Common.Internal.Materialization.RowNestedResultEnumerator.MoveNext() +235
System.Data.Common.Internal.Materialization.ObjectQueryNestedEnumerator.TryReadToNextElement() +49
System.Data.Common.Internal.Materialization.ObjectQueryNestedEnumerator.ReadElement() +29
System.Data.Common.Internal.Materialization.ObjectQueryNestedEnumerator.MoveNext() +68
System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +327
System.Linq.Enumerable.ToList(IEnumerable`1 source) +58
ReservarMVC.Models.ProductRepository.GetProductList(Nullable`1 dateStart, Nullable`1 dateEnd, Nullable`1 personQuantityId, Nullable`1 roomQuantityId) in C:\Users\JR\Documents \Visual Studio 2010\Projects\Subversion\ReservarMVC\ReservarMVC\Models\ProductRepository.cs:394
ReservarMVC.Models.ProductRepository.GetProductListSearch(Nullable`1 dateStart, Nullable`1 dateEnd, Nullable`1 personQuantityId, Nullable`1 roomQuantityId) in C:\Users\JR\Documents\Visual Studio 2010\Projects\Subversion\ReservarMVC\ReservarMVC\Models\ProductRepository.cs:605
ReservarMVC.Controllers.PortalController.MyExcurcion(ProductListSearchVM viewModel) in C:\Users\JR\Documents\Visual Studio 2010\Projects\Subversion\ReservarMVC\ReservarMVC\Controllers\PortalController.cs:63
lambda_method(Closure , ControllerBase , Object[] ) +162
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +17
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +208
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +55
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +263
System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +19
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +191
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +343
System.Web.Mvc.Controller.ExecuteCore() +116
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +97
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +37
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21
System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +12
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +50
System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8967601
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184
________________________________________
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.261
LINQ-to-Entities Query:
public IEnumerable<ProductListVM> GetProductList(DateTime? dateStart, DateTime? dateEnd, int? personQuantityId, int? roomQuantityId)
{
var query =
(from p in db.products
where p.ClientId == clientId
where p.ProductTypeId == 5
where personQuantityId <= p.Capacity
where roomQuantityId <= p.Quantity
select new ProductListVM
{
ProductId = p.ProductId,
ClientId = p.ClientId,
Name = p.Name_en,
Title = p.Title_en,
Description = p.Description_en,
Quantity = p.Quantity,
Capacity = p.Capacity,
newbookings = from b in db.bookings
where b.ProductId == p.ProductId
from res in db.reservations
where b.ReseravationId == res.ReservationId
where b.BookingDateTime >= dateStart && b.BookingDateTime <= dateEnd && res.ReservationStateId != 3
select new BookingVM
{
ProductId = b.ProductId,
BookingId = b.BookingId,
ClientId = b.ClientId,
ReservationId = b.ReseravationId,
BookingDateTime = b.BookingDateTime
},
newratecategories = from prc in db.productratecategories
where prc.ProductId == p.ProductId
from rc in db.ratecategories
where prc.RateCategoryId == rc.RateCategoryId
where (dateStart >= rc.DateStart && dateEnd <= rc.DateEnd) || (dateStart >= rc.DateStart || dateEnd <= rc.DateEnd)
select new MegaRateCategoryVM
{
RateCategoryId = rc.RateCategoryId,
DateStart = rc.DateStart,
DateEnd = rc.DateEnd
},
newproductimages = (from pi in db.productimages
where pi.ProductId == p.ProductId
from ig in db.imagegalleries
where pi.ImageGalleryId == ig.ImageGalleryId
select new MegaProductImageVM
{
ig_Description = ig.ig_Description,
ImageGalleryId = pi.ImageGalleryId
}).OrderByDescending(i => i.ImageGalleryId)
}).ToList();
return query;
}
Product List ViewModel:
namespace Project.ViewModels
{
[Serializable]
public class ProductListVM : BaseViewModel
{
public int ProductId { get; set; }
public int? ClientId { get; set; }
public int? ProductTypeId { get; set; }
public int? ProductStateId { get; set; }
public String Name { get; set; }
public String Title { get; set; }
public String Description { get; set; }
public int? Quantity { get; set; }
public int? Capacity { get; set; }
//PRODUCTIMAGE table fields
public IEnumerable<MegaProductImageVM> newproductimages { get; set; }
//RATECATEGORY table fields
public IEnumerable<MegaRateCategoryVM> newratecategories { get; set; }
//BOOKING table fields
public IEnumerable<BookingVM> newbookings { get; set; }
}
}
What could be causing this behavior? Could this be caused by a query threshold setting or network setting on the MySql 5.5's database configuration? I haven't changed any of the defaults on either of the MySql 5.5 installations. I'm just using the standard MySql Connector/Net 6.5.4 to access the DB along with Microsoft's standard MVC 3, C#, Entity Framework 4, LINQ-to-Entities code.
Any help on this is greatly appreciated. Thanks, Atlas361
To fix this, add 'respect binary flags=false' to your connection string, e.g.:
connectionString="metadata=res://*/Something.csdl|res://*/Something.ssdl|
res://*/Something.msl;provider=MySql.Data.MySqlClient;
provider connection string="server=my-server;User Id=some-user;
Persist Security Info=True;database=some-database;respect binary flags=false""
This is a known issue with certain versions of MySQL 5.0 and 5.1
There are certain situations where MySQL will return incorrect metadata about one or more columns... In the event that the changes required to your application would be too large, adding 'respect binary flags=false' to your connection string causes the connector to use the prior behavior: any column that is marked as string, regardless of binary flags, will be returned as string. Only columns that are specifically marked as a BLOB will be returned as BLOB.
Hope this helps future travelers.
I published my MVC application to the ISP so that any potential issue caused by querying across the internet was eliminated but I still had the same exact error "Object must implement IConvertible”. After troubleshooting this further with the completely inept support staff at Arvixe.com I discovered that the actual version of MySql they had the database on was 5.1.54 released 2008 and not MySql 5.5 that was released in late 2010. According to the MySql documentation the MySql Connector/Net 6.5.4 & Microsoft's Entity Framework 4 are compatible, but I found this not to be true. After fighting with Arvixe.com to put me on MySql 5.5 server the problem went away. So in the end this was version compatibility issue.
Hope the answer helps! Atlas361
We are getting a SecurityException when using Entity framework on godaddy. The entity has been configured against a MySQL store. (v. 6.1.2) A bit of weirdness with the exception though... Looking at the exception stack it seems to imply that if we open up a connection to MySQL anywhere in the site, then we should get the same exception; however, opening up a MySQL connection directly seems to be working in another part of the site...
Here's the verification:
using (MySqlConnection connection = new MySqlConnection(ConnectionString))
{
connection.Open();
...
}
Anyone run across a similar issue?
The complete error stack trace is as follows:
[SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
System.Reflection.MethodBase.PerformSecurityCheck(Object obj, RuntimeMethodHandle method, IntPtr parent, UInt32 invocationFlags) +0
System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +470
System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) +1051
System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) +111
System.Resources.ResourceManager.CreateResourceSet(Stream store, Assembly assembly) +357
System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean createIfNotExists, Boolean tryParents) +471
System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean createIfNotExists, Boolean tryParents) +583
System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean createIfNotExists, Boolean tryParents) +583
System.Resources.ResourceManager.GetString(String name, CultureInfo culture) +74
MySql.Data.MySqlClient.Resources.get_PerfMonCategoryName() +40
MySql.Data.MySqlClient.PerformanceMonitor..ctor(MySqlConnection connection) +43
MySql.Data.MySqlClient.MySqlConnection.Open() +434
System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure) +173
System.Data.EntityClient.EntityConnection.Open() +96
System.Data.Objects.ObjectContext.EnsureConnection() +81
System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption) +46
System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() +44
jet.Controllers.WorkOrder.WorkOrderView..ctor() +219
jet.Controllers.WorkOrder.WorkOrderView.get_Instance() +29
jet.Controllers.WorkItemController.Index() +11
lambda_method(ExecutionScope , ControllerBase , Object[] ) +39
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +17
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +178
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +24
System.Web.Mvc.<>c__DisplayClassa.<InvokeActionMethodWithFilters>b__7() +53
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +258
System.Web.Mvc.<>c__DisplayClassc.<InvokeActionMethodWithFilters>b__9() +20
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +193
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +382
System.Web.Mvc.Controller.ExecuteCore() +123
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +23
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +7
System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext) +144
System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext) +54
System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext httpContext) +7
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
Weird one. GoDaddy shared-hosting ASP.NET apps execute under Medium Trust, and perf counter creation probably requires full trust, but perf counter creation is not what's failing here. (and if it failed, it wouldn't propagate out since perf coutner creation exceptions are swallowed by mySQL client code).
Instead, it's failing trying to access a string resource, before perf counter creation. The failure is with this line of code in Resources.Designer.cs of the MySQL client:
return ResourceManager.GetString("PerfMonCategoryName", resourceCulture)
A few things to try, in increasing order of difficulty:
ensure you have the MySQL client DLLs in your app's BIN directory and you're not trying to load the client DLL out of GoDaddy's GAC. Never depend on GoDaddy-supplied binaries if you can avoid it!
switch to EN-US culture so the client doesn't have to go hunting for another resource DLL, and see if the problem goes away.
Build the .NET client from source code, instead of copying DLLs from a binary distribution into your app's BIN directory. This will make problems like this easier to debug since the mySQL code won't be a black box. And, in a pinch, will let you change the problematic resource-fetching calls (or hard-code the locale)! :-)
BTW, in case you're tempted to set "Use Performance Monitor=false" in your connection string to try to evade the problem, don't bother. The problematic code gets executed regardless of that setting:
public PerformanceMonitor(MySqlConnection connection)
{
this.connection = connection;
//// this line is where it bombs
string categoryName = Resources.PerfMonCategoryName;
//// this line is affected by connection string setting
if (connection.Settings.UsePerformanceMonitor && procedureHardQueries == null)
{
try
{
procedureHardQueries = new PerformanceCounter(categoryName,
"HardProcedureQueries", false);
procedureSoftQueries = new PerformanceCounter(categoryName,
"SoftProcedureQueries", false);
}
catch (Exception ex)
{
Logger.LogException(ex);
}
}
}
Justin was spot on. Problem was godaddy has an older version of the MySql dll in their gac and the entity framework was picking it up!
Here's the fix. (Apply this to web.config)
<configuration>
...
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d"/>
<bindingRedirect oldVersion="5.0.7.0" newVersion="6.1.2.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
...
</configuration>
I simply added trust level="Full" to my Web config file, and it worked
This is probably a shot in the dark but here goes nothing...
I have a Sitecore 6 site that I am developing locallty. When I pushed it to the production server, I now get an exception when trying to access the site. I had done an upgrade of the Sitecore version, and added the Forms module, among some other minor edits. So I moved everything to production, changed the connection strings, and changed the directory references in the web.config, but I still get this error.
My local machine still works fine, and even my staging server (hooked up via SVN and Cruise Control) works fine, but I can't fix this error on production.
At the bottom of the stack trace (below), it looks like it is trying to instantiate the search manager. Maybe that has something to do with it?
Or maybe I missed a setting when I moved everything? What settings need to be changed when the environment changes?
Here is what I've tried so far:
Re-copied all of the files and databases.
Gave full control permissions to the worker process, ASPNET, and Network Service users.
Double checked the directory paths in the web.config that needed to be configured.
Double checked the connection string in the connectionstring.config.
Recycled the App Pool
Stopped and started the site
Cleared my local browser cache (as they instruct you to do in the upgrade docs)
This is the exception that is being thrown when I try and access any page:
Thread information:
Thread ID: 1
Thread account name: 180716WEB1\testcom_web
Is impersonating: False
Stack trace: at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, Object[] index)
at Sitecore.Reflection.ReflectionUtil.SetProperty(Object obj, PropertyInfo property, Object value)
at Sitecore.Reflection.ReflectionUtil.SetProperty(Object obj, String name, Object value)
at Sitecore.Configuration.Factory.AssignProperties(Object obj, Object[] properties)
at Sitecore.Configuration.Factory.AssignProperties(XmlNode configNode, String[] parameters, Object obj, Boolean assert, Boolean deferred, IFactoryHelper helper)
at Sitecore.Configuration.Factory.CreateObject(XmlNode configNode, String[] parameters, Boolean assert, IFactoryHelper helper)
at Sitecore.Configuration.Factory.GetInnerObject(XmlNode paramNode, String[] parameters, Boolean assert)
at Sitecore.Configuration.Factory.AssignProperties(XmlNode configNode, String[] parameters, Object obj, Boolean assert, Boolean deferred, IFactoryHelper helper)
at Sitecore.Configuration.Factory.CreateObject(XmlNode configNode, String[] parameters, Boolean assert, IFactoryHelper helper)
at Sitecore.Configuration.Factory.GetInnerObject(XmlNode paramNode, String[] parameters, Boolean assert)
at Sitecore.Configuration.Factory.AssignProperties(XmlNode configNode, String[] parameters, Object obj, Boolean assert, Boolean deferred, IFactoryHelper helper)
at Sitecore.Configuration.Factory.CreateObject(XmlNode configNode, String[] parameters, Boolean assert, IFactoryHelper helper)
at Sitecore.Configuration.Factory.CreateObject(XmlNode configNode, String[] parameters, Boolean assert)
at Sitecore.Configuration.Factory.CreateObject(String configPath, String[] parameters, Boolean assert)
at Sitecore.Configuration.Factory.CreateObject(String configPath, Boolean assert)
at Sitecore.Search.SearchManager..cctor()
Custom event details:
For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.
It seems that there's something wrong with rights.
Make sure that you run the right identity(NETWORK SERVICES) in your AppPool and that you follow the Sitecore Installation instructions which can be found on SDN:
Kind regards,
Alex de Groot
Sitecore Solution Architect
It turned out to be that when I restored the database to production, it didn't re-associate the database user with it!!! Stupid me! For whatever reason, that causes this error to occur. I'm guessing that the SearchManager is setup as some sort of external service or something, to abstract things.
I got this error after moving a site between environments. The cause was the path for the sc.variable named dataFolder was incorrect. The value was a full file path and the site was in a different location on the new server.
<sc.variable name="dataFolder" value="c:\www\website\data\" />
Updating the web.config with the correct path fixed the problem.