Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PMC Tools: Error when project opened from a file share #7540

Closed
rowanmiller opened this issue Feb 2, 2017 · 37 comments
Closed

PMC Tools: Error when project opened from a file share #7540

rowanmiller opened this issue Feb 2, 2017 · 37 comments
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Milestone

Comments

@rowanmiller
Copy link
Contributor

Moved from dotnet/EntityFramework.Docs#346
cc @klipi

I'm following the tutorial here: https://docs.microsoft.com/en-us/ef/core/get-started/aspnetcore/new-db up to the point where I need to run the first migration:

PM> Add-Migration MyFirstMigration
Unable to resolve startup project 'Microsoft.PowerShell.Core\FileSystem::\\mac\home\documents\visual studio 2017\Projects\EFGetStarted.AspNetCore.NewDb\EFGetStarted.AspNetCore.NewDb\EFGetStarted.AspNetCore.NewDb.csproj'.
To undo this action, use Remove-Migration.
Add-Migration : Exception calling "AddFromFile" with "1" argument(s): "'basePath' cannot be an empty string ("") or start with the null character.
Parameter name: basePath"
At line:1 char:1
+ Add-Migration MyFirstMigration
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Add-Migration], MethodInvocationException
    + FullyQualifiedErrorId : ArgumentException,Add-Migration

I'm running Visual Studio 2017 RC3 under a Win10 VM in Parallels, so that might be the cause of some issues. However I have no idea on how to start to debug this, as I'm quite new to the .NET Core world and Entity Framework.

@oniskanen
Copy link

Copying this over from the documentation side

PM> $DTE.Solution.SolutionBuild.StartupProjects
EFGetStarted.AspNetCore.NewDb\EFGetStarted.AspNetCore.NewDb.csproj
PM> $DTE.Solution.Properties.Item('Path').Value
\\mac\home\Documents\Visual Studio 2017\Projects\EFGetStarted.AspNetCore.NewDb\EFGetStarted.AspNetCore.NewDb.sln

I'll try to redo the tutorial under C:\ and see what happens. Not sure if anything else is breaking, been away from Windows and VS for a couple of years. A quick HelloWorld-type web app works nicely and I was even able to publish it to Azure without a hitch. Trying to add the database layer (and EF along it) is the first I'm running into trouble.

@oniskanen
Copy link

@bricelam, No issue running under C:\

@bricelam
Copy link
Contributor

bricelam commented Feb 2, 2017

Groovy. I suspect this is the root of our problems:

PS> Split-Path \\mac\home -IsAbsolute
False

@rowanmiller rowanmiller added this to the 2.0.0 milestone Feb 10, 2017
@ojorma
Copy link

ojorma commented Mar 12, 2017

im having a similar issue except that im not in a file share. I just got vs2017 and i get this error when i try to add-migration

`add-migration : Exception calling "AddFromFile" with "1" argument(s): "'basePath' cannot be an empty string ("") or start with the null character.
Parameter name: basePath"
At line:1 char:1

  • add-migration init
  •   + CategoryInfo          : NotSpecified: (:) [Add-Migration], MethodInvocationException
      + FullyQualifiedErrorId : ArgumentException,Add-Migration
    

`

@dotnetnoobie
Copy link

I have the same error message as @ojorma
Using VS2017 ASPNET CORE & EF CORE 1.1 versions

I am using a class library for the DataContext Objects

I only get this error with the DataContext which also is the context object which is used for ApplicationDbContext

When I try it with other DataContext objects which are for small stand alone databases I don't get the error.

I also noticed that when I tried to run the web app and use the build in apply migrations button that EF-Core could not login to the database and was trying to use my Microsoft Login for the Windows/Microsoft Account, even when I have set the connection string in the app settings to use a trusted connection.

The message asked me to create the migration manually for the ApplicationDbContext
I created it manually, no error, I updated the database with no error

Once I had done this manually via the nuget command window in VS2017

I was then able to create the same migration which I got the above error for
but this time I got no error and was able to update the database and everything worked as it normally does with no errors

@bricelam
Copy link
Contributor

