Effacer les filtres
Effacer les filtres

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

7 vues (au cours des 30 derniers jours)
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 commentaire
Doctor G
Doctor G le 24 Oct 2017
Modifié(e) : Doctor G le 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?

Connectez-vous pour commenter.

Réponse acceptée

Guillaume
Guillaume le 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 commentaires
Doctor G
Doctor G le 25 Oct 2017
thank you that was enough to get me going on the solution.
KAE
KAE le 18 Avr 2022
Modifié(e) : KAE le 18 Avr 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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Call Web Services from MATLAB Using HTTP dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by