Author Topic: WPF UserControl crashes AutoCAD  (Read 256 times)

0 Members and 1 Guest are viewing this topic.

Keith Brown

  • Swamp Rat
  • Posts: 601
WPF UserControl crashes AutoCAD
« on: March 25, 2020, 04:41:49 PM »
I have an application that replaces the AutoCAD tooltips with my own custom tooltips.  Recently in AutoCAD the application will crash when trying to create the wpf user control.  Basically, the user control is an empty container that I am populating at runtime, however the control crashes AutoCAD when I new it up with this line.  (Sorry its an old application and in VB.NET)

Code - Visual Basic: [Select]
  1. Dim worxBoxToolTip = New WorxBoxToolTip()

The usercontrol itself has an empty constructor and in fact an empty class.

Code - Visual Basic: [Select]
  1. Public Class WorxBoxToolTip
  4. End Class

The xml for the control is :

Code: [Select]
<UserControl x:Class="WorxBoxToolTip"
             d:DesignHeight="300" d:DesignWidth="300">
    <Grid x:Name="RootGrid" HorizontalAlignment="Left" VerticalAlignment="Top">
        <TextBlock x:Name="ViewName" TextWrapping="Wrap" Text="View Name" Margin ="10,10,10,10" FontWeight="Bold" HorizontalAlignment="Left" VerticalAlignment="Top"></TextBlock>
        <DockPanel x:Name="LineContainer" HorizontalAlignment="Left" Margin="10,30,10,10" VerticalAlignment="Top">
            <StackPanel x:Name="StackPanelName" Orientation="Vertical" VerticalAlignment="Top" MaxWidth="290" />
            <WrapPanel x:Name="StackPanelValue" Orientation="Vertical" VerticalAlignment="Top" />

When the code tries to new up the control it throws the following error:

Code: [Select]
System.IO.FileNotFoundException: 'Could not load file or assembly 'VIEWWorx, Version=2019.2.259.1223, Culture=neutral' or one of its dependencies. The system cannot find the file specified.'

Now obviously it can find the dll as it is the one currently loaded.  What is crazy is the version of the dll is incorrect.  The current version loaded is 2020.x.x.x.  There is no way i could reference an earlier version as it would be a circular reference.

Any ideas?
« Last Edit: March 25, 2020, 04:52:47 PM by Keith Brown »
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013


  • Villiage Idiot
  • Seagull
  • Posts: 16776
  • Superior Stupidity at its best
Re: WPF UserControl crashes AutoCAD
« Reply #1 on: March 25, 2020, 05:11:22 PM »
I am just gonna throw some things out there to check:

Check the references in every project in the solution.
Make sure you are actually grabbing the correct build (I know sounds silly) but VS has a way of creating multiple destinations for the build.
Have you ever autoloaded the project such that there is a reference to an old path? I have a tendency to keep my old executables for those "just in case" moments. Usually I find the autoloader is pointing to folder\version12\ when it should be pointing to folder\version13\.

Anyway, I know its not much, because that you have shown is golden, don't have much to go on except the speculative.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: WPF UserControl crashes AutoCAD
« Reply #2 on: March 25, 2020, 05:23:26 PM »
Yup,  I checked all of the references.  What I have ended up doing is adding a resolve event handler so that if the code cannot find itself then it just returns itself.  Sounds stupid but it works.  I went with Name.StartsWith  so if by some unknown reason the version it is looking for changes it will still work.  I have spent almost a day trying to track this down and I am tired of looking so going with this.

Code - Visual Basic: [Select]
  1.      AddHandler currentDomain.AssemblyResolve, AddressOf ResolveWorxToolsHandler
  3.     Private Function ResolveWorxToolsHandler(sender As Object, args As ResolveEventArgs) As Assembly
  4.         If (args.Name.StartsWith("VIEWWorx,")) Then
  5.             Return Assembly.GetExecutingAssembly()
  6.         End If
  7.         Return Nothing
  8.     End Function

** EDIT **

If anyone comes back to this looking for a solution, make sure you add a comma after the dll name that you are looking for.  If not it will also fire when looking for the dll resources named "VIEWWorx.resources".  The comma will stop that from happening.
« Last Edit: March 25, 2020, 05:35:43 PM by Keith Brown »
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013