bricelam commented Mar 13, 2017

@ojorma @dotnetnoobie Are you using Docker? You may be hitting #7439. (Workaround: Pass your web app as -StartupProject)

@ojorma
Copy link

ojorma commented Mar 13, 2017

@bricelam I am using a console app. I first tried it with a class library but thesame thing so i tried it again in a console app. I just got vs2017 and testing the basic stuff out. I got burnt with version 1.0 cause of entityframework core.

@ojorma
Copy link

ojorma commented Mar 13, 2017

@bricelam @rowanmiller @dotnetnoobie
this is what my sample project looks like
entitycorebug

@dotnetnoobie
Copy link

dotnetnoobie commented Mar 15, 2017

@bricelam I am not using docker
Just a standard projects

AspNetCore 1.1 app which references Class Library

I have the DataContext objects on a separate project which is a
.NetCore App 1.1 (Class Library)

I set the "Default Project" in the "Package Manager Console" from the dropdown
but I did not use this "-StartupProject" option in the commands

@dotnetnoobie
Copy link

@bricelam I also had problems with the class library originally
what I did was create a test website with individual auth set in the options
I then opened the .csproj file and copied the correct EF Core related references for the nuget packages
and added them to the class library .csproj file

This seemed to solve the issues I has of not actually having all the correct nuget packages referenced to get everything working

@rowanmiller @dotnetnoobie

@ojorma
Copy link

ojorma commented Mar 16, 2017

@dotnetnoobi @rowanmiller it turns out the problem is caused as a result of having multiple dotnetsdk and the wrong one been called in the environmental variables. if you dont want to uninstall the earlier sdk make sure you move
environ
i moved the 64bit dotcli path up (C:\Program Files\dotnet ) which had the current sdk

@imad24
Copy link

imad24 commented Mar 28, 2017

Hello @ojorma,
I face the same problem with migration on Visual Studio 2017 under Windows 8.1 . I've checked and I have only one SDK installed the 1.0.0 at C:\Program Files\dotnet.
Have you tried something else ? cause I have exactly the same error message.

@ojorma
Copy link

ojorma commented Mar 28, 2017

@imad24 when you type dotnet --version in the command line what does it give you? this is mine
image
you could still try installing the x86 version of the dotnet sdk. if you could share a sample project on onedrive or something, I could download an check

@imad24
Copy link

imad24 commented Mar 28, 2017

@ojorma I've got the same version as you can see (along with two others installed i think)

image

@bricelam Everything seems ok with the Powershell commands as well:
PM> $DTE.Solution.SolutionBuild.StartupProjects
HPCRM\HPCRM.csproj
PM> $DTE.Solution.Properties.Item('Path').Value
C:\Users\imad.rahmouni\documents\visual studio 2017\Projects\HPCRM\HPCRM.sln
PM>
The error message just in case:

image

@ojorma I'll try to install the x86 version as you suggested, then give it another try with a sample project. I'll send you a link if it still not work.
Thank you

@ojorma
Copy link

ojorma commented Mar 29, 2017

@imad24 im seeing 1.0.0-preview2-1...... That means there are multiple sdks on your system.

  1. Please try to delete both folders that have the preview thing. you can leave them in the recycle bin,

  2. then check a similar path on the programfiles x86 folder, if there is anyone with preview in it delete the folder. You can use add remove programes to uninstall later.

  3. Then check your environmental variables as I mentioned earlier.

I think visual studio is some how invoking the older sdks. Please let us know your outcome. Good luck

@imad24
Copy link

imad24 commented Mar 29, 2017

@ojorma I didnt want to delete the older preview version because I have other projects pointing to them that I haven't migrated yet. But I thought since the "dotnet --version" is displaying "1.0.0" then the right SDK is used. Anyway:
1- I deleted the two folders: not working, same error.
2- I have no dotnet folder in the x86 programs(not yet)
3- In the environment variables i only have one line for dotnet which points to "C:\Program Files\dotnet"

Next i'll install and try with the x86 version. I'll keep you updated.

@imad24
Copy link

imad24 commented Mar 29, 2017

