Simulate 2022 gives error loading Navisworks.Api.Controls

Simulate 2022 gives error loading Navisworks.Api.Controls

DeanLyon2
Contributor Contributor
1,290 Views
7 Replies
Message 1 of 8

Simulate 2022 gives error loading Navisworks.Api.Controls

DeanLyon2
Contributor
Contributor

I am rewriting an application for use with Simulate 2022. It compiles and works against 2019.  I have updated my references to point at the 2022 versions of the DLLs (assemblies). However, I am getting an error when I run the program when it hits this line: 

Autodesk.Navisworks.Api.Controls.ApplicationControl.ApplicationType = ApplicationType.SingleDocument;

The error says System.IO.FileNotFoundException: can not load file or assembly Autodesk.Navisworks.Api.dll or one of its dependencies. I have tried .Net 4.7, 4.7..1, 4.7.2, and 4.8.  This is a console application that combines DWG files into a Navisworks model.  Just trying to make it work with Simulate 2022.

0 Likes
Accepted solutions (1)
1,291 Views
7 Replies
Replies (7)
Message 2 of 8

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @DeanLyon2 ,

 

Maybe you can try by changing the "Copy Local" value of Navisworks dlls.

 

If the above suggestion doesn't help, then, Could you please send us a simple non-confidential reproducible visual studio project and a step-by-step approach to reproduce the issue?


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 8

DeanLyon2
Contributor
Contributor

All of the Autodesk references are set to True for Copy Local. I have attached an example that produces the same error. I do have this code in another module than Main but it produces the same error when run from Main.

0 Likes
Message 4 of 8

DeanLyon2
Contributor
Contributor

I have installed Visual Studio 2022 and it gives the same errors.

0 Likes
Message 5 of 8

DeanLyon2
Contributor
Contributor

If I set the .NET to lower than 4.7. I do get the error that Navisworks.Api.Controls needs .NET 4.7  When I compile and run at 4.7 I get the error that Navisworks.Api.Controls can not run.

0 Likes
Message 6 of 8

naveen.kumar.t
Autodesk Support
Autodesk Support
Accepted solution

Hi @DeanLyon2 ,

 

Sorry for the delay.

I tested your application. I have no clue what is causing the issue in your application.

I created my own console application and copy-pasted the sample code which is present in your application. My console application is working fine.

 

I would suggest you create a new project and test it.

 

Here are the steps I followed

 

1)I created a console application.
2)I added the required dlls to my console visual studio project(NW Simulate 2022).
3)I set "Autodesk.Navisworks.Resolver" copy the local value to "True".For other dlls, I set copy the local value to "False"
4) Right-click your project in solution explorer--> Properties --> Build -->Platform target-->Set "x64"
5)Now everything worked fine for me.

 

Here is the sample code I used

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using Autodesk.Navisworks.Api;
using Autodesk.Navisworks.Api.ApplicationParts;
using Autodesk.Navisworks.Api.Controls;
using Autodesk.Navisworks.Api.DocumentParts;
using Autodesk.Navisworks.Api.Plugins;
using Autodesk.Navisworks.Api.Resolver;
using Autodesk.Navisworks.Api.Data;
namespace Simple_Console
{
    class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            //BuildModel cmb = new BuildModel();
            String runtimeName = Resolver.TryBindToRuntime(RuntimeNames.NavisworksSimulate);
            if (String.IsNullOrEmpty(runtimeName)) { throw new Exception("Failed to bind to Navisworks runtime"); }
            //cmb.BuildCompositeModel(PlantCode, RemoveList, IncludeList);
            //cmb = null;

            try
            {
                XMain(args);
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message);
            }
        }

        private static void XMain(string[] args)
        {
            List<Model> ModelList = new List<Model>();
            Autodesk.Navisworks.Api.Automation.NavisworksApplication oApp = null;
            Autodesk.Navisworks.Api.Controls.ApplicationControl.ApplicationType = ApplicationType.SingleDocument;
            Autodesk.Navisworks.Api.Application.FileInteractiveResolving += Application_FileInteractiveResolving;
            Autodesk.Navisworks.Api.Application.FileResolving += Application_FileResolving;
            ApplicationControl.Initialize();
            DocumentControl documentCtrl = new DocumentControl();
            documentCtrl.SetAsMainDocument();

            Console.WriteLine("End");
            Console.ReadKey();
        }

        private static void Application_FileResolving(object sender, FileResolvingEventArgs e)
        {
            e.Handled = true;
        }

        private static void Application_FileInteractiveResolving(object sender, FileInteractiveResolvingEventArgs e)
        {
            e.Handled = true;
        }
    }
}

Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 7 of 8

DeanLyon2
Contributor
Contributor

.NET 4.7 is correct. Copy Local is True on Resolver and False on the other Navisworks references.  These settings made the issue go away.  Thank you so much. I was banging my head against a wall on this one.

0 Likes
Message 8 of 8

gustavo_sanches7ZZVWX
Observer
Observer

hi! I am having the same trouble, i followed everything it was discussed here. But nothing was solved. Does anyone has any other suggetion what could it be?

0 Likes