Can't add a migration anymore - entity-framework

I am using EF Core. Works well, but from this morinng I have this error message when I try to create a migration:
Microsoft.Extensions.CommandLineUtils.CommandParsingException: Unrecognized option '--startup-project' at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.HandleUnexpectedArg(CommandLineApplication command, String[] args, Int32 index, String argTypeName)
at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
at Microsoft.EntityFrameworkCore.Tools.Cli.Program.Main(String[] args)
Unrecognized option '--startup-project'
Does anybody knows this issue? I could not find any informations.
I checked, the default project is the correct one, migrations are enabled and I already successfully added migrations.
Thanks

Related

EF 6.2.0 migrate.exe ERROR: Object reference not set to an instance of an object

I'm setting up migrate.exe to run DB migration during VSTS release:
migrate.exe DataAccess.dll /connectionProviderName="System.Data.SqlClient" /connectionString="Data Source=SQLXXX\DEV01;Initial Catalog=XXXXX;Integrated Security=true;" /verbose
Output:
VERBOSE: Target database is: 'XXXXX' (DataSource: SQLXXX\DEV01, Provider: System.Data.SqlClient, Origin: Explicit).
No pending explicit migrations.
Running Seed method.
System.Data.Entity.Migrations.Design.ToolingException: Object reference not set to an instance of an object.
at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner)
at System.Data.Entity.Migrations.Console.Program.Run()
at System.Data.Entity.Migrations.Console.Program.Main(String[] args)
ERROR: Object reference not set to an instance of an object.
We have no code in Seed method. No pending explicit migrations is expected but we need the script to finish without an error for the release process to continue. How to fix this error?
I raised this issue on EF6 GitHub
To make it work I had to provide /startupConfigurationFile instead of /connectionString.

VS2017 + ReactJS + use of entity framework throws and error on migration

I've started a new React+Redux project in VS2017 (.net core 2.0). Default template comes without database use, so I just added use of entity framework manually. It compiles well but when I try to add a migration using command
dotnet ef migrations add "Initial"
I'm getting the next error:
An error occurred while calling method 'BuildWebHost' on class 'Program'. Continuing without the application service provider. Error: One or more errors occurred. (Webpack dev middleware failed because of an error while loading 'aspnet-webpack'. Error was: Error: Cannot find module 'aspnet-webpack'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (C:\Users\sibvic\AppData\Local\Temp\iu25u5dg.r0n:83:19)
at __webpack_require__ (C:\Users\sibvic\AppData\Local\Temp\iu25u5dg.r0n:20:30)
at createWebpackDevServer (C:\Users\sibvic\AppData\Local\Temp\iu25u5dg.r0n:62:26)
at C:\Users\sibvic\AppData\Local\Temp\ftqvg4wq.l1l:114:19
at IncomingMessage.<anonymous> (C:\Users\sibvic\AppData\Local\Temp\ftqvg4wq.l1l:133:38)
at emitNone (events.js:86:13)
Current directory is: C:\projects\test\bin\Debug\netcoreapp2.0
)
Unable to create an object of type 'ApplicationDbContext'. Add an implementation of 'IDesignTimeDbContextFactory<ApplicationDbContext>' to the project, or see https://go.microsoft.com/fwlink/?linkid=851728 for additional patterns supported at design time.
It looks like this features is too new. Not much information I can find. And can't figure out what's wrong by myself (at least yet, rubber duck method doesn't work either).
Any idea how to fix it?
I had the same issue during migration from dotnet core 1.1 to 2.0.
I had to update implementation of my Program class to following:
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
}
I know that this is not about React+Redux, but maybe it can help you.

Unable to cast object of type 'Glimpse.Ado.AlternateType.GlimpseDbConnection' to type 'System.Data.SqlClient.SqlConnection'

I am getting an "System.InvalidCastException occurred" exception where I am using the EF 6 asynchronous functionality.
The message is: Unable to cast object of type 'Glimpse.Ado.AlternateType.GlimpseDbConnection' to type 'System.Data.SqlClient.SqlConnection'.
This application was upgraded from MVC4 to MVC5 and is using the .Net Framework 4.5 for the first time.
I am aware this has been raised as an issue before; https://github.com/Glimpse/Glimpse/issues/540 but I tried getting the latest version of Glimpse and I still got the same problem.
I am wondering if I failed to uninstall Glimpse properly, either the latest version or the one I used previously.
The code where the exception happened is;
public static async Task<IList<Company>> GetCompaniesAsync()
{
using (var db = new SherryGreenGroupContext())
{
return await db.Companies
.Include("AddressLines")
.Where(x => x.EndOfBusinessDate == null)
.OrderBy(x => x.CompanyName).ToListAsync();
}
}
The exception is;
System.InvalidCastException occurred
HResult=-2147467262
Message=Unable to cast object of type 'Glimpse.Ado.AlternateType.GlimpseDbConnection' to type 'System.Data.SqlClient.SqlConnection'.
Source=System.Data
StackTrace:
at System.Data.SqlClient.SqlCommand.set_DbConnection(DbConnection value)
InnerException:
You should check you don't have Glimpse EF5 installed. That fixed it for me.
If you dont' then just uninstall all Glimpse packages. Clean your solution and reinstall Glimpse.

Error publishing an asp 3.5 app

