Clear Filters
Clear Filters

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

4 views (last 30 days)
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 Comment
Doctor G
Doctor G on 24 Oct 2017
Edited: Doctor G on 24 Oct 2017
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?

Sign in to comment.

Accepted Answer

Guillaume
Guillaume on 24 Oct 2017
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.
  2 Comments
KAE
KAE on 18 Apr 2022
Edited: KAE on 18 Apr 2022
@Guillaume, where in your code is asm defined as a constant? Is it the 'Constant' argument to properties? Link doesn't work but I believe it pointed here.

Sign in to comment.

More Answers (0)

Categories

Find more on Parallel Computing Fundamentals in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!