How can I add my SoundModel class to the namespace?
When I built the project, the error went away.
Related
I have a yii2 project set up on phpstorm 8.0.3. My namespace structure is as follows:
backend\
controllers
models
...
frontend\
controllers
models
..
common\
controllers
models
I used composer on the project and have various dependancies installed in the vendor folder.
Whenever I try to use a class that is not in the same base namespace (frontend, backend or common), I get an undefined class error. The odd thing is the namespace of the class is in autocomplete:
Another oddity is that the undefined class error disappears for some classes if the file with the defined class is opened.
It looks like the PHPStorm cache was somehow corrupted. I ended up invalidating the cache by going to File -> Invalidate Caches/Restart. This deleted my history but fixed the undefined class issue.
You must declare in use section nedded class or namespace. For example, if you need to use BaseController from custom\controllers namespace:
<?php
namespace frontend\components;
// Add this line
use common\controllers\BaseController;
class Controller extends BaseController {
}
I had to reset my PHPstorm to fix the issue of "Class not found".
File > Manage IDE Settings > Restore Default Settings...
Be carreful, it rests everything, but it also offers you to back up your current settings. After that, all has been hard reseted and it now works again.
Can be helpful sometimes.
Settings -> Directories
Remove folders from "Excluded"
I think you have some problems with composer autoload.
Try :
composer update
This was happening to me because of my PHP language settings. I found this out by taking out the namespace in one of my classes. The error changed to "Scalar types are only available in PHP 7".
Go to File -> Settings -> Language & Frameworks -> PHP. Change the PHP language level to language version 7 or greater.
Edit:
After doing that, Insert -> Getters and Setters was intermittently generating functions and comments as mixed instead of string. I don't know why this happened but I recreated all my fields manually and that fixed the issue.
I have been trying to create background tasks in my universal app solution. As separate Windows Runtime Component project is required to contain background tasks, I have add one to my solution. In the tasks I am accessing a class that resides in my shared project and in order to do so I use add as link. Although there seems to be no errors when I try to compile the project I get the following errors.
"winmdexp.exe" exited with code -1073741819.
Metadata file 'C:\...\BackgroundTasks.winmd' could not be found...
I believe it might be caused by the fact that the classes that I add as link doesn't have the same major namespace as background task project.
Does anyone know a solution to this problem.
Thanks in advance.
As stated in Creating Windows Runtime Components in C# and Visual Basic, all public types must have a root namespace that matches the assembly name. I believe by adding a class as a link to my Windows Runtime Component project, I broke the same root namespace restriction and as the project didn't compile successfully metadata file was not created.
In order to solve this problem at first I changed output type of my project to class library and it compiled without a problem. Unfortunately background tasks didn't run when I tried to trigger them from lifecycle events.
So in the end I moved the classes that was shared between my "Shared" and background tasks project into a class library project and this solved my problem.
I have an IntelliSense problem with Nancy and the Razor View Engine.
I try to use the functionality of an (self-made) external library inside my razor view. Therefore I reference the dll and try to put an #using and the namespace on top of the view to get some IntelliSense-Support.
But it doesn't work. The #using can't find the dll or rather the namespace I have to put behind it.
The VS-Error I get is: "The type or namespace name 'type/namespace' could not be found (are you missing a using directive or an assembly reference?)"
It just seems to be an IntelliSense problem because the engine is able to render the view if I use the correct #using on top of the view and ignore the error message or if I have a class inside my project which inherits from IRazorConfiguration and returns the needed namespace.
Notes:
Hosting: Self-Host and/or OWIN
It works if the library is part of the same solution
This happens with with Nancy 0.22.2 as well as 0.23 and the corresponding Razor packages.
Steps to reproduce (or better: things I did):
Create a new Console Application
Install the Nancy Razor View Engine package
Reference an external dll (namespace: External)
Reference a dll which is part of the same solution (namespace: Same)
Create a new Razor View
Try: #using External -> not working
Try: #using Same -> working
I hope someone can help me even if It is not a real problem since razor is able to render the view but it's annoying :(
OK, I finally found a solution. The following answer led me to it:
https://stackoverflow.com/a/19653760/1761291
I tried it and it worked but instead of doing this its ok to only copy the external dll into the bin folder.
I keep getting the error "The type or namespace name 'xVal' could not be found (are you missing a using directive or an assembly reference?" when I include the namespace:
using xVal.ServerSide;
Am I missing something? Please help. Thanks in advance.
The solution is very simple though. Just have to include a dll on the bin folder of the app.
I have run into an issue with my razor templates.
In the the template I am using it has two using references at the top of the file.
#using Framework;
#using Bundler;
Both of these reference internal namespaces in my project that are both included as refs in the project that is compiling the template. However the bundler reference fails with the classic.
Unable to compile template. The type or namespace name 'Bundler' could not be found (are you missing a using directive or an assembly reference?)
This to me is a bit weird because if I parse the template instead it works fine.
So it is really only a performance issue but as it doesn't effect the site from running correctly.
Is there any reason why compiling (Razor.Compile(content, Name);) fails when parsing (Razor.Parse(content, model, this.Name)) Doesn't?
Thanks for the help :)
So I found a solution.
If I call a method in the namespace before the razor.Compile it seems to fix the issue.
I created a method called helloDll anywhere inside of the namespace that is failing.
public static void helloDll(){}
I call this before my compile
Bundler.cvStyleBundle.helloDll();
Razor.Compile(content, Name);
No more error :)
I think it has something to do with just in time dll loading and the fact that the dll is not loaded at the time of compile and because the compile happens in some weird lovely funky way it doesnt load the dll rather it just grabs all existing ones from the project :)