Well, I'm here to ask about some problem I have, the detail is that when I publish the application from my computer to the server folder and after make the changes in IIS when I try to browse the web app I get the next error:
Index and length must refer to a location within the string.
Parameter name: length
In my local computer, I installed Visual Studio 2008 with SP1 and in the server is not installed only Framework 3.5.
Is the error related with Entity Framework or it's another problem?
Well, I hope you could help me... regards !
Stack Trace:
[ArgumentOutOfRangeException: Index and length must refer to a location within the string.
Parameter name: length]
System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy) +7495179
System.String.Substring(Int32 startIndex, Int32 length) +11
InnovaWebSite.Global.Session_Start(Object sender, EventArgs e) in C:\Users\cvelazquezt\Desktop\InnovaWeb\InnovaWebSite\Global.asax.cs:117
System.Web.SessionState.SessionStateModule.RaiseOnStart(EventArgs e) +8783312
System.Web.SessionState.SessionStateModule.CompleteAcquireState() +237
System.Web.SessionState.SessionStateModule.BeginAcquireState(Object source, EventArgs e, AsyncCallback cb, Object extraData) +504
System.Web.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +66
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
The error thrown is from a substring operation. Where it is actually being thrown, I have no clue, as you have not actually posted the stack trace on the error. This could be because you don't know how to do this?
If you can find the stack trace, or even detail your code that gets pieces of a string, you will have a better context of the exception and be able to start doing something to cure it.
As for root cause, the fact it is only happening after publish indicates a) something is missing on the server or b) the server is configured incorrectly (wrong version of .NET for the app pool for example) or c) you have not correctly published the site (maybe copied from your compiled application rather than published and moved the published version over, etc.???)

Re-hydrated workflow throws Profile cannot be null exception

We have a workflow as webservice application. We use custom tracking profile for each workflow type.
The worklfow assembly version got changed, so I changed the profile version too. So as the older workflows should work fine.
Now I started the workflow runtime , a workflow got triggered and persisted to DB
After some time , i re-start the runtime, the workflow is re-hydrated, but try to invoke an event on workflow, it shows exception.
If The workflow engine is not re-started , everything works fine, no errors and workflow is completed.
System.Workflow.Activities.EventDeliveryFailedException: Event "Event_111" on interface type "Service.IService" for instance id "4d0b7397-4ce1-49c7-92c6-92405caa8fe4" cannot be delivered. ---> System.ArgumentNullException: Value cannot be null.
Parameter name: profile
at System.Workflow.Runtime.RTTrackingProfile..ctor(TrackingProfile profile, Activity root, Type serviceType)
at System.Workflow.Runtime.TrackingProfileManager.CreateProfile(TrackingProfile profile, Type workflowType, Type serviceType)
at System.Workflow.Runtime.TrackingProfileManager.GetProfile(TrackingService service, Activity workflow, Version versionId)
at System.Workflow.Runtime.TrackingListenerFactory.GetChannels(Activity schedule, WorkflowExecutor exec, Guid instanceID, Type workflowType, TrackingListenerBroker& broker)
at System.Workflow.Runtime.TrackingListenerFactory.GetListener(Activity sked, WorkflowExecutor skedExec, TrackingListenerBroker broker)
at System.Workflow.Runtime.TrackingListenerFactory.GetTrackingListener(Activity sked, WorkflowExecutor skedExec, TrackingListenerBroker broker)
at System.Workflow.Runtime.TrackingListenerFactory.WorkflowExecutorInitializing(Object sender, WorkflowExecutorInitializingEventArgs e)
at System.EventHandler`1.Invoke(Object sender, TEventArgs e)
at System.Workflow.Runtime.WorkflowRuntime.WorkflowExecutorCreated(WorkflowExecutor workflowExecutor, Boolean loaded)
at System.Workflow.Runtime.WorkflowExecutor.ReRegisterWithRuntime(WorkflowRuntime workflowRuntime)
at System.Workflow.Runtime.WorkflowRuntime.RegisterExecutor(Boolean isActivation, WorkflowExecutor executor)
at System.Workflow.Runtime.WorkflowRuntime.Load(Guid key, CreationContext context, WorkflowInstance workflowInstance)
at System.Workflow.Runtime.WorkflowRuntime.GetWorkflow(Guid instanceId)
at System.Workflow.Activities.WorkflowMessageEventHandler.EventHandler(Object sender, ExternalDataEventArgs eventArgs)
--- End of inner exception stack trace ---
at System.Workflow.Activities.WorkflowMessageEventHandler.EventHandler(Object sender, ExternalDataEventArgs eventArgs)
at RecipeChangeService.RecipeChangeService.MfgEngOrTLApproved(Guid instanceId, ResponseDataObject rdo) in E:\MES\trunk\DotNet\WorkflowDesignProject\WorkflowDesignProject\Workflow Types\RecipeChangeWF\RecipeChangeService.cs:line 64
Any ideas, what is getting wrong? There are two workflows of different versions, but attached to same profile version, can this be issue?
I found the solution for it. The version of tracking profile should match the version while creating tracking profile xml.
TrackingProfile myProfile = new TrackingProfile();
myProfile.Version = new Version("4.0.0.0");
The verison should be same as the version used in stored procedure "UpdateTrackingProfile"
This solved my problem.