我在同一解决方案下有两个Windows窗体应用程序。
A.EXE框架是针对x86的4.5.2。
B.EXE框架是针对x86的3.5。
在单击A.EXE按钮时,我打开了B.EXE。
在B.EXE中有一个函数可以打印到爱普生TMT81。
在B.EXE表单加载中,我初始化打印机对象.
m_Printer = new ThermalPrinter();ThermalPrinter类:
string strLogicalName = "PosPrintTMT81";
try
{
//Create PosExplorer
PosExplorer posExplorer = new PosExplorer();
DeviceInfo deviceInfo = null;
try
{
deviceInfo = posExplorer.GetDevice(DeviceType.PosPrinter, strLogicalName);
m_Printer = (PosPrinter)posExplorer.CreateInstance(deviceInfo);
}
catch (Exception ex)
{
string strErrorMsg = ex.Message.ToString()
+ "\n\nPlease rectify the error and try again.";
LogException(ex);
return strErrorMsg;
}行PosExplorer posExplorer = new PosExplorer();返回一个错误..。
'Microsoft.PointOfService.Management.Explorer‘的类型初始化程序System.TypeInitializationException引发了一个异常。
发布于 2017-04-19 09:39:07
解决此问题的一个常见解决方案是将以下内容添加到.NET中,从而恢复到遗留的app.config代码访问安全策略:
<configuration>
<runtime>
<NetFx40_LegacySecurityPolicy enabled="true"/>
</runtime>
</configuration> 您可以尝试将其添加到两个应用程序的app.config中,以查看它是否解决了这个问题。然而,这只适用于运行在.NET 4及以上的应用程序。
如果更改此设置对您来说不是一个长期解决方案,那么您的B应用程序必须只在.NET 3.5中运行。因此,您需要研究导致它在.NET 4中运行的原因。
也许是因为你从A中打开应用程序B的特殊方式--你可以提供这些代码。
或者你的B app.config里有类似的东西吗?
<startup>
<supportedRuntime version="v4.0"/> 您还可以提供app.config。
https://stackoverflow.com/questions/43481309
复制相似问题