简体   繁体   中英

Visual Studio stops debugging unity project

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 2017 to 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://docs.microsoft.com/en-us/visualstudio/cross-platform/unity-scripting-upgrade?view=vs-2017#adding-assembly-references-when-using-the-net-4x-api-compatibility-level

  1. add a file, called mcs.rsp, in the asset root

  2. Insert the line -r:System.Data.DataSetExtension (take the name of the reference you need)

  3. Restart Unity

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM