XbimGeometry icon indicating copy to clipboard operation
XbimGeometry copied to clipboard

Failed to load IFC file: failed to load Xbim.Geometry.Engine64.dll

Open andremansour opened this issue 1 year ago • 8 comments

I am trying to create a revit plugin using xbim. I want to load an ifc file to a model viewer using WPF and xbim however I am getting the following error:

Failed to load IFC file: failed to load Xbim.Geometry.Engine64.dll

here are the versions of the packages I am using:

Xbim.Common version=6.0.445 Xbim.Geometry version=5.1.437 Xbim.Geometry.Engine.Interop version=5.1.437 Xbim.Ifc version=6.0.445 Xbim.Ifc2x3 version=6.0.445 Xbim.Ifc4 version=6.0.445 Xbim.IO.MemoryModel version=6.0.445 Xbim.ModelGeometry.Scene version=5.1.437 Xbim.Tessellator version=6.0.445 Xbim.WindowsUI version=5.1.228

I have tried to add the Xbim.Geometry.Engine64.dll to the project but it still doesn't work.

here is my code for loading the ifc file:

xaml


<Window x:Class="BoundingBoxXYZExtraction.BoundingBoxForm"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
        xmlns:presentation="http://schemas.Xbim.com/Presentation"
        mc:Ignorable="d"
        x:Name="MainWindow"
        DataContext="{Binding RelativeSource={RelativeSource Self}}"
        Title="" Height="1080" Width="1920"
        Background="#FF2D2D30" TextElement.Foreground="#FFFFFF">

        <!-- Main Content Area for IFC Model Viewer -->
        <DockPanel Grid.Column="1" Grid.Row="2" Margin="0,0,0,0">
            <presentation:DrawingControl3D x:Name="DrawingControl" 
                               x:FieldModifier="public" 
                               Model="{Binding ModelProvider.ObjectInstance}" 
                               Focusable="True"
                               ModelOpacity="1"/>
        </DockPanel>


    </Grid>
</Window>

xaml.cs

using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using Octokit;
using LibGit2Sharp;
using System.Windows.Media.Imaging;
using System.Text.RegularExpressions;
using Xbim.Common;
using Xbim.Ifc;
using Xbim.Ifc4.Interfaces;
using Xbim.ModelGeometry.Scene;
using Microsoft.Extensions.Logging;
using Xbim.Presentation;
using GitHubRepo = Octokit.Repository;
using GitCredentials = Octokit.Credentials;
using GitHubBranch = Octokit.Branch;
using Newtonsoft.Json.Linq;
using Xbim.IO;
using System.Windows.Data;

namespace BoundingBoxXYZExtraction
{
    public partial class BoundingBoxForm : Window
    {

        private UIDocument _uiDoc;
        private ModelViewModel viewModel = new ModelViewModel();
        private const string SettingsFilePath = "appsettings.json";

        public event EventHandler<ProjectCreatedEventArgs> ProjectCreated;

        public BoundingBoxForm(ExternalCommandData commandData)
        {
            InitializeComponent();
            _uiDoc = commandData.Application.ActiveUIDocument;
            this.DataContext = viewModel;

        }


        private ObjectDataProvider ModelProvider
        {
            get
            {
                return MainFrame.DataContext as ObjectDataProvider;
            }
        }

        private void LoadIfcFile(string ifcFilePath)
        {
            try
            {
                if (!File.Exists(ifcFilePath))
                {
                    MessageBox.Show($"IFC file not found at {ifcFilePath}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                using (var model = IfcStore.Open(ifcFilePath))
                {
                    var context = new Xbim3DModelContext(model); // Updated constructor call 
                    context.CreateContext();

                    ModelProvider.ObjectInstance = context;  // Set to the context
                    ModelProvider.Refresh();
                }

                MessageBox.Show("IFC file loaded successfully.", "Success", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Failed to load IFC file: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
    }
}

andremansour avatar May 27 '24 20:05 andremansour

What is the exact error message?

martin1cerny avatar May 28 '24 09:05 martin1cerny

The exact message is "Failed to load IFC file: failed to load Xbim.Geometry.Engine64.dll"

andremansour avatar Jun 05 '24 22:06 andremansour

Which version of Revit is this? Or is it multiple?

I'm assuming you've ruled out the usual deployment issues that can cause this issue: https://github.com/xBimTeam/XbimGeometry/issues/312#issuecomment-778184952

In Revit is sometimes due to a clash of dependencies with other addins loaded into revit. E.g. your addin and another each use Microsoft.Extensions.Logging but with different versions and you can get assembly binding issues that cause the xbim dlls to fail to load. Try unloading other addins to test.

A useful tool to see what is going on is Microsoft's fuslogvw

andyward avatar Jun 06 '24 09:06 andyward

Sorry for the late response. I am using Revit 2024. Also, I have made sure that all my .dll files are up to par with the ones that Revit is using. Currently I am using addin manager and then loading up my addin using it. I tried using fuslogvw however nothing is coming up.

andremansour avatar Jun 10 '24 18:06 andremansour

Which version of Revit is this? Or is it multiple?

I'm assuming you've ruled out the usual deployment issues that can cause this issue: #312 (comment)

In Revit is sometimes due to a clash of dependencies with other addins loaded into revit. E.g. your addin and another each use Microsoft.Extensions.Logging but with different versions and you can get assembly binding issues that cause the xbim dlls to fail to load. Try unloading other addins to test.

A useful tool to see what is going on is Microsoft's fuslogvw

please check this error report. XbimError

andremansour avatar Jun 10 '24 21:06 andremansour

Are you sure you enabled fuslogvw? You need to turn it on to log failed assembly bindings.

You can't tell anything from that stack trace. Fuslogvw will tell you what assembly actually failed to bind. In all likelihood it is the ILogger though.

andyward avatar Jun 11 '24 08:06 andyward

The exact message is "Failed to load IFC file: failed to load Xbim.Geometry.Engine64.dll"

You may try also #312. This ensures to copy correct .dll in output folder after build. But your problem can be different.

I have tried to add the Xbim.Geometry.Engine64.dll to the project but it still doesn't work.

Make you sure that for this file you use property: <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> Or instead of PreserveNewest use Always.

Rachvel avatar Aug 27 '24 14:08 Rachvel

@andremansour Did you get this resolved?

andyward avatar Aug 30 '24 08:08 andyward