Visual Studio stops debugging unity project - c#

Setup: Unity 2017.4.16f1 / 2018.2.18f1
I've got an own written C# library, using .Net. The library works fine in a Winforms application. In general it contacts a server application and fetches some data.
Now we want to visualize the data within Unity. For that I followed this guide: https://docs.unity3d.com/Manual/UsingDLL.html. In short: Drag and drop the library in the asset folder, add a new script and access the library. My first problem was the compatibility. Because, I used Unity 2017.4.16f1 first, I needed to downgrade the library from .Net 4.7.2 to .Net 4.6 and change the project settings to the same .Net framework. After getting rid of all the compiler errors, I ran into my current Problem.
I attached Visual Studio 2017to unity set up my breakpoint and started the app within Unity. The breakpoint is on the first call of a function from my custom library. The breakpoint is reached. But if i say 'Step over' (either via click or F10) the active line doesn't switch and I get back to Unity. It's like i never started debugging. Unity goes on like nothing happened.
After that i tried it with Unity 2018.2.18f1. However, there is the same problem. The library isn't called.
Regarding some compatibility issues, I built the Unity project. No error occurs. Finally I stripped down the external library to a basic level. But again I got this strange behavior. Below is the script for unity and an example class from the custom library. Thank you for every advice.
C#:
[Serializable]
public class PostgreSQLParameters
[XmlElement(ElementName = "PostgreSQL_User", IsNullable = false)]
public string UserName
{
get
{
return this.userName;
}
set
{
if (this.userName == value)
return;
this.userName = value;
this.OnPropertyChanged();
}
}
public PostgreSQLParameters()
{ }
Unity:
void Start () {
string cwd = Directory.GetCurrentDirectory();
string pathVariable = Environment.GetEnvironmentVariable("PATH");
try
{
//this line has the break point, untill here all is ok
//after the Debug steps in, I hit F10 here to get to the next line,
//which should be the bracket befor the catch
PostgreSQLParameters parameter = new PostgreSQLParameters();
} // The cursor should be here after hitting F10, but disappears only
catch (Exception)
{
throw;
}
}

The core problem are the dependencies. I compared the dependencies in my library, with them from the unity project within Visual Studio. It turns out on library wasn't linked in Unity: System.Data.DataSetExtension. There are two solutions:
A) If you don't need them, omit them in your library. Delete the reference in the library and compile again
B) Or if you need them and it's part of '.Net' do the following (not tested):
See https://learn.microsoft.com/en-us/visualstudio/cross-platform/unity-scripting-upgrade?view=vs-2017#adding-assembly-references-when-using-the-net-4x-api-compatibility-level
add a file, called mcs.rsp, in the asset root
Insert the line -r:System.Data.DataSetExtension (take the name of the reference you need)
Restart Unity

Related

How do I fix the error I receive in Post Processing when launching Unity?

