I have a UWP project that uses Win2D. When I attempt to generate a migration with EF the migration will fail with the following error.
System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.RuntimeAssembly.get_DefinedTypes()
at Microsoft.Data.Entity.Design.Internal.StartupInvoker..ctor(String startupAssemblyName, String environment)
at Microsoft.Data.Entity.Design.DbContextOperations..ctor(ILoggerProvider loggerProvider, String assemblyName, String startupAssemblyName, String environment)
at Microsoft.Data.Entity.Design.MigrationsOperations..ctor(ILoggerProvider loggerProvider, String assemblyName, String startupAssemblyName, String environment, String projectDir, String rootNamespace)
at Microsoft.Data.Entity.Design.OperationExecutor.<>c__DisplayClass3_0.<.ctor>b__3()
at Microsoft.Data.Entity.Internal.LazyRef1.get_Value() at Microsoft.Data.Entity.Design.OperationExecutor.<AddMigrationImpl>d__7.MoveNext() at System.Linq.Buffer1..ctor(IEnumerable1 source) at System.Linq.Enumerable.ToArray[TSource](IEnumerable1 source)
at Microsoft.Data.Entity.Design.OperationExecutor.OperationBase.<>c__DisplayClass4_0`1.b__0()
at Microsoft.Data.Entity.Design.OperationExecutor.OperationBase.Execute(Action action)
Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
This is due to the use of CanvasBitmap.LoadAsync() from Win2D. Any use of that method will prevent migrations from being generated. I have created a sample project demoing this. You can find it here
I have posted this on the Win2D GitHub as well https://github.com/Microsoft/Win2D/issues/290
Note for triage: The call is in MainPage.xaml.cs - so not a code path that is hit when instantiating the context to get the model.
I have the same problem if I have a UserControl that includes CanvasBitmap.LoadAsync in it's code behind:
private async Task CreateResourcesAsync(CanvasControl sender)
{
// Comment the following line when running migrations
if (BackgroundImageSource != null)
{
_backgroundBitmap =
await CanvasBitmap.LoadAsync(sender, ((BitmapImage) BackgroundImageSource).UriSource);
_blurEffect = new GaussianBlurEffect
{
Source = _backgroundBitmap,
BlurAmount = BlurFactor
};
}
}
This looks like a dupe of #3803. Unfortunately UWP is broken on the nightly build, so we can't really confirm that this is fixed yet...
"dependencies": {
"EntityFramework.Commands": "7.0.0-rc1-final",
"EntityFramework.SQLite": "7.0.0-rc1-final",
"Microsoft.ApplicationInsights": "1.2.3",
"Microsoft.ApplicationInsights.PersistenceChannel": "1.2.3",
"Microsoft.ApplicationInsights.WindowsApps": "1.1.1",
"Microsoft.Azure.Mobile.Client": "2.0.1",
"Microsoft.Azure.Mobile.Client.SQLiteStore": "2.0.1",
"Microsoft.NETCore.UniversalWindowsPlatform": "5.0.0",
"Newtonsoft.Json": "8.0.2",
"NotificationsExtensions.Win10": "10586.0.2",
"Win2D.uwp": "1.15.0"
@darenm Thanks, I realized you included a full repro and quickly withdrew my question. :wink:
I wonder if VS 2015 Update 2 CTP would work (without .NET Native) with our nightly build...
We'll give that a shot. BTW - this code is destined for some important labs at the end of the month...
@bricelam to verify once we are able to use latest builds again
Are the latest builds still busted for UWP? We're getting a type loader error, now related to adding the Windows Mobile Extensions for UWP...
@darenm yep the packages won't even install on UWP at the moment. Unfortunately, even when things start working, I think you are going to have to wait for an update to UWP tooling before you can use them.
At least we know to comment out the offending references and we can move forward:
// private static async Task<PhoneLine> GetDefaultPhoneLineAsync()
// {
// var phoneCallStore = await PhoneCallManager.RequestStoreAsync();
// var lineId = await phoneCallStore.GetDefaultLineAsync();
// return await PhoneLine.FromIdAsync(lineId);
// }
@darenm @geoffmmorgan any luck with WIn2D issue that you mentioned above.. i lost good time trying to fix EF .. when the issue was caused due to Win2D.. code of LoadAsync on CanvasBitmat. I have the same line and when i commented this like the Migration started working again.. .. Any solutions so far for this issue? Anything is much appreciated
@MMalikKhan So, the simplest workaround we have is:
Whenever you want to add-migration, switch your startup project to the dummy app that doesn't have any offensive code from Win2D, Mobile Extensions, etc. As all your models and dbcontext are in the library, when you are in the Package Manager Console you need to change the Default project drop down to target the library
Note: You need to install the command package in both the App and the Library
Note2: We are seeing the Command package locking the APPX after we create migrations, uninstalling the Commands package and restarting VS clears this. See issue #4997 for more details.
I have verified this issue still exists with RC2. I have updated my original sample to RC2 binaries https://github.com/geoffmmorgan/MigrationTest/tree/master