‘Could not load type “System.IO.Directory” from assembly “System.Runtime, Version = 4.0.0.0”.’

huangapple go评论72阅读模式
英文:

Getting the following 'Could not load type "System.IO.Directory" from assembly "System.Runtime, Version = 4.0.0.0"'

问题

目前,每当我启动 Revit 来测试我的插件,该插件应该将 Revit 文档中的 ViewSchedules 内容导出到 txt 格式时,我怀疑我的项目引用存在问题,但我已链接了 RevitAPI 和 RevitUIAPI。

以下是插件的代码:

using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using System.IO;
using static System.Net.Mime.MediaTypeNames;

namespace RevitExportImportSchedule
{
    [TransactionAttribute(TransactionMode.Manual)]
    public class Class1 : IExternalCommand
    {
        public string Export(Document doc, string export_folder_name, string extension)
        {
            FilteredElementCollector col = new FilteredElementCollector(doc).OfClass(typeof(ViewSchedule));

            ViewScheduleExportOptions opt = new ViewScheduleExportOptions();
            var output = "Exported Files:\n";
            try
            {
                foreach (ViewSchedule vs in col)
                {
                    Directory.CreateDirectory(export_folder_name);

                    vs.Export(export_folder_name, vs.Name + "_Schedule" + extension, opt);
                    output += export_folder_name + vs.Name + "_Schedule" + extension + "\n";
                }
                return output;
            }
            catch(Exception e)
            {
                output += e;
                return output;
            }
        }
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            var export_folder = "C:\\Users\\BEN.DENNISON\\Documents\\revit_open_auto";
            var extension = ".txt";
            UIApplication uiapp = commandData.Application;
            UIDocument uidoc = uiapp.ActiveUIDocument;
            Document doc = uidoc.Document;
            var output = Export(doc, export_folder, extension);
            
            TaskDialog.Show("Export", output);
            return Result.Succeeded;
        }
    }
}

这是我的 .addin 文件:

<RevitAddIns>   
    <AddIn Type="Command">     
        <Name>RevitImportExport</Name>    
        <FullClassName>RevitExportImportSchedule.Class1</FullClassName>  
        <Text>Import/Export</Text>     
        <Description>Exports/Imports all Schedules present in a revit project</Description>     
        <VisibilityMode>AlwaysVisible</VisibilityMode>     
        <Assembly>C:\Users\BEN.DENNISON\source\repos\RevitScheduleImportExport\RevitScheduleImportExport\bin\Debug\net7.0\RevitScheduleImportExport.dll</Assembly>    
        <AddInId>239BD853-36E4-461f-9171-C5ACEDA4E723</AddInId>     
        <VendorId>COMPANY</VendorId>     
        <VendorDescription>COMPANY</VendorDescription>   
    </AddIn> 
</RevitAddIns>

我正在使用 Visual Studio 2022。

我已尝试注释掉导出函数,但未能解决问题,这表明问题可能出现在如何构建项目上。

英文:

Currently, Whenever I launch revit to test my addin that is supposed to export the contents of ViewSchedules in a revit document to txt format. I suspect something is wrong with my project references, however I am linking RevitAPI and RevitUIAPI.

Below is the code for the addin:

using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using System.IO;
using static System.Net.Mime.MediaTypeNames;

namespace RevitExportImportSchedule
{
    [TransactionAttribute(TransactionMode.Manual)]
    public class Class1 : IExternalCommand
    {
        public string Export(Document doc, string export_folder_name, string extension)
        {
            FilteredElementCollector col = new FilteredElementCollector(doc).OfClass(typeof(ViewSchedule));

            ViewScheduleExportOptions opt = new ViewScheduleExportOptions();
            var output = &quot;Exported Files:\n&quot;;
            try
            {
                foreach (ViewSchedule vs in col)
                {
                    Directory.CreateDirectory(export_folder_name);

                    vs.Export(export_folder_name, vs.Name + &quot;_Schedule&quot; + extension, opt);
                    output += export_folder_name + vs.Name + &quot;_Schedule&quot; + extension + &quot;\n&quot;;
                }
                return output;
            }
            catch(Exception e)
            {
                output += e;
                return output;
            }
        }
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            var export_folder = &quot;C:\\Users\\BEN.DENNISON\\Documents\\revit_open_auto&quot;;
            var extension = &quot;.txt&quot;;
            UIApplication uiapp = commandData.Application;
            UIDocument uidoc = uiapp.ActiveUIDocument;
            Document doc = uidoc.Document;
            var output = Export(doc, export_folder, extension);
            
            TaskDialog.Show(&quot;Export&quot;, output);
            return Result.Succeeded;
        }
    }
}`

Here is my .addin:

&lt;RevitAddIns&gt;   

&lt;AddIn Type=&quot;Command&quot;&gt;     

&lt;Name&gt;RevitImportExport&lt;/Name&gt;    

&lt;FullClassName&gt;RevitExportImportSchedule.Class1&lt;/FullClassName&gt;  

&lt;Text&gt;Import/Export&lt;/Text&gt;     

&lt;Description&gt;Exports/Imports all Schedules present in a revit project&lt;/Description&gt;     &lt;VisibilityMode&gt;AlwaysVisible&lt;/VisibilityMode&gt;     

&lt;Assembly&gt; 		C:\Users\BEN.DENNISON\source\repos\RevitScheduleImportExport\RevitScheduleImportExport\bin\Debug\net7.0\RevitScheduleImportExport.dll 	

&lt;/Assembly&gt; 	

&lt;AddInId&gt;239BD853-36E4-461f-9171-C5ACEDA4E723&lt;/AddInId&gt;     

&lt;VendorId&gt;COMPANY&lt;/VendorId&gt;     

&lt;VendorDescription&gt;COMPANY&lt;/VendorDescription&gt;   

&lt;/AddIn&gt; 

&lt;/RevitAddIns&gt; 

I am using visual studio 2022

I have tried commenting out the export function to no avail which indicated to me it is a problem with how I am building it.

答案1

得分: 1

这似乎是你可能违反了Revit API基本系统要求

> Autodesk Revit API 需要 Microsoft .NET Framework 4.8。

英文:

It sounds to me as if you may be violating the Revit API basic system requirements:

> The Autodesk Revit API requires the Microsoft .NET Framework 4.8.

答案2

得分: 0

Jeremy在这里是正确的。您需要编辑.csproj文件并修改您的目标框架。如果您只是在Visual Studio的Application: General中选择它,那是行不通的。如果需要修改您的目标框架,请查看来自Microsoft的此链接。

英文:

Jeremy was correct here. You need to edit the .csproj file and modify your targeted framework. It won't work if you just select it in Application: General in Visual Studio. Check out this link from Microsoft if you need to modify your targeted framework.

huangapple
  • 本文由 发表于 2023年7月13日 23:49:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/76681257.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定