You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was runing a simple EF Core study with script files with the code bellow:
#!/usr/bin/env dotnet-script
#r "nuget: Microsoft.EntityFrameworkCore.Sqlite, 5.0.10"
#r "nuget: Microsoft.EntityFrameworkCore.Design, 5.0.10"
using Microsoft.EntityFrameworkCore;
Run();privatestaticvoidRun(){using(vardb=new BloggingContext()){
db.Database.Migrate();// Note: This sample requires the database to be created before running.
Console.WriteLine($"Database path: {db.DbPath}.");// Create
Console.WriteLine("Inserting a new blog");
db.Add(new Blog {Url="http://blogs.msdn.com/adonet"});
db.SaveChanges();// Read
Console.WriteLine("Querying for a blog");varblog= db.Blogs
.OrderBy(b => b.BlogId).First();// Update
Console.WriteLine("Updating the blog and adding a post");
blog.Url ="https://devblogs.microsoft.com/dotnet";
blog.Posts.Add(new Post {Title="Hello World",Content="I wrote an app using EF Core!"});
db.SaveChanges();// Delete
Console.WriteLine("Delete the blog");
db.Remove(blog);
db.SaveChanges();}}publicclassBloggingContext:DbContext{publicDbSet<Blog> Blogs {get;set;}publicDbSet<Post> Posts {get;set;}publicstringDbPath{get;privateset;}publicBloggingContext(){varfolder= Environment.SpecialFolder.LocalApplicationData;varpath= Environment.GetFolderPath(folder);DbPath=$"{path}{System.IO.Path.DirectorySeparatorChar}blogging.db";}// The following configures EF to create a Sqlite database file in the// special "local" folder for your platform.protectedoverridevoidOnConfiguring(DbContextOptionsBuilderoptions)=> options.UseSqlite($"Data Source={DbPath}");}publicclassBlog{publicintBlogId{get;set;}publicstringUrl{get;set;}publicList<Post> Posts {get;}=newList<Post>();}publicclassPost{publicintPostId{get;set;}publicstringTitle{get;set;}publicstringContent{get;set;}publicintBlogId{get;set;}publicBlogBlog{get;set;}}
When I execute dotnet script main.csx the flowing error appears:
System.IO.FileLoadException: Could not load file or assembly 'Microsoft.Extensions.DependencyInjection, Version=5.0.0.1, Culture=neutral, PublicKeyToken=adb9793829ddae60'. Could not find or load a specific file. (0x80131621)
File name: 'Microsoft.Extensions.DependencyInjection, Version=5.0.0.1, Culture=neutral, PublicKeyToken=adb9793829ddae60'
---> System.IO.FileLoadException: Could not load file or assembly 'Microsoft.Extensions.DependencyInjection, Version=5.0.0.1, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
at System.Runtime.Loader.AssemblyLoadContext.LoadFromPath(IntPtr ptrNativeAssemblyLoadContext, String ilPath, String niPath, ObjectHandleOnStack retAssembly)
at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath)
at System.Reflection.Assembly.LoadFrom(String assemblyFile)
at System.Reflection.Assembly.LoadFromResolveHandler(Object sender, ResolveEventArgs args)
at System.Runtime.Loader.AssemblyLoadContext.InvokeResolveEvent(ResolveEventHandler eventHandler, RuntimeAssembly assembly, String name)
at System.Runtime.Loader.AssemblyLoadContext.OnAssemblyResolve(RuntimeAssembly assembly, String assemblyFullName)
at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.<>c__DisplayClass4_0.<GetOrAdd>g__BuildServiceProvider|3()
at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.<>c__DisplayClass4_0.<GetOrAdd>b__2(Int64 k)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.GetOrAdd(IDbContextOptions options, Boolean providerRequired)
at Microsoft.EntityFrameworkCore.DbContext..ctor(DbContextOptions options)
at Microsoft.EntityFrameworkCore.DbContext..ctor()
at Submission#0.BloggingContext..ctor() in /workspace/ef-core-sample/main.csx:line 49
at Submission#0.Run() in /workspace/ef-core-sample/main.csx:line 10
at Submission#0.<<Initialize>>d__0.MoveNext() in /workspace/ef-core-sample/main.csx:line 6
--- End of stack trace from previous location ---
at Dotnet.Script.Core.ScriptRunner.Execute[TReturn](String dllPath, IEnumerable`1 commandLineArgs) in C:\Users\VssAdministrator\AppData\Local\Temp\tmpBFB\Dotnet.Script.Core\ScriptRunner.cs:line 110
Probably I'm doing something wrong, could somebody help me?
The text was updated successfully, but these errors were encountered:
Hello,
I was runing a simple EF Core study with script files with the code bellow:
When I execute
dotnet script main.csx
the flowing error appears:Probably I'm doing something wrong, could somebody help me?
The text was updated successfully, but these errors were encountered: