Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use .NET Core 3.1 #96

Merged
merged 6 commits into from May 21, 2020
Merged

Use .NET Core 3.1 #96

merged 6 commits into from May 21, 2020

Conversation

KarbonKitty
Copy link
Contributor

Ports FrEee.Core, FrEee.Tests and FrEee.WinForms to .NET Core 3.1.

In Tests, MSTest was replaced with NUnit, some tests were commented out, and there are 10 more tests failing (there were 12 before, and I'm unclear on whether those failures are legitimate). Review of the tests is necessary before going forward.

Otherwise, there were surprisingly few issues; one major outstanding issue is the fact that ValueInjector in the version used by FrEee (2.3.3) is .NET Framework - based, and new version seems to contain some breaking changes that I was incapable of resolving right away; review of possible upgrade of that version would be a good idea too.

Some TODOs were added in code; most important touches the post-build.bat/post-build.sh duality; in .NET Core the build system should be capable of selecting correct file per platform, and xbuild.sh hack should be unnecessary. In the meantime, post-build step is hardcoded using post-build.bat file.

Copy link
Owner

@ekolis ekolis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. I'm surprised how little needed to be changed, apart from the unit tests. Thanks for performing this migration!

FrEee.Tests/post-build.bat Outdated Show resolved Hide resolved
@@ -4,15 +4,15 @@ for /f "tokens=1,* delims= " %%a in ("%*") do set ALL_BUT_FIRST=%%b

echo Copying assets to %ALL_BUT_FIRST%\bin\%1\net472
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again we are mentioning a nonexistent net472 folder.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And fixed again. :)

FrEee.Tests/post-build.bat Outdated Show resolved Hide resolved
FrEee.WinForms/post-build.bat Show resolved Hide resolved
FrEee.sln Outdated Show resolved Hide resolved
FrEee.sln Outdated Show resolved Hide resolved
@ekolis ekolis self-assigned this Apr 28, 2020
@ekolis ekolis added this to In progress in core via automation Apr 28, 2020
@ekolis ekolis added this to In progress in winforms-gui via automation Apr 28, 2020
@ekolis ekolis added this to the alpha-10 milestone Apr 28, 2020
@ekolis ekolis linked an issue Apr 28, 2020 that may be closed by this pull request
@ekolis
Copy link
Owner

ekolis commented Apr 28, 2020

So it looks like there are still 2 remaining issues:

  • The build on Azure DevOps is failing with "error code 1". Any idea what that might be? You're not having any trouble building locally, are you?
  • You mentioned something about ValueInjecter not being compatible with .NET Core? Or at least the old version of ValueInjecter that I'm using? I did want to upgrade it but the injection that I was using is no longer supported, and I have yet to take the time to figure out how to use the new LoopInjection to replace it.

@KarbonKitty
Copy link
Contributor Author

It turns out that error code 1 appears on first build after manually deleting bin/ and obj/ folders from FrEee.Tests. The normal rebuild wasn't enough - only after removing directories by hand I was able to reproduce it. Luckily, this entire post-build step isn't really necessary - I was able to use new MSBuild capabilities introduced in .NET Core to encode moving those folders in the csproj file itself, so I've dropped the post-build.bat from test project. The WinForms project probably could do without it too, but I can't parse what the current batch file does to the scripts, and it doesn't give me any problems, so I've left it for now. You might want to look into removing it later on.

As for the ValueInjector, there is the warning that I receive when building the solution:
2>F:\Programming\Projects\FrEee\FrEee.Tests\FrEee.Tests.csproj : warning NU1701: Package 'valueinjecter 2.3.3' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETCoreApp,Version=v3.1'. This package may not be fully compatible with your project.
It's only a warning, so it might work anyway - I can't really be sure, as I didn't do any thorough testing, and I'm frankly not sure what could be the problem, if there was one.

@ekolis
Copy link
Owner

ekolis commented Apr 29, 2020

Oh, thanks for fixing the build! :)

So if ValueInjecter failed then lots of things would break, because it's used when serializing and deserializing data, and also in instantiating templates for objects such as ships. (if I'm not mistaken, I haven't touched that code in a while). So if you are able to play a few turns of the game without it crashing, I guess it is compatible!

@ekolis ekolis moved this from In progress to Review in progress in core Apr 29, 2020
@ekolis
Copy link
Owner

ekolis commented May 5, 2020

I tried running the game from your branch and I noticed it is unable to load any existing files such as game setups because mscorlib does not exist in .NET Core. You might have to add some code to SafeType to replace references to mscorlib with whatever .NET Core uses in its place.

@KarbonKitty
Copy link
Contributor Author

I had to replace mscorlib with System.Private.CoreLib everywhere, but now quickstart actually works, so it seems to have gone well.

