Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Missing System.ComponentModel.Annotations v4.2.0.0

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
stevenpulsipher
5821 Views, 4 Replies

Missing System.ComponentModel.Annotations v4.2.0.0

Setup:

In my project directory I have a reference set up to use System.ComponentModel.Annotations v4.2.1.0 and it is being copied to local.

In my app.config file I have the following binding redirect for System.ComponentModel.Annotations: "<bindingRedirect oldVersion="0.0.0.0-4.2.1.0" newVersion="4.2.1.0" />"

 

My project is set up as an application plugin that launches my application when a button is clicked from the ribbon panel in the addins section of revit. I know that I have that set up correctly because it has run correctly prior to my latest addition (which involves Entity Framework reading/writing to a database). I have a class that extends DBContext stored in the variable _context. When I first initialize _context I immediately run the command _context.Database.Migrate(). Upon running this command I get the error below. This issue only occurs when i run this application through revit. I have a standalone application that runs outside of Revit and makes the exact same calls that doesn't have any problem finding/loading System.ComponentModel.Annotations. I'm not sure why my application can't load this dependency when running through Revit, but can through my standalone project (both of which have identical references). Does anyone have any ideas on how to fix this?

 

System.IO.FileNotFoundException
  HResult=0x80070002
  Message=Could not load file or assembly 'System.ComponentModel.Annotations, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
  Source=Microsoft.EntityFrameworkCore
  StackTrace:
   at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.CoreConventionSetBuilder.CreateConventionSet()
   at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.CreateConventionSet(IConventionSetBuilder conventionSetBuilder)
   at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.CreateModel(DbContext context, IConventionSetBuilder conventionSetBuilder, IModelValidator validator)
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.LazyInitValue()
   at Microsoft.EntityFrameworkCore.Internal.DbContextServices.CreateModel()
   at Microsoft.EntityFrameworkCore.Internal.DbContextServices.get_Model()
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine.<>c__DisplayClass1_0.<RealizeService>b__0(ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
   at Microsoft.EntityFrameworkCore.DbContext.get_DbContextDependencies()
   at Microsoft.EntityFrameworkCore.DbContext.get_InternalServiceProvider()
   at Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.GetRelationalService[TService](IInfrastructure`1 databaseFacade)
   at Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.Migrate(DatabaseFacade databaseFacade)
   at BT.Data.Repo.FacilityRepo.RunMigrations() in C:\Views\Plugins\LifeSciences\BT.Data.Repo\FacilityRepo.cs:line 66
   at BT.Controller.Controller.RunMigration() in C:\Views\Plugins\LifeSciences\BT.Controller\Controller.cs:line 118
   at BT.Controller.Controller..ctor() in C:\Views\Plugins\LifeSciences\BT.Controller\Controller.cs:line 83
   at BT.Controller.Interfaces.SController.get_Controller() in C:\Views\Plugins\LifeSciences\BT.Controller\Interfaces\SController.cs:line 30
   at BT.LifeSciencesPlugin.Views.LifeSciencesView..ctor() in C:\Views\Plugins\LifeSciences\BT.LifeSciencesPlugin\Views\LifeSciencesView.xaml.cs:line 66
   at BT.LifeSciencesPlugin.LifeSciencesPlugin..ctor() in C:\Views\Plugins\LifeSciences\BT.LifeSciencesPlugin\LifeSciencesPlugin.cs:line 77

4 REPLIES 4
Message 2 of 5

Is this the same issue as in your other thread?

 

https://forums.autodesk.com/t5/revit-api-forum/fails-to-load-dependencies/td-p/8227232

 

In that case, can we assume that it is now resolved as well?

 

Thank you!

 

Cheers,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 5

Although this is similar to my previous post, the solution that I used for that one did not solve the problem for this one.

Message 4 of 5

I still haven't  been able to get this working.

Message 5 of 5
JimJia
in reply to: stevenpulsipher

You may try to force to load the assembly if it cannot be loaded successfully, please refer to code snippet below,this should be safe solution, per my experience; hope it can be helpful:

        Result IExternalCommand.Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            // Try to load assembly if Revit command fails to load it.
            AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CommandLoad_AssemblyResolve);
			//
			// your other code...
		}
		
		private Assembly CommandLoad_AssemblyResolve(object sender, ResolveEventArgs args)
        {
		   if(args.Name.Contains("ComponentModel.Annotations"))
		   {
		      string assemblyFile = Path.Combine(addinDir, "ComponentModel.Annotations.dll");
			  if(File.Exists(assemblyFile))
			     return return Assembly.LoadFrom(assemblyFile);		   
		   }
		}

 


Jim Jia
Autodesk Forge Evangelist
https://forge.autodesk.com
Developer Technical Services
Autodesk Developer Network
Email: Jim.Jia@autodesk.com

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community