Log in to reply
 

How do I get dotnet2 and dotnet 3 to play nice together.



  • I've had ambiguous name in namespace VS errors before and I've been able to resolve them. But this one seems trickier and I'm sure the experts can easily answer this one.

    I'm, for the first time, writing a script with dotnet 2 and dotnet 3. This is causing 2 kinds of problems. 'Function' is ambiguous in the namespace 'GTA'. This would apply to World and Vector 3 for example, which are native and supported by both, at least based on the VS error message.

    The second type of issue is that dotnet3, which i need, throws a VS 2019 error when I use UI.Subtitle. It doesn't support this?

    So, after that long preface, is there a prefix i can use on the imports (VB.Net) or using (C#) or the functions themselves or any other fix to resolve using both dlls in one script?



  • Just for clarity, I'm trying to qualify the function names so they are no longer ambiguous.



  • Ok. I've done lots of googling research on this and it seems to be easier to fix in C# and I'm using VB.net and some say it is impossible to do in VB.net and that it is bad practice to have 2 assemblies (i.e. donet2 and dotnet3) using the same names.

    One bandaid fix would be to get a replacement for UI.ShowSubtitle which is a show stopper for me. I guess there is a different function in dotnet 3 because I get the compiler error 'ShowSubtitle' is not a member of GTA.UI.

    Edit: Ok, so with dotnet 3 it changed to:
    Imports Screen = GTA.UI.Screen 'using an alias
    Screen.ShowSubtitle()

    or using Screen=GTA.UI.Screen // c#

    This fixes the issue. I'm still confused as to whether dotnet 3 includes all functions of donet 2 as well as new ones. I thought you needed both because of the compiler issues, but now I realize it could just be that some of the function names in dotnet 3 are different than in donet 2. One thing for sure, is you can't use both at the same time, well not without some hacks.



  • @JohnFromGWN said in How do I get dotnet2 and dotnet 3 to play nice together.:

    The second type of issue is that dotnet3, which i need, throws a VS 2019 error when I use UI.Subtitle. It doesn't support this?

    So, after that long preface, is there a prefix i can use on the imports (VB.Net) or using (C#) or the functions themselves or any other fix to resolve using both dlls in one script?

    Yes, there were API changes. Like

    GTA.UI.Screen.ShowSubtitle
    

    As you found out, yourself. Took me several hours to convert my old v2 scripts to v3. Annoying, but once you took the hurdle, you'll be glad you did.

    However, there is no 'dll issue', running v3 and v2 concurrenly. Nor is there any need for "dotnet2 and dotnet 3 to play nice together." You simply compile against the version you need, like

    <Reference Include="ScriptHookVDotNet3">
      <HintPath>C:\SteamLibrary\steamapps\common\Grand Theft Auto V\ScriptHookVDotNet3.dll</HintPath>
    </Reference
    

    For your old, v2 scripts, you would simly keep referring to the v2 dll. Clearly, you want your new scripts compiled against v3 now. But you can keep both in your scripts directory. In fact, doing so is customary, as keeping the older version operational is useful for legacy reasons (until the older one has fully phased out).

    One thing for sure, is you can't use both at the same time, well not without some hacks.

    And this is patently untrue (see above).



  • You should only have one referenced. v3 contains most (if not all) of the functions that v2 had, many have just been renamed or moved.



  • @Jitnaught Fully agree. Will stick to 3 going forward.



  • @meimeiriver Thank you for your clarifications. I've learned quite a bit since joining these forums. Three or 4 months ago, before stumbling here, I didn't even know what a trainer was. There is however something I need to clarify on my end - because I'm confused about it. Having said that, based on your reply and my recent experience it might not be relevant. When I said you can't use both at the same time I didn't mean without having both installed.

    What I really meant to write was: is it possible, even if it's just hypothetical, to have both .dlls/assemblies as references in the same script.

    At the time, it was relevant for me, because I didn't realize that certain functions in 3 had been renamed. So when I saw the compiler freaking out at world, camera, showsubtitles, etc. I wrongly concluded that I needed both. And ofc, I was missing some import (or using) statements such as GTA.UI.

    From doing some googling, I read that you can sometimes prefix a property or object or method so your compiler doesn't freak out. I also knew from my own experience that I could write GTA.World or World in a script, either one was ok.

    So again, as an example, I was wondering if I could resolve the ambiguous error by simply adding a prefix. Like SHVDN_2.whatever and SHVDN_3.whatever and that would resolve the ambiguity.

    Is that possible? And yes, it is irrelevant since it's clear to me now that 3 is a superset of 2 (with renamed functions) so 2 is just there for legacy purposes.



  • @JohnFromGWN This is one of the google finds. This when I was trying to resolve my errors, not realizing i didn't need both .dlls. Not sure if it's exactly the same issue, but along the same lines, at least to me it was, although I was within the same namespace (actually i don't put namespaces unless i use more than 1 tab in VS).

    extern alias (C# Reference)

    02/04/2013
    2 minutes to read
    

    You might have to reference two versions of assemblies that have the same fully-qualified type names. For example, you might have to use two or more versions of an assembly in the same application. By using an external assembly alias, the namespaces from each assembly can be wrapped inside root-level namespaces named by the alias, which enables them to be used in the same file.

    https://docs.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2010/ms173212(v=vs.100)?redirectedfrom=MSDN


Log in to reply
 

Looks like your connection to GTA5-Mods.com Forums was lost, please wait while we try to reconnect.