2014-12-04 104 views
3

我已經編寫了一個AutoCAD插件,用於根據用戶選擇的表單項顯示圖像。圖像的一個例子被稱爲顯示將AutoCAD插件無法找到資源

previewBox.Image = System.Drawing.Image.FromFile("Window Width.PNG"); 

然而,即使PNG文件是在同一目錄作爲我的.dll文件,我得到一個錯誤,說像無法找到。下面是我得到的完整錯誤文本。

Application does not support just-in-time (JIT) debugging. See the end of this message for details. 

************** Exception Text ************** 
System.IO.FileNotFoundException: Window Height.PNG 
    at System.Drawing.Image.FromFile(String filename, Boolean useEmbeddedColorManagement) 
    at WindowsAndDoorsPlugin.WindowsDoors.heightBox_isClicked(Object sender, EventArgs e) 
    at System.Windows.Forms.Control.OnClick(EventArgs e) 
    at System.Windows.Forms.TextBoxBase.OnMouseUp(MouseEventArgs mevent) 
    at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) 
    at System.Windows.Forms.Control.WndProc(Message& m) 
    at System.Windows.Forms.TextBoxBase.WndProc(Message& m) 
    at System.Windows.Forms.TextBox.WndProc(Message& m) 
    at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) 
    at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) 
    at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) 


************** Loaded Assemblies ************** 
mscorlib 
    Assembly Version: 4.0.0.0 
    Win32 Version: 4.0.30319.18444 built by: FX451RTMGDR 
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll 
---------------------------------------- 
Acdbmgd 
    Assembly Version: 19.1.0.0 
    Win32 Version: 19.1.18.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202014/AcdbMgd.DLL 
---------------------------------------- 
System 
    Assembly Version: 4.0.0.0 
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL 
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll 
---------------------------------------- 
System.Core 
    Assembly Version: 4.0.0.0 
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL 
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll 
---------------------------------------- 
AdApplicationFrame 
    Assembly Version: 0.0.0.0 
    Win32 Version: 4.0.19.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202014/AdApplicationFrame.DLL 
---------------------------------------- 
AdWindows 
    Assembly Version: 4.0.24.0 
    Win32 Version: 4.0.24.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202014/AdWindows.DLL 
---------------------------------------- 
PresentationFramework 
    Assembly Version: 4.0.0.0 
    Win32 Version: 4.0.30319.18408 
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/PresentationFramework/v4.0_4.0.0.0__31bf3856ad364e35/PresentationFramework.dll 
---------------------------------------- 
WindowsBase 
    Assembly Version: 4.0.0.0 
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL 
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/WindowsBase/v4.0_4.0.0.0__31bf3856ad364e35/WindowsBase.dll 
---------------------------------------- 
PresentationCore 
    Assembly Version: 4.0.0.0 
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL 
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_32/PresentationCore/v4.0_4.0.0.0__31bf3856ad364e35/PresentationCore.dll 
---------------------------------------- 
System.Xaml 
    Assembly Version: 4.0.0.0 
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL 
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xaml/v4.0_4.0.0.0__b77a5c561934e089/System.Xaml.dll 
---------------------------------------- 
System.Xml 
    Assembly Version: 4.0.0.0 
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL 
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll 
---------------------------------------- 
PresentationFramework.Classic 
    Assembly Version: 4.0.0.0 
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL 
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/PresentationFramework.classic/v4.0_4.0.0.0__31bf3856ad364e35/PresentationFramework.classic.dll 
---------------------------------------- 
System.Drawing 
    Assembly Version: 4.0.0.0 
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL 
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll 
---------------------------------------- 
accoremgd 
    Assembly Version: 19.1.0.0 
    Win32 Version: 19.1.18.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202014/accoremgd.DLL 
---------------------------------------- 
Acmgd 
    Assembly Version: 19.1.0.0 
    Win32 Version: 19.1.18.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202014/Acmgd.DLL 
