aspnet/DependencyInjection

ServiceProvider.GetService<MyAppContext>() can not get an assembly that has already been loaded in AppDmain.

JohnHe404 opened this issue · 1 comments

dotnet/efcore#8181

Describe what is not working as expected.

If you are seeing an exception, include the full exceptions details (message and stack trace).

I'm Develop one WPF App.

All assembly in project->Resources->Embed resources
Then use it EF Core DependencyInjection->serviceScope.ServiceProvider.GetService()
But I get a System.IO.FileNotFoundException.

Exception message:
System.IO.FileNotFoundException:“未能加载文件或程序集“MyApp.Services, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null”或它的某一个依赖项。系统找不到指定的文件。”
Stack trace:


### Steps to reproduce
Include a complete code listing (or project/solution) that we can run to reproduce the issue.

Partial code listings, or multiple fragments of code, will slow down our response or cause us to push the issue back to you to provide code to reproduce the issue.

```c#
<code listing>
`List<Assembly> CurrentAssemblies = AppDomain.CurrentDomain.GetAssemblies().ToList<Assembly>();`
`Assembly ExecutingAssembly = **Assembly.GetExecutingAssembly();`
`if (CurrentAssemblies.Where(a => item.IndexOf(a.ManifestModule.ScopeName) > -1).Any())
                    continue;
                using (var stream = ExecutingAssembly.GetManifestResourceStream(item))
                {
                    byte[] bt = new byte[stream.Length];
                    stream.Read(bt, 0, bt.Length);
                    var assembly = Assembly.Load(bt);
                    CurrentAssemblies.Add(assembly);
                }`
If the program is copied separately to another folder,I get a error.
 serviceScope.ServiceProvider.GetService<MyAppContext>() 

Further technical details

EF Core version: 1.1.1.0
Database Provider: (EntityFrameworkCore.SqlServerCompact40)
Operating system: windows10
IDE: VS2017 Community Edition

Very Thx,I'm success Run the program.EF Core can give assembly has been loaded in AppDmain.I'm use WPF+EF core Developed the program only one .exe file.It was a great moment for me.