I'm pretty new to Unity so forgive me If I didn't give you enough information but whenever I open project in Unity I get a few errors.
First two are: Unity Error Image
#1:
***Library\PackageCach\.com.unity.postprocessing#2.0.3-preview\PostProccessing\Runtime\PostProcessManager.cs(424,66):error CS0117:'EditorSceneManager' does not contain a definition for 'IsGameObjectInScene'\***
#2: ***Library\PackageCach\.com.unity.postprocessing#2.0.3-preview\PostProccessing\Runtime\PostProcessManager.cs(425,66):error CS0117:'EditorSceneManager' does not contain a definition for 'IsGameObjectInMainScene'***
If I go into the code and delete these two lines
? UnityEditor.SceneManagement.EditorSceneManager.IsGameObjectInScene(volume.gameObject, customScene)
: UnityEditor.SceneManagement.EditorSceneManager.IsGameObjectInMainScenes(volume.gameObject);
From this
#if UNITY_2018_3_OR_NEWER && UNITY_EDITOR
// If the current camera have a custom scene then the camera is rendering that scene,
// otherwise the camera is rendering the scenes in the SceneManager.
var customScene = camera.scene;
return customScene.IsValid()
? UnityEditor.SceneManagement.EditorSceneManager.IsGameObjectInScene(volume.gameObject, customScene)
: UnityEditor.SceneManagement.EditorSceneManager.IsGameObjectInMainScenes(volume.gameObject);
#else
return true;
It gives me a Syntax error in Unity :
; expected
When I fix that error it gives me this error:
**Library\PackageCache\com.unity.postprocessing#2.0.3-preview\PostProcessing\Editor\Utils\PostProcessShaderIncludePath.cs(10,10): error CS0619: 'ShaderIncludePathAttribute' is obsolete: '[ShaderIncludePath] attribute is no longer supported. Your shader library must be under the Assets folder or in a package. To include shader headers directly from a package, use #include "Packages/<package name>/<path to your header file>"'**
After I delete this line of code:
[ShaderIncludePath]
From this:
#if UNITY_2018_1_OR_NEWER
[ShaderIncludePath]
#endif
public static string[] GetPaths()
{
var srpMarker = Directory.GetFiles(Application.dataPath, "POSTFXMARKER", SearchOption.AllDirectories).FirstOrDefault();
var paths = new string[srpMarker == null ? 1 : 2];
var index = 0;
if (srpMarker != null)
{
paths[index] = Directory.GetParent(srpMarker).ToString();
index++;
}
paths[index] = Path.GetFullPath("Packages/com.unity.postprocessing");
return paths;
After fixing all that I can use Unity normally. If this has no future effect on exporting my project I'm fine with deleting it every time. But I have zero idea what any of that code does, so If anyone can help me or knows how to solve it please let me know.
Judging by the fact that the post processing package is version 2.0.3 (preview), and the latest stable is 2.3.0 as of January 2020, I'm going to suggest that you're using grossly outdated packages.
Firstly, check to see if you Unity Editor is up-to-date by using your Unity Hub app, to "Add" new Unity versions. I would suggest if you're looking for the widely regarded, most stable version, grabbing 2019.4 LTS. Otherwise, if you're looking for that "new" thing, the 2020.2 beta is fairly stable under most conditions, but has the benefit of including the new tools and features.
Next, open up your Package Manager under the Window menu, and then check to see if all of your packages are up-to-date.
Once your Unity Editor and packages are all up-to-date, you'll more than likely find this error is resolved. I also suggest updating now, as you've said you're new to Unity, and I'm assuming you're not halfway through a major project. It's generally considered unwise to update your Unity Editor to new major versions partway through a project without a compelling reason.

Importing Object working in Unity editor, error when running build project

I am trying to import a .obj file into my unity project at runtime. I used the framework SimpleOBJ to import this file.
When running the project inside of the Unity editor everything works as expected and the object gets imported and displayed.
However after building the project when I try to import the file I get an error and the .obj file does not get imported.
I've tried different methodes of importing, more closely resembeling the examples delevered with the framework, however this only complicated the code but did not fix my issue.
class ObjHandler : MonoBehaviour
{
public GameObject import()
{
filepath = FileBrowser.OpenSingleFile("*");
WWW www = new WWW(filepath);
return ObjImporter.Import(www.text);
}
public void ImportObject()
{
ObjHandler handler = new ObjHandler();
_gameObject = handler.Import();
foreach (Transform child in _gameObject.transform)
{
GameObjects.Add(new GameObjectModel(child.gameObject));
Debug.Log(child.gameObject.name);
}
}
Expected Result:
https://i.imgur.com/0o0iyf6.png
Actual result (Error):
https://i.imgur.com/yMtesoh.png
I found a solution to my issue.
Turns out it was the Unity version that I was using that created the issue.
After digging some more in the error log I found this error:
WARNING: Shader Unsupported: 'Legacy Shaders/Diffuse' - Pass 'Meta'
has no vertex shader
So I tried upgrading Unity a couple of times.
Eventually I used the Beta build:
Unity 2019.2 0a11
This version fixed the unsupported shader error and this fixed my standalone build error.

VS 2015 C# AsyncExtension.cs not found

I haven't been able to find any information on this online. I'm debugging an console application, trying to step through some code. When I go to step over I get a source not found error. It says "AsyncExtension.cs not found" and then gives me some details. It says "You need to find AsyncExtension.cs to view the source for the current call stack frame". I'm working in VS2015. I'm assuming something async is happening behind the scenes, its erroring at some point but can't give me the specific details because it can't find the assembly containing AsyncExtension. But I don't know what this is, where to get it, etc. The code in particular I'm trying to step over is below. But I seem to get this at various points, and even when debugging other projects under the same solution.
Line of code:
var newObject = JsonConvert.DeserializeObject<HIDPMessage>(message.ToString());
HIDPMessage:
public class HIDPMessage
{
public string version { get; set; }
[Newtonsoft.Json.JsonProperty]
public string header { get; set; }
[Newtonsoft.Json.JsonProperty]
private Data Data { get; set; }
}
Not sure what you are trying to do but the code you have provided would not normally have any references to anything called AsyncExtension.cs. However your attempt to deserialize message could cause a JsonReaderException.
I'm guessing that "message" is some object that contains properties in common with HIDPMessage type and that you are trying to extract those into a new object, if so message.ToString(), unless overridden will just return the name of the type.
You need to serialize the object to a json string and use the json string instead of message.ToString();
Thanks for the input guys, you were right my code for deserializing was a little off. It turns out this app was built using VS2017 and some components from the Azure SDK were missing. I tried a manual install of the SDK but it wouldn't work - upgrading to 2017 fixed it, but I'm kinda surprised I had to upgrade just to get it to work.
I appreciate the feedback on the serialization stuff as well. This is a new-ish area for me and I'm still learning.

sharing a static class with a DLL in C# without passing a reference

VS2012 for desktop .net framework 4.5 normal windows forms applications, not WPF
Hello, I tried to search for an answer, but I'm not sure of the correct terminology. I've managed to break my code, and can't understand what I've done wrong. (i didn't think i had changed anything, but ...)
I have a solution which contains 2 projects. The first project is an executable program, and the second is a DLL, which is loaded at run time and used by the first project.
the first project contains a form, and a static class with public static strings in the same namespace. (and some other unconnected classes). specifically:
namespace project1_namespace
{
static class settings
{
public static string some_words = "some words in a string";
}
class dll_callback{
//.. some public methods here
}
dll_callback dllcallback; // instance is initialised in the code (not shown)
Form form;
public partial class frm_splash : Form
{
private void frm_splash_FormClosing(object sender, FormClosingEventArgs e)
{
// this function actually loads the DLL, ensuring its the last step
//... some error checking code removed for brevity
Assembly assembly = Assembly.LoadFrom("c:\dllpath\project2.dll");
Type type_init = assembly.GetType("project2_class");
object init = Activator.CreateInstance(type_init, form, dllcallback);
//... some error checking code removed for brevity
}// end method
}// end form class
}// end namespace
when the form is closing, the method shown above is called which calls the second projects class project2_class constructor.
in project 2, the DLL, there is:
namespace project2_namespace
{
// how did i get this working to reference "settings" class from project 1??
public class project2_class
{
public project2_class(project2_namespace.Form1 form_ref, object callback)
{
settings.some_words = "the words have changed";
//... some more stuff
}
}
}
Now, i was experimenting with some code in an entirely different part of project2, and VS2012 suddenly started refusing to compile stating:
error CS0103: The name 'settings' does not exist in the current context
the standard solution to this appears to be to add a reference to project2, but that would create circular dependencies because project 1 calls 2 as a DLL.
I really honestly don't think i had changed anything relevant to this, but also clearly I have.
looking at it, i cant see how project 2 would have access to a class in project 1 without a reference, but the list of arguments to the project2_class constructor doesn't include one, and I am absolutely positive that it hasn't changed (and I cant change it for backwards compatibility reasons).
would really appreciate help with this, as its been a lot of work to get this working.
as a side note, I've definitely learned my lesson about not using source control. and not making "how this works" comments instead of "what this does" comments.
may dynamic help you? You can not get the setting string at complie time.

Can't load model using ContentTypeReader

I'm writing a game where I want to use ContentTypeReader. While loading my model like this:
terrain = Content.Load<Model>("Text/terrain");
I get following error:
Error loading "Text\terrain". Cannot find ContentTypeReader
AdventureGame.World.HeightMapInfoReader,AdventureGame,Version=1.0.0.0,Culture=neutral.
I've read that this kind of error can be caused by space's in assembly name so i've already removed them all but exception still occurs.
This is my content class:
[ContentTypeWriter]
public class HeightMapInfoWriter : ContentTypeWriter<HeightmapInfo>
{
protected override void Write(ContentWriter output, HeightmapInfo value)
{
output.Write(value.getTerrainScale);
output.Write(value.getHeight.GetLength(0));
output.Write(value.getHeight.GetLength(1));
foreach (float height in value.getHeight)
{
output.Write(height);
}
}
public override string GetRuntimeType(TargetPlatform targetPlatform)
{
return
"AdventureGame.World.Heightmap,AdventureGame,Version=1.0.0.0,Culture=neutral";
}
public override string GetRuntimeReader(TargetPlatform targetPlatform)
{
return
"AdventureGame.World.HeightMapInfoReader,AdventureGame,Version=1.0.0.0,Culture=neutral";
}
}
Does anyone meed that kind of error before?
I have been encountering the same problem for a week, and finally decided to do a quick check on the whole "assembly" part.
I found a fix!
Essentially, when you go into AssemblyInfo.cs, you will see all the properties(ie Title, Description, etc.)
The Title, sadly made by XNA, is NOT what your runtime reader refers to. Its actually getting the initial name of the project, which it uses to track back to your application (exe) file in your project. Try either re-making your project from scratch, making sure to keep your namespace the same as your project and never change it , or give a go at re-naming your exe file, found in the debug/obj folder in your project(i believe). hope I helped!
-Will

Categories

Resources