- Home /
GetAllAssetPaths : System.Security.SecurityException
I'm trying to write a 3DS Max plugin that can read a unity scene. I am new to Unity C# development (and somewhat new to C# development too)
when I attempt to use AssetDatabase.GetAllAssetPaths()
in my VS project, it crashes due to a security exception. I have all added references for the .dlls In C:\Program Files (x86)\Unity\Editor\Data\Managed
to my VS project.
my super simple program to output the results of GetAllAssetPaths() to the console:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEditor;
namespace UnitySceneReader
{
class Program
{
static void Main(string[] args)
{
string[] assets= AssetDatabase.GetAllAssetPaths();
Console.Write(assets);
Console.ReadLine();
}
}
}
crashes with:
An unhandled exception of type 'System.Security.SecurityException' occurred in mscorlib.dll
Additional information: ECall methods must be packaged into a system module.
can anybody clue me in on what I am doing wrong?
Answer by Jeff-Kesselman · May 14, 2014 at 12:36 AM
Um it looks like you are trying to use the Unity script environment OUTSIDE of Unity.
Why on earth would you imagine that this would work?
because I'm an optimistic noob, I figured I could reference unity's .dlls and be able to access its classes in my independant C# program. so these untiy editor classes won't work OUTSIDE of untiy. What exactly does it mean to code INSIDE of unity? How do I do that?
It means that what you're trying to do should be done from a script that lives in a Unity project. What if Unity was closed? what does GetAllAssetPaths
mean in that case? how should it know how to react? What if there was more than one instance of Unity, etc.
You can reference Unity types from an external project yes, but you can't act on its editor/runtime API.
If you're unit-testing, you can mock things so you create fake GameObjects, etc but that's another subject.
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Script editors won't launch (at all) 1 Answer
Material doesn't have a color property '_Color' 4 Answers
VS2013 Attach to Unity does nothing 0 Answers
Any way to get Intellisense in Visual Studio 2010 to work with Unity? 1 Answer