在以下代码中,如果注释掉UIDocument UIDocument = new UIDocument(Document);
这一行代码(倒数第二行),运行后可以正常输出到init finish
,但是这行代码如果存在则只能输出到$"2, {clientId.GetGUID()}"
这一行,然后会报运行时错误:
未经处理的异常: System.AccessViolationException: 尝试读取或写入受保护的内存。这通常指示其他内存已损坏。
为什么会存在这种后面还没运行到的代码可以影响前面代码的报错?
[STAThread]
static void Main(string[] args)
{
// 初始化
Init();
Product revitInstance = Product.GetInstalledProduct();
Console.WriteLine("1");
var clientId = new ClientApplicationId(Guid.NewGuid(), "testing", "ADSK.Username");
Console.WriteLine($"2, {clientId.GetGUID()}");
revitInstance.Init(clientId, "I am authorized by Autodesk to use this UI-less functionality.");
Console.WriteLine("3");
Autodesk.Revit.ApplicationServices.Application Application = revitInstance.Application;
Console.WriteLine("4");
Document Document = Application.OpenDocumentFile(inputPath);
Console.WriteLine("5");
UIDocument UIDocument = new UIDocument(Document);
Console.WriteLine("init finish");
......
}
1
idealhs 2024-06-25 11:12:14 +08:00
你这是 Unity 吧?先说清楚环境,.NET 还是 mono 啥的
|
![]() |
4
BBrother OP @idealhs #3 init 可以注释掉不影响这个现象的发生,单步不了,环境比较特殊,需要在一台没有 vs 的机器上运行。
|
![]() |
5
Eiden 2024-06-25 12:19:52 +08:00
vs 可以远程调试的
|
6
a33291 2024-06-25 12:51:35 +08:00
@BBrother 先确认在开发机是否正常,然后用依赖检查工具检查在目标机器上的 revit dll 的依赖是否满足,特别是运行时环境(应该是 vc++)
|
7
idealhs 2024-06-25 13:11:46 +08:00
@BBrother #4 没法开发机调的话,上 Visual Studio remote debugger
https://learn.microsoft.com/en-us/visualstudio/debugger/remote-debugging?view=vs-2022 |