- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我尝试以这种方式启动 OPC UA 服务器:http://documentation.unified-automation.com/uasdkdotnet/2.1.0/html/L3ServerTutGSLess01.html
ApplicationLicenseManager.AddProcessLicenses(Assembly.GetExecutingAssembly(), "License.lic");
MyServerManager server = new MyServerManager();
ApplicationInstance.Default.Start(server, null, server); //Start the server
At
ApplicationInstance.Default.Start(server, null, server)"
following Error Appears: System.NullReferenceException: Object reference not set to an object instance. at UnifiedAutomation.UaServer.ServerSettings..ctor ( ApplicationInstance application ) at UnifiedAutomation.UaServer.ServerManager.OnServerStarting ( ApplicationInstance application ) at UnifiedAutomation.UaBase.ServerBase.Start ( ApplicationInstance application ) at UnifiedAutomation.UaServer.ServerManager.Start ( ApplicationInstance application ) at UnifiedAutomation.UaBase.ApplicationInstance.Start ( ServerBase server , WaitCallback callback , Object userData ) at VeitsServer.TapakoServerStarter.StartAkomiServer ( IDevice testDeviceToLink ) in TapakoServerStarter.cs : line . 39 at Implementationstests.OpcUaServerTest.ServerShouldRun ( ) in OpcUaServerTest.cs : line 44
如果它是从 Main()
内部启动的,则相同的代码可以正常工作。但是,一旦我尝试通过同一项目映射(例如测试项目)中的外部项目调用 OpcUaServerStarter,就会出现 NullReferenceException。
也许项目必须编译为 .dll 或者我必须添加一些引用?或者出于某种原因,MyServerManager
的可见性在 OPC-UA 网站上是内部
。
Exception 之前的 Debug Session 看起来是这样的:
MyServerManager
类(与工作的 MyServerManager
唯一的关键区别可能是 public
封装):
public class MyServerManager : ServerManager
{
private NodeManager _nodeManager;
private ObjectModel _objectModel;
/// <summary>
/// Method is called (from SDK) when NodeManager starts up.
/// </summary>
/// <param name="rootNodeManager"></param>
protected override void OnRootNodeManagerStarted(RootNodeManager rootNodeManager)
{
Console.WriteLine("Creating Node Manager.");
_nodeManager = new NodeManager(this);
_nodeManager.Startup();
_objectModel = new ObjectModel(_nodeManager);
}
/// <summary>
/// Creates an internal model of the given device and automatically creates nodes and callbacks
/// </summary>
/// <param name="device">AKOMI Device that will be shown on the Server</param>
public void LinkObjectToModel(IDevice device)
{
if (_objectModel == null)
{
throw new NullReferenceException("hv: objectModel is not initilized, try starting the server first.");
}
Console.WriteLine("Register Device: " + device.GetType().Name);
_objectModel.RegisterAkomiDevice(device, 0, 4);
}
/// <summary>
/// Creates an internal model of the given entity and automatically creates nodes and callbacks
/// </summary>
public void LinkObjectToModel(object entity, string name, int curLvl, int maxLvl)
{
if (_objectModel == null)
{
throw new NullReferenceException("hv: objectModel is not initilized, try starting the server first.");
}
Console.WriteLine("Register Entity: " + name);
_objectModel.RegisterEntity(entity, name, curLvl, maxLvl);
}
}
谢谢!
最佳答案
最后我找到了解决方案。我必须将以下代码添加到“App.config”文件中。希望能解决您的问题!
<?xml version="1.0"?> <!--The UA Server needs this App.config!-->
<configuration>
<configSections>
<section name="UaApplicationConfiguration" type="UnifiedAutomation.UaBase.ApplicationConfigurationSection,UnifiedAutomation.UaBase"/>
</configSections>
<UaApplicationConfiguration>
<SecuredApplication xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://opcfoundation.org/UA/2011/03/SecuredApplication.xsd" xmlns:ua="http://opcfoundation.org/UA/2008/02/Types.xsd">
<!-- Identify the Application -->
<ApplicationName>My Server</ApplicationName>
<ApplicationUri>urn:localhost:UnifiedAutomation:MyServer</ApplicationUri>
<ApplicationType>Server_0</ApplicationType>
<!-- Specify location of Certificates and Trust Lists -->
<ApplicationCertificate>
<StoreType>Directory</StoreType>
<StorePath>%CommonApplicationData%\unifiedautomation\UaSdkNet\pki\own</StorePath>
<SubjectName>CN=GettingStartedServer/O=UnifiedAutomation/DC=localhost</SubjectName>
<ValidationOptions>0</ValidationOptions>
</ApplicationCertificate>
<TrustedCertificateStore>
<StoreType>Directory</StoreType>
<StorePath>%CommonApplicationData%\unifiedautomation\UaSdkNet\pki\trusted</StorePath>
<ValidationOptions>0</ValidationOptions>
</TrustedCertificateStore>
<IssuerCertificateStore>
<StoreType>Directory</StoreType>
<StorePath>%CommonApplicationData%\unifiedautomation\UaSdkNet\pki\issuers</StorePath>
<ValidationOptions>0</ValidationOptions>
</IssuerCertificateStore>
<RejectedCertificatesStore>
<StoreType>Directory</StoreType>
<StorePath>%CommonApplicationData%\unifiedautomation\UaSdkNet\pki\rejected</StorePath>
<ValidationOptions>0</ValidationOptions>
</RejectedCertificatesStore>
<!-- Specify Endpoints the Server will use -->
<BaseAddresses>
<BaseAddress>opc.tcp://localhost:48030</BaseAddress>
<!--
Uncomment this line to enable the HTTPS based profiles.
This profile works but is not officially supported in this version of the SDK.
This is the HTTP based protocol that will be supported by embedded devices.
Enabling this profile requires that you have a HTTPS certificate issued by a certificate authority
in your root certificate store. You can create your own authority and add it to the root store or
you can use authorities like VeriSign or Thawte.
-->
<!--
<BaseAddress>https://localhost:48031/</BaseAddress>
-->
<!--
Uncomment this line to enable the WS-Secure Conversation based profiles.
This profile works but is not officially supported since it is not practical to support on embedded devices.
You should not enable this protocol unless you have an application that must support XML Web Services.
-->
<!--
<BaseAddress>http://localhost:48032/wssecurity/</BaseAddress>
-->
</BaseAddresses>
<!-- Specify the SecurityProfiles the Server supports -->
<SecurityProfiles>
<SecurityProfile>
<ProfileUri>http://opcfoundation.org/UA/SecurityPolicy#Basic256</ProfileUri>
<Enabled>true</Enabled>
</SecurityProfile>
<SecurityProfile>
<ProfileUri>http://opcfoundation.org/UA/SecurityPolicy#Basic128Rsa15</ProfileUri>
<Enabled>true</Enabled>
</SecurityProfile>
<SecurityProfile>
<ProfileUri>http://opcfoundation.org/UA/SecurityPolicy#None</ProfileUri>
<Enabled>true</Enabled>
</SecurityProfile>
</SecurityProfiles>
<!-- Specify Configuration for Different Components (Can include 'YourCompany' Configuration) -->
<Extensions>
<!-- Specify the Trace settings for the Application -->
<Extension>
<TraceSettings xmlns="http://unifiedautomation.com/schemas/2011/12/Application.xsd" MasterTraceEnabled="false" DefaultTraceLevel="Info">
<TraceFile>%CommonApplicationData%\unifiedautomation\logs\GettingStartedServer.log.txt</TraceFile>
<MaxEntriesPerLog>100000</MaxEntriesPerLog>
<MaxLogFileBackups>3</MaxLogFileBackups>
<FastTrace>false</FastTrace>
<ModuleSettings>
<ModuleTraceSettings ModuleName="UnifiedAutomation.Stack"/>
<ModuleTraceSettings ModuleName="UnifiedAutomation.Server"/>
</ModuleSettings>
</TraceSettings>
</Extension>
<!-- Specify Settings when EXE is run with the /install argument -->
<Extension>
<InstallationSettings xmlns="http://unifiedautomation.com/schemas/2011/12/Application.xsd">
<GenerateCertificateIfNone>true</GenerateCertificateIfNone>
<DeleteCertificateOnUninstall>true</DeleteCertificateOnUninstall>
</InstallationSettings>
</Extension>
<!-- Specify Settings for the ServerManager -->
<Extension>
<ServerSettings xmlns="http://unifiedautomation.com/schemas/2011/12/Application.xsd">
<ProductName>UnifiedAutomation GettingStartedServer</ProductName>
<DiscoveryRegistration>
<Enabled>false</Enabled>
</DiscoveryRegistration>
</ServerSettings>
</Extension>
<Extension>
<SessionSettings xmlns="http://unifiedautomation.com/schemas/2011/12/Application.xsd">
<MaxSessionCount>100</MaxSessionCount>
</SessionSettings>
</Extension>
<!-- Specify Settings for the SubscriptionManager -->
<Extension>
<SubscriptionSettings xmlns="http://unifiedautomation.com/schemas/2011/12/Application.xsd">
<MaxSubscriptionCount>500</MaxSubscriptionCount>
</SubscriptionSettings>
</Extension>
</Extensions>
</SecuredApplication>
</UaApplicationConfiguration>
<system.serviceModel>
<services>
<service name="UnifiedAutomation.UaBase.SessionEndpoint" behaviorConfiguration="SessionEndpoint.Behavior">
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<!--
Must turn on mexHttpsBinding instead of mexHttpBinding if only HTTPS endpoint configured.
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
-->
</service>
</services>
<!-- Servers deployed in production environments should turn the httpGetEnabled and includeExceptionDetailInFaults options off -->
<behaviors>
<serviceBehaviors>
<behavior name="SessionEndpoint.Behavior">
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceMetadata httpGetEnabled="true"/>
<!--
Must turn on httpsGetEnabled instead of httpGetEnabled if only HTTPS endpoint configured.
<serviceMetadata httpsGetEnabled="true" />
-->
</behavior>
</serviceBehaviors>
</behaviors>
<!--
<diagnostics>
<messageLogging logEntireMessage="true" maxMessagesToLog="3000" logMessagesAtServiceLevel="true" logMalformedMessages="true" logMessagesAtTransportLevel="true"/>
</diagnostics>
-->
</system.serviceModel>
<!--
<system.diagnostics>
<sources>
<source name="System.ServiceModel" switchValue="Verbose, ActivityTracing">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="Default"/>
<add name="ServiceModel Listener"/>
</listeners>
</source>
<source name="System.ServiceModel.MessageLogging">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="Default"/>
<add name="ServiceModel Listener"/>
</listeners>
</source>
</sources>
<sharedListeners>
<add initializeData="VendorServer.svclog" type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" name="ServiceModel Listener" traceOutputOptions="LogicalOperationStack, DateTime, Timestamp, ProcessId, ThreadId, Callstack"/>
</sharedListeners>
</system.diagnostics>
-->
</configuration>
关于c# - 从对 ServerManager 类的公共(public)访问启动 Opc Ua 服务器抛出 NullPointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31922402/
这个问题在这里已经有了答案: 关闭 10 年前。 Possible Duplicate: When should [assembly: InternalsVisibleTo()] be used?
问题与微服务有关,当我有多个微服务提供将被订购和计费的功能/服务时。 我正在确定采用哪种方法, a) 每个可计费微服务有一个订单和一个计费服务,有各自的数据库。b) 跨所有微服务的通用订单管理和计费服
我正在尝试使用 gcloud图书馆。 (ns firengine.state (:import [com.google.cloud AuthCredentials] [com.goog
Java 允许定义以下一对类。 class Class1 { ... } public Class2 { public Class2(Class1 c1) { ... } } 如果因为 Class1
我正在尝试查找文件 1 和文件 2 中的共同行。如果公共(public)行存在,我想写入文件 2 中的行,否则打印文件 1 中的非公共(public)行。fin1 和 fin2 是这里的文件句柄。它读
好吧,这是一个满口的标题。不过,这让我明白了。这是我的代码的要点,在 jar 里: public class NetworkShared { public static class Login
我在使用 ltree 时遇到 PHP 问题来自 PostgreSQL .我在 SQL 中这样做: SELECT * FROM tabla t WHERE t.parent_path " for "OP
我知道如何为类/接口(interface)/包的子集生成 Javadoc。但是有没有办法只为公共(public)方法的一个子集生成 Javadoc? 我更喜欢能够将方法(Javadoc 标记或注释)标
这个问题在这里已经有了答案: 关闭 12 年前。 Possible Duplicates: c#: why have empty get set properties instead of usin
在我们的每个项目中,都有一个文件用于存储该项目中使用的各种SQL 语句。类的声明方式和字符串的声明方式有一些变化。 示例类声明: internal sealed class ClassName int
我根据 http://docs.jquery.com/Plugins/Authoring 定义了我的插件 (function( $ ){ var methods = { init : fu
我正在使用 Inno Setup 来构建我的安装程序,我有 C:\Users\Public文件夹硬编码在我的 [Files] 中放置一些文件的部分(Inno Setup 没有此文件夹的常量) 我的目标
我有一个 dataframe1 包含像 'ID', 'A', 'B', 'C', 'D', 'E', 'F', 'G' 这样的列. 现在,我创建了两个数据框, dataframe2 包含 'ID',
我有一个抽象类,不幸的是我无法更改它的定义,它基本上提供了一个抽象方法,有点像。 public abstract void do(Data someData, BaseInterface interf
我刚刚在重构时偶然发现了一段奇怪的代码。它看起来像是分解出两个 readString() 方法的共同部分的候选者,只是它似乎是不可能的(这对我来说是一个令人毛骨悚然的脑筋急转弯): private f
是否有解析为公用文件夹的属性?显然,我不想在目录结构中对“c:\users\public”进行硬编码,但我找不到预定义的 Property解决这个问题。是否有一种可接受的方式来指定要在此处安装和/或在
我试图将值从一个类传递到另一个类。 subPanel1 类读取全局变量,但当我通过调整监听器更新这些变量时,它不会更改值。我试图将 rc、gc 和 bc 变量从 subPanel2 类传递到 subP
我想使用具有自动属性的干净且编码较少的类。所有属性(property)都是公共(public)的。在同一类的方法中我也使用了该属性。因此,我认为这种方法是可混搭的,因为我将公共(public)属性用于
不久前,我在 Android 应用程序中创建了一个 SQLiteHelper 类。我不是 100% 确定原因,但表名和列名是嵌套公共(public)静态抽象类中的公共(public)静态最终字段。我记
这个问题已经有答案了: Cannot make a static reference to the non-static method (8 个回答) 已关闭 3 年前。 我正在为类(class)做一
我是一名优秀的程序员,十分优秀!