@ekolis
Copy link
Owner

ekolis commented May 6, 2020

Hmm, now I get this error when I try to run a quickstart game:

System.InvalidOperationException: 'Operations that change non-concurrent collections must have exclusive access. A concurrent update was performed on this collection and corrupted its state. The collection's state is no longer correct.'

at System.ThrowHelper.ThrowInvalidOperationException_ConcurrentOperationsNotSupported()
at System.Collections.Generic.Dictionary2.FindEntry(TKey key) at System.Collections.Generic.Dictionary2.TryGetValue(TKey key, TValue& value)
at FrEee.Utility.SafeDictionary2.get_Item(TKey key) in C:\Users\edkol\source\repos\FrEee\FrEee\Utility\SafeDictionary.cs:line 91 at FrEee.Utility.Extensions.ChecksExtensions.<GetAttributes>d__31.MoveNext() in C:\Users\edkol\source\repos\FrEee\FrEee\Utility\Extensions\ChecksExtensions.cs:line 34
at System.Linq.Enumerable.SelectEnumerableIterator2.MoveNext() at System.Linq.Enumerable.UnionIterator1.MoveNext()
at System.Linq.Enumerable.Contains[TSource](IEnumerable1 source, TSource value, IEqualityComparer1 comparer)
at System.Linq.Enumerable.Contains[TSource](IEnumerable1 source, TSource value) at FrEee.Utility.Extensions.Parser.<>c__DisplayClass9_01.b__0(MemberInfo m) in C:\Users\edkol\source\repos\FrEee\FrEee\Utility\Extensions\Parser.cs:line 138
at System.Linq.Enumerable.WhereEnumerableIterator1.ToArray() at System.Linq.Enumerable.ToArray[TSource](IEnumerable1 source)
at FrEee.Utility.Extensions.Parser.ParseSingleEnum[T](String s) in C:\Users\edkol\source\repos\FrEee\FrEee\Utility\Extensions\Parser.cs:line 138
at FrEee.Utility.Extensions.Parser.<>c__81.<ParseFlagsEnum>b__8_0(String s) in C:\Users\edkol\source\repos\FrEee\FrEee\Utility\Extensions\Parser.cs:line 116 at System.Linq.Enumerable.SelectArrayIterator2.MoveNext()
at FrEee.Utility.Extensions.Parser.ParseFlagsEnum[T](IEnumerable1 ss) in C:\Users\edkol\source\repos\FrEee\FrEee\Utility\Extensions\Parser.cs:line 116 at FrEee.Utility.Extensions.Parser.ParseFlagsEnum[T](String s) in C:\Users\edkol\source\repos\FrEee\FrEee\Utility\Extensions\Parser.cs:line 96 at FrEee.Utility.Extensions.Parser.ParseEnum[T](String s) in C:\Users\edkol\source\repos\FrEee\FrEee\Utility\Extensions\Parser.cs:line 28 at FrEee.Modding.LiteralFormula1.ComputeValue() in C:\Users\edkol\source\repos\FrEee\FrEee\Modding\LiteralFormula.cs:line 126
at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)

@ekolis
Copy link
Owner

ekolis commented May 21, 2020

dotnet/runtime#26868 - this explains the concurrency error we were getting

@ekolis
Copy link
Owner

ekolis commented May 21, 2020

@KarbonKitty you should be able to fix that concurrency error by changing the internal implementation of SafeDictionary to use ConcurrentDictionary instead of a plain old Dictionary.

@KarbonKitty
Copy link
Contributor Author

I've replaced the Dictionary with ConcurrentDictionary (it needed replacing Remove with TryRemove method, but it seemed a trivial change). It doesn't crash on me now, but it also didn't crash on me before, so it'd be great if you could take a try and make sure it works for you now.

As an aside, it seems that ConcurrentDictionary has a set of methods that do the same thing that the SafeDictionary does (AddOrUpdate, GetOrAdd etc.), so it might be prudent to go with .NET Core class in the future.

@ekolis
Copy link
Owner

ekolis commented May 21, 2020

That seems to have worked, thanks!

Copy link
Owner

@ekolis ekolis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks good now; I'm only concerned with the temporary lack of Linux support until we implement Xamarin/Avalonia/Unity/whatever for the UI.

core automation moved this from Review in progress to Reviewer approved May 21, 2020
winforms-gui automation moved this from In progress to Reviewer approved May 21, 2020
@ekolis ekolis merged commit c9225a1 into ekolis:master May 21, 2020
core automation moved this from Reviewer approved to Done May 21, 2020
winforms-gui automation moved this from Reviewer approved to Done May 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
core
  
Done
winforms-gui
  
Done
Development

Successfully merging this pull request may close these issues.

Port game to .NET Core
2 participants