Problem accessing .NET classes

I am having problems trying to use .NET in MATLAB. Trying the example from "Access a Simple .NET Class" fails like so:
>> netDate = System.DateTime.Now;
Undefined variable "System" or class "System.DateTime.Now".
Just trying to query it with NET.isNETSupported seems to be calling a ".m" file, rather than a built-in. A coworker has the same MATLAB version (R2016b) and the same .NET version (4.0), but I get this:
>> which NET.isNETSupported
C:\Program Files\MATLAB\R2016b\toolbox\matlab\winfun\NET\+NET\isNETSupported.m % static method or package function
while my coworker gets this:
>> which NET.isNETSupported
isNETSupported is a built-in method % static method or package function
I fulfill the System Requirements for Using MATLAB Interface to .NET (I'm running Windows 7). That requirements page also mentions the config file for MATLAB, MATLAB.exe.config. Mine is identical to my coworker's.
Any suggestions how I can access a .NET class?

1 Comment

That C:\Program Files\MATLAB\R2016b\toolbox\matlab\winfun\NET\+NET\isNETSupported.m is just the m file associated with built-in functions for documentation. However, it is puzzling that which does not report the built-in method.
It's not something that I've come across. I think you'd be better off contacting mathworks support directly.
netDate = System.DateTime.Now
should work out of the box, regardless of which .Net version you've got installed.

Sign in to comment.

 Accepted Answer

Michael
Michael on 14 Nov 2018
This only got resolved when I reinstalled MATLAB. Before that, I had also uninstalled and re-installed .NET. We did not learn what the root cause was of this problem.

More Answers (1)

The default paths of MATLAB may not be configured properly on your workstation. In order to reset them, please proceed with the following steps:
In MATLAB, type the commands to restore the application path
>> rehash toolboxcache
>> restoredefaultpath
>> matlabrc
>> savepath
Any custom path will be overwritten but you can make a backup as described in the article below:
How will running the restoredefaultpath and savepath commands affect my custom paths and how do I back up my custom paths? http://www.mathworks.com/matlabcentral/answers/166871
"restoredefaultpath" path will reset paths for all toolboxes/addons. This is why if you have installed a third party toolbox which doesn't come from MathWorks, you will have to reinstall that toolbox.

5 Comments

Unfortunately that didn't help:
>> which -all pathdef
C:\Program Files\MATLAB\R2016b\toolbox\local\pathdef.m
>> rehash toolboxcache
>> restoredefaultpath
>> matlabrc
>> savepath
>> System.DateTime.Now
Undefined variable "System" or class "System.DateTime.Now".
>> which NET.isNETSupported
C:\Program Files\MATLAB\R2016b\toolbox\matlab\winfun\net\+NET\isNETSupported.m % static method or package function
>>
What happens when you run NET.isNETSupported?
tf = NET.isNETSupported
Does it return true or false, or does it throw an error?
Can you confirm (looking in Control Panel) that you have Microsoft .NET Framework version 4.0 or later installed on your system?
>> tf = NET.isNETSupported
Error using NET.isNETSupported
Attempt to execute SCRIPT isNETSupported as a function:
C:\Program Files\MATLAB\R2016b\toolbox\matlab\winfun\net\+NET\isNETSupported.m
I can confirm that I have "Microsoft .NET Framework 4.7.2" installed. When I posted this question, I had .NET 4.6.1, but I updated in the course of my experimentation. The behavior remained the same.
Can you check the .NET installation with the .NET Framework Setup Verification Tool from the link below:
If the verification tool finds any issues, there is a .NET Framework Repair Tool also available in the link above.
In the ".NET Framework Setup Verification Utility", I selected ".NET Framework 4.7.2" as the "Product to Verify". Clicked "Verify Now", and the "Current status" is now "Product verification succeeded!".

Sign in to comment.

Products

Release

R2016b

Tags

Asked:

on 8 Nov 2018

Answered:

on 14 Nov 2018

Community Treasure Hunt

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

Start Hunting!