---------------------------------------- 
System.Configuration 
    Assembly Version: 4.0.0.0 
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL 
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll 
---------------------------------------- 
AcWindows 
    Assembly Version: 19.1.0.0 
    Win32 Version: 19.1.18.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202014/AcWindows.DLL 
---------------------------------------- 
AcCui 
    Assembly Version: 19.1.0.0 
    Win32 Version: 19.1.18.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202014/AcCui.DLL 
---------------------------------------- 
PresentationFramework-SystemXml 
    Assembly Version: 4.0.0.0 
    Win32 Version: 4.0.30319.18408 
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/PresentationFramework-SystemXml/v4.0_4.0.0.0__b77a5c561934e089/PresentationFramework-SystemXml.dll 
---------------------------------------- 
PresentationFramework.Aero 
    Assembly Version: 4.0.0.0 
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL 
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/PresentationFramework.Aero/v4.0_4.0.0.0__31bf3856ad364e35/PresentationFramework.Aero.dll 
---------------------------------------- 
WindowsFormsIntegration 
    Assembly Version: 4.0.0.0 
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL 
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/WindowsFormsIntegration/v4.0_4.0.0.0__31bf3856ad364e35/WindowsFormsIntegration.dll 
---------------------------------------- 
AcWindows.resources 
    Assembly Version: 19.1.0.0 
    Win32 Version: 19.1.18.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202014/en-US/AcWindows.resources.DLL 
---------------------------------------- 
System.Windows.Forms 
    Assembly Version: 4.0.0.0 
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL 
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll 
---------------------------------------- 
PresentationUI 
    Assembly Version: 4.0.0.0 
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL 
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/PresentationUI/v4.0_4.0.0.0__31bf3856ad364e35/PresentationUI.dll 
---------------------------------------- 
System.Xml.Linq 
    Assembly Version: 4.0.0.0 
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL 
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml.Linq/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.Linq.dll 
---------------------------------------- 
PresentationFramework-SystemXmlLinq 
    Assembly Version: 4.0.0.0 
    Win32 Version: 4.0.30319.18408 
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/PresentationFramework-SystemXmlLinq/v4.0_4.0.0.0__b77a5c561934e089/PresentationFramework-SystemXmlLinq.dll 
---------------------------------------- 
FeaturedAppsPlugin 
    Assembly Version: 19.0.0.0 
    Win32 Version: 19.0.55.0.0 
    CodeBase: file:///C:/ProgramData/Autodesk/ApplicationPlugins/Autodesk%20FeaturedApps.bundle/Contents/Windows/2014/FeaturedAppsPlugin.dll 
---------------------------------------- 
ContextualTabSelectorRules 
    Assembly Version: 0.0.0.0 
    Win32 Version: 19.1.18.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202014/AcWindows.dll 
---------------------------------------- 
PresentationFramework-SystemCore 
    Assembly Version: 4.0.0.0 
    Win32 Version: 4.0.30319.18408 
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/PresentationFramework-SystemCore/v4.0_4.0.0.0__b77a5c561934e089/PresentationFramework-SystemCore.dll 
---------------------------------------- 
Microsoft.Expression.Interactions 
    Assembly Version: 4.0.0.0 
    Win32 Version: 2.0.20520.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202014/Microsoft.Expression.Interactions.DLL 
---------------------------------------- 
ManagedMC3 
    Assembly Version: 7.2.0.0 
    Win32 Version: 7.2.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202014/ManagedMC3.DLL 
---------------------------------------- 
UIAutomationTypes 
    Assembly Version: 4.0.0.0 
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL 
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/UIAutomationTypes/v4.0_4.0.0.0__31bf3856ad364e35/UIAutomationTypes.dll 
---------------------------------------- 
AcTaskDialogs 
    Assembly Version: 19.1.0.0 
    Win32 Version: 19.1.18.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202014/AcTaskDialogs.DLL 
---------------------------------------- 
AcTaskDialogs.resources 
    Assembly Version: 19.1.0.0 
    Win32 Version: 19.1.18.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202014/en-US/AcTaskDialogs.resources.DLL 
