我正在为Bricscad制作一个插件,它基本上是应用程序使用的一个dll。此插件同时使用控制台命令和WPF窗口。当我尝试调试它并设置断点时,有一种奇怪的行为--如果代码被命令调用,它会在断点处停止,并且可以对其进行调试。然而,如果我打开我的一个WPF窗口,有问题的代码被触发(即按下一个按钮),它仍然在断点处中断,但我得到的消息是:“您的应用程序已进入中断状态,但当前没有所选调试引擎支持的代码正在执行(例如,只有本机运行时代码正在执行)。”这发生在单个dll的作用域中。动态链接库是使用4.5.1 .NET框架构建的。
我已经检查了studio中的模块- dll是否加载以及它的符号。我还尝试取消选中“仅我的代码”选项,但没有效果。我检查了线程--在两种情况下,代码都是在主线程中执行的。我看到的唯一不同之处在于,只有在从WPF窗口调用代码时才会出现此消息。
下面是一个使用xaml文件的示例。
<Window x:Class="Plugin.Window"
Title="Window"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
MaxHeight="400"
MinHeight="350"
Width="400"
MinWidth="400" Height="350">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary
Source="pack://application:,,,/Resource;component/AppDictonary.xaml">
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<StackPanel Orientation="Vertical" Margin="5">
<Button x:Name="_startButton" Content="Start" Width="100" Click="ButtonStart_Click" />
</StackPanel></Window>
和WPF调用的函数
private void ButtonStart_Click(object sender, RoutedEventArgs e)
{
Foo();
}
如果Foo中的断点是由Bricscad中的控制台命令触发的,那么调试就可以了。但是如果它是从ButtonStart_Click调用的,消息就会显示出来。
此消息的可能原因是什么?有没有人遇到过这种行为(可能在其他一些dll中)?
发布于 2020-02-13 16:54:19
也许对你来说太晚了:D,但对未来的读者来说还不是。
描述:
您遇到的问题是,在由某些事件调用的方法中,断点上的源不可用(我使用了WindowsForms,但假设WPF使用相同的sh*t )。
但是,只有在将窗体/窗口显示为模式时才会发生这种情况--如果您将其显示为无模式,那么它就可以工作!(Form.Show() -无模式,Form.ShowDialog() -模式)
解决方案
若要在窗体代码中调试BricsCAD,请尝试在bricscad.exe.config文件
中将useLegacyV2RuntimeActivationPolicy=设置为“false
从该链接-> https://forum.bricsys.com/discussion/comment/25822/#Comment_25822
编辑:
重要信息我花了几个小时调试StackOverflowException,然后进程崩溃和关闭,同时从NUnit控制台运行测试(这很糟糕,我必须用WinDbg调试并检查转储文件)。
事实证明,更改此配置会造成所有这些问题。因此,只有当您确实想在Windows窗体内调试代码时,才保留它为"false“,否则切换为"true”。
下面是我用来打开和关闭此配置的代码(在Visual Studio/Tools中,您可以使用“外部工具...”添加新命令(启用/禁用)。使用参数选择新的.exe )
static void Main(string[] args)
{
string bricscadFolder = @"C:\Program Files\Bricsys\";
bool enableFormDebugging = true;
if (args != null && args.Length > 1)
{
bricscadFolder = args[0];
enableFormDebugging = args[1] == "true";
}
var folders = Directory.GetDirectories(bricscadFolder);
foreach(var folder in folders)
{
string file = $"{folder}\\bricscad.exe.config";
if (File.Exists(file))
{
string content = File.ReadAllText(file);
string replacement = $"useLegacyV2RuntimeActivationPolicy=\"{(enableFormDebugging ? "true" : "false")}\"";
string pattern = @"useLegacyV2RuntimeActivationPolicy\s*=\s*""(true|false)""";
Regex regex = new Regex(pattern);
string result = regex.Replace(content, replacement);
try
{
File.WriteAllText(file, result);
}
catch(UnauthorizedAccessException e)
{
Console.Write($"{file} is protected! Give it Write permission for User.");
Console.ReadLine();
}
}
}
}
https://stackoverflow.com/questions/58500279
复制相似问题