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

2 visualizzazioni (ultimi 30 giorni)
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 Commento
Doctor G
Doctor G il 24 Ott 2017
Modificato: Doctor G il 24 Ott 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?

Accedi per commentare.

Risposta accettata

Guillaume
Guillaume il 24 Ott 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 Commenti
KAE
KAE il 18 Apr 2022
Modificato: KAE il 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.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Parallel Computing Fundamentals in Help Center e File Exchange

Tag

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by