---------------------------------------- 
AutoCAD CSharp plug-in4 
    Assembly Version: 1.0.5421.29773 
    Win32 Version: 1.0.0.0 
    CodeBase: file:///C:/Users/Administrator/AppData/Roaming/Autodesk/ApplicationPlugins/Clearspan.bundle/Contents/Windows/ShowHideLayers.dll 
---------------------------------------- 
WindowsAndDoorsPlugin 
    Assembly Version: 1.0.5451.27174 
    Win32 Version: 1.0.0.0 
    CodeBase: file:///C:/Users/Administrator/AppData/Roaming/Autodesk/ApplicationPlugins/Clearspan.bundle/Contents/Windows/WindowsDoorsTool.dll 
---------------------------------------- 
AcAeNet.resources 
    Assembly Version: 19.1.0.0 
    Win32 Version: 19.1.18.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202014/en-US/AcAeNet.resources.DLL 
---------------------------------------- 
AcButterflyExt.resources 
    Assembly Version: 19.1.0.0 
    Win32 Version: 19.1.18.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202014/en-US/AcButterflyExt.resources.DLL 
---------------------------------------- 
AcCloudRender.resources 
    Assembly Version: 19.1.0.0 
    Win32 Version: 19.1.18.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202014/en-US/AcCloudRender.resources.DLL 
---------------------------------------- 
AcCustomize.resources 
    Assembly Version: 19.1.0.0 
    Win32 Version: 19.1.18.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202014/en-US/AcCustomize.resources.DLL 
---------------------------------------- 
AcDxWizard.resources 
    Assembly Version: 19.1.0.0 
    Win32 Version: 19.1.18.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202014/en-US/AcDxWizard.resources.DLL 
---------------------------------------- 
AcExportLayoutUI.resources 
    Assembly Version: 19.1.0.0 
    Win32 Version: 19.1.18.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202014/en-US/AcExportLayoutUI.resources.DLL 
---------------------------------------- 
AcInterfere.resources 
    Assembly Version: 19.1.0.0 
    Win32 Version: 19.1.18.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202014/en-US/AcInterfere.resources.DLL 
---------------------------------------- 
AcLayer.resources 
    Assembly Version: 19.1.0.0 
    Win32 Version: 19.1.18.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202014/en-US/AcLayer.resources.DLL 
---------------------------------------- 
AcLayerTools.resources 
    Assembly Version: 19.1.0.0 
    Win32 Version: 19.1.18.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202014/en-US/AcLayerTools.resources.DLL 
---------------------------------------- 
AcMrUi.resources 
    Assembly Version: 19.1.0.0 
    Win32 Version: 19.1.18.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202014/en-US/AcMrUi.resources.DLL 
---------------------------------------- 
AcMultiLineUi.resources 
    Assembly Version: 19.1.0.0 
    Win32 Version: 19.1.18.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202014/en-US/AcMultiLineUi.resources.DLL 
---------------------------------------- 
AcRecoverAll.resources 
    Assembly Version: 19.1.0.0 
    Win32 Version: 19.1.18.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202014/en-US/AcRecoverAll.resources.DLL 
---------------------------------------- 
AcScaleList.resources 
    Assembly Version: 19.1.0.0 
    Win32 Version: 19.1.18.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202014/en-US/AcScaleList.resources.DLL 
---------------------------------------- 
AcUnderlay.resources 
    Assembly Version: 19.1.0.0 
    Win32 Version: 19.1.18.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202014/en-US/AcUnderlay.resources.DLL 
---------------------------------------- 
AcViewTransitionsUi.resources 
    Assembly Version: 19.1.0.0 
    Win32 Version: 19.1.18.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202014/en-US/AcViewTransitionsUi.resources.DLL 
---------------------------------------- 
AdskConnectionPointMgd.resources 
    Assembly Version: 1.0.0.0 
    Win32 Version: 19.1.18.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202014/en-US/AdskConnectionPointMgd.resources.DLL 
