adding a fresh .NET assembly gives a warning : Warning: Assembly xxx has already been added from location

2 次查看(过去 30 天)
I have a very simple .m class, that has a method called setup that adds a .NET assembly, But I get a warning that the assembly is already added.
Well, there was no Matlab running. I launched a fresh copy. Setup is only called once. The line (#18) that adds the assembly (according to the debugger) is only called once. In fact, I checked to see if the assembly was added before the setup, and it returned false, i.e. that the assembly was not found.
So what gives?
(I know, this is only a warning, and the code still works, but this is frustrating).
classdef liveFeed < handle
%eFeed Recieves live entities values (PDU data) from VR-Link
% DIS PDU's are captured by the C# feeder.dll from the UDP
% bus and translated by VR-Link code to Entity objects
% user should subscribe the the entities they want and will get
% them as messages
properties
asm
feed
result
end
methods
function this = liveFeed
end
function setup(this)
this.asm = NET.addAssembly(fullfile(fileparts(mfilename('fullpath')), '..\bin\MatLink.dll'));
this.feed = linkware.Feeder('me');
addlistener(this.feed,'NextEntity',@this.processEntry);
end
function classView(this)
methodsview(this.feed);
end
function fire(this)
this.feed.fire();
end
function processEntry(this, ~, entry)
this.result = char(entry.name);
disp(this.result);
end
function classList(this)
disp(this.asm.Classes);
end
end
end
>> l = liveFeed
l =
liveFeed with properties:
asm: []
feed: []
result: []
>> isempty(which('linkware.Feeder'))
ans =
logical
1
>> l.setup
18 this.asm = NET.addAssembly(fullfile(fileparts(mfilename('fullpath')), '..\bin\MatLink.dll'));
Warning: Assembly 'D:\CERDEC\LinkWare\bin\MatLink.dll' has already been added from location
'MatLink'.
> In liveFeed/setup (line 18)
>> isempty(which('linkware.Feeder'))
ans =
logical
0
  1 个评论
Doctor G
Doctor G 2017-10-24
编辑:Doctor G 2017-10-24
if true
% code
endIs there some hidden thing in
fullfile(fileparts(mfilename('fullpath'))
that might cause the code to execute twice? since if I just hard code the path, it seems not to give this problem?

请先登录,再进行评论。

采纳的回答

Guillaume
Guillaume 2017-10-24
I'm not really sure why your code is not working properly. However, since asm is supposed to be a singleton, defining it as a constant property would ensure that it is only evaluated once, when the class is loaded:
classdef liveFeed < handle
%eFeed Recieves live entities values (PDU data) from VR-Link
% DIS PDU's are captured by the C# feeder.dll from the UDP
% bus and translated by VR-Link code to Entity objects
% user should subscribe the the entities they want and will get
% them as messages
properties (Constant)
asm = NET.addAssembly(fullfile(fileparts(mfilename('fullpath')), '..\bin\MatLink.dll'));
end
properties
feed
result
end
The rest of your setup function can then go into the class constructor.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Parallel Computing Fundamentals 的更多信息

标签

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by