Hello again @ojorma,
As you mentionned I tried to recreate the same conditions as yours, I installed the x86 version, made the changes to the environment variables and it didnt work. (naturally I didnt have the x86 line before)

env_var

After installing the x86 version I realized the 1.0.1 skd was out, so installed the 1.0.1 x64 and made the same tests, I even inverted the env variables, still nothing.

Here is a screenshot of most of the tests I made, I dont think it's related to the multiple SDKs as you can see (PM console VS cmd console)
It's not related to the paths either since I am on an exclusively windows environment and the powershell commands results seem ok as I mentionned earlier.

all-tests

Please tell me if you have other suggestions.

@ojorma
Copy link

ojorma commented Mar 29, 2017

while the project is open in visual studio type dotnet alone and dotnet --version. Let see what gets invoked
image
Lastly if its a demo project you can send to my email. Dont know if its allowed here. [email protected].
Let me check if it runs. if not I will assume its some wrong reference from nugget package.

@imad24
Copy link

imad24 commented Mar 29, 2017

@ojorma I'm sending you the project by email.

@imad24
Copy link

imad24 commented Mar 29, 2017

Hello everyone,
Just to point out that i fixed my problem. Actually it had to do with the data model on which I was applying the migration.
Many "design errors" were on it (a foreign key property that references a key that doesn't exist on the target type for example.)
I don't understand why it displayed that exception message though.

Thanks for your help @ojorma

@Cae2
Copy link

Cae2 commented Mar 30, 2017

Hello, Im having this problem too...

ps: the exact command was working last week, not sure if its related with VS2017 update yesterday.

ef-error

@imad24
Copy link

imad24 commented Mar 30, 2017

@Cae2 For me it was related to the model classes, there were some errors so the migration was raising this "generic error".
Try to scaffold a simpler model (with just one table for example) and see if it displays the same message.

@Cae2
Copy link

Cae2 commented Mar 30, 2017

@imad24 created a very simple table to test, but the same error occurs:

1

also tried the @bricelam command:

2

@imad24
Copy link

imad24 commented Mar 30, 2017

@Cae2 Well, it may be something else.
One last thing, when creating a migration from a class with "add-migration" you have to specify a primary key for each entity, I see that you didn't on the table you're willing to scaffold. can you give it a last try with primary key set ?

@Cae2
Copy link

Cae2 commented Mar 30, 2017

@imad24

To be honest, it seems that doesnt even reach the point to scaffold something...
3

@ojorma
Copy link

ojorma commented Mar 30, 2017

@imad24 glad u fixed it. I even went to the extent of living just one table in the dbcontext and still got the error but I never checked the table it self. That error message is highly misleading. I guess Entityframework core is still evolving.

@Cae2
Copy link

Cae2 commented Mar 30, 2017

lol, this is really strange... I just keep flooding the PMC and in the end it works... (the flood "up + enter" was about 1 per second)

4

@bricelam
Copy link
Contributor

What type of project are you using? This may be an issue with the new project system...

@themausam
Copy link

I am getting the same error as well on new Class Library (.NET Standard) project while trying to do database first initialisation with connection string:
Scaffold-DbContext "Data Source=Server1;Initial Catalog=MyDb;Persist Security Info=True;User ID=Developer;Password=Password" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -v -t MyTable1
I am running Windows 10 with VS 2017. My .csproj file looks like:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard1.4</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="1.1.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.1.0" />
  </ItemGroup>
</Project>

My scenario is to create a common .NET Standard library so that it can be used in both .NET Core and Xamarin projects. Can someone please point out if I am on right path. The error message isn't helping much. Thank you.

@bricelam bricelam changed the title PowerShell commands broken when project opened from a file share PMC Tools: Error when project opened from a file share Mar 31, 2017
@ojorma
Copy link

ojorma commented Mar 31, 2017

@themausam I dont think codefirst can run from a .netstandard library

@ajcvickers ajcvickers modified the milestones: 2.0.0-preview1, 2.0.0 Apr 19, 2017
@bricelam bricelam removed the tools label Apr 26, 2017
@bricelam bricelam added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label May 12, 2017
@bricelam bricelam modified the milestones: 2.0.0, 2.0.0-preview2 May 16, 2017
@joacar
Copy link

joacar commented May 20, 2017

I can confirm that this has to do with invalid data modelling. Had this issue as well with a type on an inverse property attribute causing the generic error. Then fixing that, I got informed about another incorrect configuration (proper exception message). Fixed that but then again forgot to remove a navigation property on dependent entity and the generic error message was back.

@isaacrlevin
Copy link

isaacrlevin commented Jun 22, 2017

I can make this another issue if needed

I started getting error out of nowhere (I did upgrade by VS2017 Preview verison, but doubt that has reference).

I have a Dot Net Core 2 Console App (2.0.0-preview1-005977) that I am using to do Migrations using Package Manager. The Context is in a .Net Standard 2.0(2.0.0-preview1-25301-01) CL. Here is my Context and the Factory

    public class BlogContext : DbContext
    {
        public BlogContext(DbContextOptions<BlogContext> options) : base(options) { }
        public DbSet<ContactEntity> Contacts { get; set; }

        public DbSet<UserEntity> Users { get; set; }
        public DbSet<PostEntity> Posts { get; set; }
        public DbSet<PostTagEntity> PostTags { get; set; }
        public DbSet<TagEntity> Tags { get; set; }
        public DbSet<CategoryEntity> Categories { get; set; }
   }

    public class BlogContextFactory : IDbContextFactory<BlogContext>
    {
        public BlogContext Create(DbContextFactoryOptions options)
        {
            var builder = new DbContextOptionsBuilder<BlogContext>();
            builder.UseSqlServer(
                "Server=localhost;Database=Blog;Trusted_Connection=True;MultipleActiveResultSets=true");

            return new BlogContext(builder.Options);
        }
    }

I have the Console Project as Startup and the Default Project the CL and when I run Add-Migrations Test, I get

System.ArgumentNullException: Value cannot be null.
Parameter name: contentRootPath
   at Microsoft.EntityFrameworkCore.Utilities.Check.NotEmpty(String value, String parameterName)
   at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations..ctor(IOperationReporter reporter, Assembly assembly, Assembly startupAssembly, String environment, String projectDir, String contentRootPath, String rootNamespace)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.<>c__DisplayClass4_0.<.ctor>b__4()
   at Microsoft.EntityFrameworkCore.Internal.LazyRef`1.get_Value()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Value cannot be null.

And if I set the CL as the Startup project, I get

Startup project 'Database' targets framework '.NETStandard'. This framework is not intended for execution and may fail to resolve runtime dependencies. If so, select a different startup project and try again.
To undo this action, use Remove-Migration.
Add-Migration : Exception calling "AddFromFile" with "1" argument(s): "'basePath' cannot be an empty string ("") or start with the null character.
Parameter name: basePath"
At line:1 char:1
+ Add-Migration Blog
+ ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Add-Migration], MethodInvocationException
    + FullyQualifiedErrorId : ArgumentException,Add-Migration

This was working fine but all of a sudden it isn't. All my nuget packages are from 5/9 so I am totally lost here.

@smitpatel
Copy link
Contributor

@isaac2004 - See #8731

@oldsand
Copy link

oldsand commented Oct 12, 2017

I got the same issue as well, I have try all the solutions mentioned above, and the issue still occurs.

@divega
Copy link
Contributor

divega commented Oct 13, 2017

@oldsand an issue with the same exception was reported again and we are tracking it at #10044. It would be great if you could help us repro it. Please reply there with repro steps and project.

@007souvikdas
Copy link

if u are facing issue in Package manager console, try using dotnet cli with the following commands:
for add migration:=>dotnet ef migrations add MyFirstMigration
and for update database:=> dotnet ef database update, it worked for me

@bricelam
Copy link
Contributor

Related issues: #14349 & #14781

@ajcvickers ajcvickers modified the milestones: 2.0.0-preview2, 2.0.0 Oct 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Projects
None yet
Development

No branches or pull requests