---------------------------------------- 
AcCalcUi.resources 
    Assembly Version: 19.1.0.0 
    Win32 Version: 19.1.18.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202014/en-US/AcCalcUi.resources.DLL 
---------------------------------------- 
AcLivePreviewContext 
    Assembly Version: 0.0.0.0 
    Win32 Version: 19.1.18.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202014/AcWindows.dll 
---------------------------------------- 
AcLayer 
    Assembly Version: 19.1.0.0 
    Win32 Version: 19.1.18.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202014/AcLayer.DLL 
---------------------------------------- 
PresentationFramework.Luna 
    Assembly Version: 4.0.0.0 
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL 
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/PresentationFramework.Luna/v4.0_4.0.0.0__31bf3856ad364e35/PresentationFramework.Luna.dll 
---------------------------------------- 
AcMrUi 
    Assembly Version: 19.1.0.0 
    Win32 Version: 19.1.18.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202014/AcMrUI.DLL 
---------------------------------------- 
FeaturedAppsPlugin.resources 
    Assembly Version: 19.0.0.0 
    Win32 Version: 19.0.55.0.0 
    CodeBase: file:///C:/ProgramData/Autodesk/ApplicationPlugins/Autodesk%20FeaturedApps.bundle/Contents/Resources/en-US/FeaturedAppsPlugin.resources.dll 
---------------------------------------- 
UIAutomationProvider 
    Assembly Version: 4.0.0.0 
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL 
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/UIAutomationProvider/v4.0_4.0.0.0__31bf3856ad364e35/UIAutomationProvider.dll 
---------------------------------------- 
AcCommandToolTips 
    Assembly Version: 19.1.0.0 
    Win32 Version: 19.1.18.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202014/AcCommandToolTips.DLL 
---------------------------------------- 
AcCommandToolTips.resources 
    Assembly Version: 19.1.0.0 
    Win32 Version: 19.1.18.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202014/en-US/AcCommandToolTips.resources.DLL 
---------------------------------------- 
Connect.Client.AutoCAD 
    Assembly Version: 3.1.2.0 
    Win32 Version: 3.1.2.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202014/Connect.Client.AutoCAD.DLL 
---------------------------------------- 
AcDialogToolTips 
    Assembly Version: 19.1.0.0 
    Win32 Version: 19.1.18.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202014/AcDialogToolTips.DLL 
---------------------------------------- 
AcDialogToolTips.resources 
    Assembly Version: 19.1.0.0 
    Win32 Version: 19.1.18.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202014/en-US/AcDialogToolTips.resources.DLL 
---------------------------------------- 

************** JIT Debugging ************** 
Application does not support Windows Forms just-in-time (JIT) 
debugging. Contact the application author for more 
information. 
+0

我編輯了自己的冠軍。請參閱:「[應該在其標題中包含」標籤「](http://meta.stackexchange.com/questions/19190/)」,其中的共識是「不,他們不應該」。 – 2014-12-04 21:40:58

回答

3

這是因爲AutoCAD中的工作目錄是AutoCAD的文件夾(通常C:\Program Files\Autodesk\<version>\),不是你的DLL插件來自該文件夾。這種行爲對於所有應用程序都是通用的 - 無論加載外部庫,運行目錄都保留在可執行應用程序啓動的位置。

您需要完全或相對於該AutoCAD文件夾引用您的文件。你可以,但是,通過Assembly.Location正是如此

typeof(MyType).Assembly.Location 

使用該得到的完整路徑,你的DLL,你可以使用此代碼所需的文件:

using System.IO; 
... 
var dllPath = typeof(MyType) // Where 'MyType' is a type defined in your assembly 
    .Assembly.Location; 
var folderPath = new FileInfo(dllPath).Directory.FullName; 
var fullPath = Path.Combine(folderPath, "Window Width.PNG"); 

previewBox.Image = System.Drawing.Image.FromFile(fullPath);