i created an opc ua client in unity using the OPC Foundation net standard packages . recently I installed the Universal RP package in my project and started getting this error "Library\PackageCache\com.unity.render-pipelines.core@14.0.9\Runtime\Utilities\BatchRendererGroupGlobals.cs(234,20): error CS0433: The type ‘HashCode’ exists in both ‘Microsoft.Bcl.HashCode, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51’ and ‘netstandard, Version=2.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51’ " . I tried deleting the Microsoft.Bcl.HashCode.dll which solved the issue but then my client stopped working ( it can’t connect to the server). Accordingly as an alterative i tried creating an alias in all possible ways ( directly changing the aliases from the assembly’s properties window, modifying the .csproj file to include the alias using the AssetPostprocessor.OnGeneratedCSProject() function and created a smcs.rsp file (also tried mcs.rsp and csc.rsp) “-reference:bclhashcode=Assets/Plugins/Microsoft.Bcl.HashCode.dll " ) then adding “extern alias bclhashcode” at the top of the script generating the error but i always end up getting this error “The extern alias ‘bclhashcode’ was not specified in a /reference option” with a warning that i shouldn’t apply changes to an immutable file or i get this warning " The package cache was invalidated and rebuilt because the following immutable asset(s) were unexpectedly altered:
Packages/com.unity.render-pipelines.core/Runtime/Utilities/BatchRendererGroupGlobals.cs” and the line i added gets removed. i would be really grateful if someone could tell me how to solve this issue.
note :- i am not actually using Microsoft.Bcl.Hashcode in my client script but apparently it’s a dependency for one of the opc packages although i fail to understand why since i am using he version of the package for netstandard2.1 which shouldn’t require that dll. I’m mentioning this because i don’t know what script uses the dll hence i can’t add the extern alias line their instead of the immutable script
Is this it?
OPC is the interoperability standard for the secure and reliable exchange of data in the industrial automation space and in other industries. It is platform independent and ensures the seamless flow of information among devices from multiple vendors. The OPC Foundation is responsible for the development and maintenance of this standard.
Before you dig any deeper I would advise creating a new empty project with that editor and URP package versions to be sure this works. Then add the OPC stuff in it to see if the same issue occurs. If it does, check if the API compatibility level is indeed set to .NET Standard 2.1 (note: it can be different for the editor and builds).
Lastly, the OPC probably doesn’t make any guarantees that it is compatible with Unity? If so you will be treading uncharted territory where you’ll have to bite the bullet and try all sorts of options until it either gets resolved or turns out to be unresolvable (within whatever constraints you may have, ie budget, time, willpower).
This is to be expected. Built-in packages are immutable. You could theoretically copy the package contents to Assets and uninstall the package, and then modify it. But consider that you are editing an essential part of Unity.
For Microsoft.Bcl.Hashcode, disable “Auto Reference” in the assembly’s Inspector settings. Assembly definition (.asmdef) assemblies that don’t explicitly reference the assembly in question will no longer reference it when compiling their own code, while keeping references between precompiled assemblies intact. You may want to consider doing this for all related precompiled assemblies you add, and switch to explicitly referencing these as necessary. Note that code outside an assembly definition (means they get compiled to predefined assemblies) won’t be able to use precompiled assemblies that aren’t auto referenced. It’s generally a good idea to move your code to assembly definitions where possible.
With that said, yeah, there shouldn’t be a need for that assembly under .NET Standard 2.1. For instance, this library doesn’t reference the hashcode assembly under that framework. ILSpy shows assemblies referenced by the application, so that could be a diagnostic measure. I would try re-obtaining all the used assemblies for a start and make sure the version for the right target framework is used. There could be some transitive dependencies that use the hashcode functionality and just don’t have a .NET Standard 2.1 variant or mistakenly includes it even under .NET Standard 2.1.
Recent versions of 2022.3 (since 2022.3.28f1) and Unity 6 (Preview) support temporary user changes in content in the package cache until the library gets rebuilt or package changes occur (add/remove/update). Now is a good time to update to the latest 2022.3 release.
The normal way to apply persistent custom changes to a package is to embed it, a simple matter of copying a package to the Packages folder where it then overrides the manifest version without needing to uninstall or anything.
Copying a package to Assets is wrong and comes with side effects like messing up path-based references and just not being recognized as a package / having its dependencies pulled in.