用过C#和海康威视VM的来看看这个Bug,困扰很久了

hzx1515886777 2022-06-27 11:43:18

用VisionMaster4.1.0进行二次开发,加载方案时弹出如下错误:

img


从其他专业毕业,种种原因转到了机器视觉方向,刚开始学习VM,有不专业的表述请各位见谅。

代码如下:

public partial class Form1 : Form
{
bool mSolutionIsLoad = false; //true 代表方案加载成功,false 代表方案关闭


 
  1. public Form1()

  2. {

  3. InitializeComponent();

  4. }

  5.  
  6. /****************************************************************************

  7. * @fn 选择方案路径

  8. * @fn Select solution's path

  9. ****************************************************************************/

  10. private void buttonChooseSoluPath_Click(object sender, EventArgs e)

  11. {

  12. OpenFileDialog openFileDialog = new OpenFileDialog();

  13. openFileDialog.Filter = "VM Sol File|*.sol*";

  14. DialogResult openFileRes = openFileDialog.ShowDialog();

  15. if (DialogResult.OK == openFileRes)

  16. {

  17. textBoxSolutionPath.Text = openFileDialog.FileName;

  18. }

  19. }

  20.  
  21. /****************************************************************************

  22. * @fn 加载方案

  23. * @fn Load solution

  24. ****************************************************************************/

  25. private void buttonLoadSolution_Click(object sender, EventArgs e)

  26. {

  27. string strMsg = null;

  28. int nProgress = 0;

  29. progressBarSaveAndLoad.Value = nProgress;

  30. labelProgress.Text = nProgress.ToString();

  31. labelProgress.Refresh();

  32.  
  33. try

  34. {

  35. VmSolution.Import(textBoxSolutionPath.Text, textBoxPassword.Text);

  36. mSolutionIsLoad = true;

  37.  
  38. IMVSCircleFindModuTool circleFindModule = (IMVSCircleFindModuTool)VmSolution.Instance["流程1.圆查找1"];

  39. vmRenderControl1.ModuleSource = circleFindModule;

  40. }

  41. catch (VmException ex)

  42. {

  43. strMsg = "LoadSolution failed. Error Code: " + Convert.ToString(ex.errorCode, 16);

  44. listBoxMsg.Items.Add(strMsg);

  45. listBoxMsg.TopIndex = listBoxMsg.Items.Count - 1;

  46. return;

  47. }

  48.  
  49. strMsg = "LoadSolution success";

  50. listBoxMsg.Items.Add(strMsg);

  51. listBoxMsg.TopIndex = listBoxMsg.Items.Count - 1;

  52.  
  53. nProgress = 100;

  54. labelProgress.Text = nProgress.ToString();

  55. labelProgress.Refresh();

  56. progressBarSaveAndLoad.Value = Convert.ToInt32(nProgress);

  57. }

下面是app.config的代码,百度了很多解决方法都是app.config里的名称有问题,但这个问题我没找出来。


 
  1. <?xml version="1.0" encoding="utf-8"?>

  2. <configuration>

  3. <appSettings>

  4. <!--启动服务形式(0代表默认系统服务, 1代表exe方式启动)-->

  5. <add key="StartServerByExe" value="0"/>

  6. <!--服务绝对路径,用于拉起服务(value为""时默认拉起系统服务,value为服务路径时为以进程方式启动)-->

  7. <add key="ServerPath" value=""/>

  8. <!--<add key="ServerPath" value="E:\Program Files\VisionMaster\VisionMaster4.1.0\Applications\Server\VisionMasterServer.exe"/>-->

  9. <add key="ClientSettingsProvider.ServiceUri" value=""/>

  10. </appSettings>

  11. <startup>

  12. <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>

  13. </startup>

  14. <runtime>

  15. <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

  16. <probing privatePath="myLibs;myLibs\Newtonsoft.Json;3rdLib;3rdLib\System;3rdLib\MsgPack;3rdLib\Log4Net;3rdLib\ICSharpCode;3rdLib\OpenCv;GateWay;Module(sp)\x64;Module(sp)\x64\Collection\ImageSourceModule;Module(sp)\x64\Location\IMVSCircleFindModu"/>

  17. <dependentAssembly>

  18. <assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral"/>

  19. <bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1"/>

  20. </dependentAssembly>

  21. </assemblyBinding>

  22. </runtime>

  23. <system.web>

  24. <membership defaultProvider="ClientAuthenticationMembershipProvider">

  25. <providers>

  26. <add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri=""/>

  27. </providers>

  28. </membership>

  29. <roleManager defaultProvider="ClientRoleProvider" enabled="true">

  30. <providers>

  31. <add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400"/>

  32. </providers>

  33. </roleManager>

  34. </system.web>

  35. </configuration>

  36.  

 

 

img

 

Form窗口可以运行,选择方案路径也可以选择,但到了加载方案时就报错

检查了很多次引用的dll和配置环境,都没找到问题

大手子们帮忙看看,谢谢!

...全文
2943 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
wanghui0380 2022-06-27
  • 打赏
  • 举报
回复

另外在异常的时候,请查看详细,里面有内联详细异常详细,他会告诉你到底是那个静态变量异常了
知道是啥异常了,你就可以具体百度了

wanghui0380 2022-06-27
  • 打赏
  • 举报
回复

没办法帮你
只能告诉你检查方法

请检查你项目里所有 staitc 字段或者属性
问题产生原因,静态字段初始化 错误,因为静态字段初始化时候依赖了一些外部环境,而这个外部环境异常
常见的错误

  1. static string xx=config["xxxxx"] //这就是你百度到的从配置文件获取,而配置文件没有东西
  2. static xxxx xxx=xxxxx库.xxxx方法或属性;//当库不存在该方法或属性时候,或者当库的依赖dll不存在或者依赖库的依赖库不存在
  3. using(db dbcontext=new dbdononext(xxxxx库的.静态字段))

我们可以随便简单写个例子,当然我只是演示这个异常是因为静态变量产生,而不是你这个问题的具体解决(因为我们没办法解决,这个必须你自己去检查所有的静态变量)
/

/我这里故意让一个静态变量产生异常
//我故意让这个静态stream访问一个压根不存在的文件,你就可以模拟出你这个异常了
//当然我是模拟,具体你的代码,你需要自己检查所有依赖静态变量的地方,任何静态变量,任何静态变量初始化异常都可以引发
//所以我们不能帮你排错,错误原因太多,但一定在发生在静态变量上
 public static Stream xx = new FileInfo(@"d:\abbbbb.dd").OpenRead();

hzx1515886777 2022-06-27
  • 举报
回复
@wanghui0380 已经解决了,感谢
qq_27895169 2022-07-23
  • 举报
回复
@hzx1515886777 怎么解决的
梁卓远 2023-07-30
  • 举报
回复
@qq_27895169 怎么解决?

111,130

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