Visual Studio C# reference-warning - visual-studio

After compiled, my solution has a warning as below snapshot.
Double clicking the warning will popup a question which I have no idea what it is.
If you understand what VS is talking about, please share.

This looks like you've referenced slightly different versions of your dependencies in different projects in your solutions. What this means is that when you try and run your projects you may get unexpected errors if you pass any references with types in the dependencies as types from different versions of the same assembly are considered to be different.
E.g.
Project1 uses dependency SomeAssembly.dll which is Version 1.0
Project2 uses dependency SomeAssembly.dll but at Version 1.1
Project2 has Project1 as a dependency
Code in project 2 tries to pass a reference of SomeType where that type is defined in SomeAssembly.dll from its code to code from project 1. Project 1 throws an error because the type is not recognised as it comes from a different version of the assembly.
Your problem may be more subtle than this since most errors of this type can be caught by the compiler but if you have complex dependencies or use dependency injection the compiler may not necessarily spot things like this.
Visual Studio is offering to effectively do a workaround for you my redirecting the dependencies all to a specific version. IMHO I would avoid taking the fix if you can fix it manually yourself.
You would be much better off going through your solution and checking all your references to ensure they all match version wise. You may need to remove and add back references to get this working properly but doing this now will avoid unexpected problems in the long run.

Related

Marking .NET 5.0 EXE to avoid warings about version dependent APIs

I'm updating projects in a .NET Framework solution containing a DLL and an EXE to target .NET 5.0. Every call from the from the EXE which touches the DLL is marked with the warning:
Warning CA1416 'MyDllClass.MyProperty<int>(ref int, int, string)' is supported on 'Windows' 7.0 and later
The suggested actions from Microsoft basically amount to either adding cruft to every call or just giving up and suppressing the warnings. Logically, I expected to be able to mark my EXE to declare that it was targeting Windows 7.0 or higher, so that it would give an exception if anyone tried to run it elsewhere, but the compiler could assume this was the baseline for all API calls. Two things I tried, neither of which helped:
Attempt 1
<SupportedOSPlatformVersion>7.0</SupportedOSPlatformVersion>
Attempt 2
<TargetFramework>net5.0-windows7.0</TargetFramework>
What is the elegant way to address this situation? The fact that I'm in control of both projects seems like the best-case scenario.
From EXE Project:
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows</TargetFramework>
<UseWPF>true</UseWPF>
From DLL Project:
<TargetFramework>net5.0-windows</TargetFramework>
<UseWPF>true</UseWPF>
Thanks to a comment by Hans Passant, I tried removing this from my EXE project:
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
I also had to remove the AssemblyInfo.cs due to auto-generated fields conflicting with fields defined in there. After that, all good, no warnings. I presume the compiler is generating whatever fields it needs to keep itself happy.
I also guess that this would not be an issue on a green-field project and that I only ended up with that element somewhere in the process of migrating the application.

What does '[some_platform, 0]' mean in Visual Studio?

When I open a generated solution+project file, I get the following warning for each platform I have in the project file:
path/to/project.vcxproj : warning : Platform '[some_platform, 0]' referenced in the project file 'project' cannot be found.
some_platform is a valid platform in the project, and building, browsing etc all work normally. There is no line number showing where the problem is.
My question is, what does '[some_platform, 0]' really mean?
Coming from Linux, I initially thought the quotes signify that I have [some_platform, 0] literally specified somewhere, which I don't. I don't see ,\s*0 used anywhere in the project file either. How do I decipher that message to be able to find out what it's complaining about?
This is a C++ project if that matters.
Edit: The only places , is even used are inside two messages and an SDK reference. So the [some_platform, 0] is definitely something constructed for the sake of warning, but what does the second part (0) mean?
Resolved: Why VS generates an output like that, I don't know, and who knows what the 0 means. However, it turned out that the platform name is something an SDK would register with VS (or something along those lines) and VS expects it case-sensitive. I had changed ORBIS and Durango to orbis and durango, causing the warning. Fixing the case makes the warning go away (the project was loading and building fine regardless).
I think you might have unmatched solution/project platform and build configurations, resulting in the rare case when visual studio defines or creates new ones: https://msdn.microsoft.com/en-us/library/kkz9kefa.aspx ending in the odd platform names '[some_platform, 0]', '[durango, 0]' and '[orbis, 0]' you have.
Now this is entirely my guess (since I could not find any documents to confirm it). But what that 0 actually means, is the reference to the default build configuration that project should use when you target those individual platforms. For instance, you usually have lines similar to this in the solution (.sln) file:{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
In the case above you would use build configuration 0 as the default build configuration when using msbuild solutionname.sln from the console. But since the entire platform was generated for that project, we of-course don't have a default build configuration either, so... lets generate. There is more details and examples of the default build-configuration in this post: Visual Studio solution file - what does the "Build.0" mean?
Now back to what might actually be your real problem. You mentioned SDK references, have you made sure they are pointing to the correct place and any environment variables is properly configured in visual studio? If not, the problem might be related to the warnings mentioned here:
Platform 'Android' referenced in the project file 'san-angeles' cannot be found. The warning message on that question sure looks similar to the warning you have, only you have those oddly generated platform names.
Hope this will help you solve the problem.

General Compilation Problems VS 2010

I'm running VS2010 Version 10.0.30319.1 RMTRel
I've noticed problems compiling VB.NET application. When I "rebuild" the solution it reports the build was successful. When I then click the run icon to begin debugging, then the compiler will report build errors(often related to referenced projects). I've confirmed all the projects are targeting the same framework and after an undeterministic number of times repeating the same steps, it will eventually compile. This seems consistent enough to me with other code bases to believe that it's a problem with VS. Anyone have any thoughts that might help improve my experience?
You should also check your configuration manager - probably some of projects are disabled for building in current build plan.
is this a rather large solution? If so, the order of build may be out of whack and the way to solve that is to set the build order of the projects to make sure all of the dependent projects are built first.
One common reason is circular references. You cannot do this in a pair of projects, but it can be done if you cobble together a long string of projects. The way to catch this is a dependency mapping tool with a visual representation of dependencies. You will see the items that refer back up to the top.

Is this the correct way to eliminate warning C4945 (symbol already imported from another assembly)?

I've got a .net solution (written in C++/CLI) which references some .dll projects as follows:
MainProject->ProjectA->ProbjectB
MainProject->ProjectB
Originally I'd referenced both ProjectA and ProjectB from MainProject which gave me the warnings as mentioned above.
I can remove the warnings by removing the reference to ProjectB from ProjectMain but it makes it less obvious that MainProject relies on ProjectB. Is this the right thing to do to get rid of the warnings?
Speaking in general terms, a system of dependencies can be depicted by a directed graph where each node is a software component and each edge is a dependency. In my opinion, the more simplification that can be done to the graph, the better.
Yeah that's fine.
If you have ReSharper, you can view the dependency graph by right-clicking ProjectMain --> Project Hierarchy.
I just want to describe, but not explain, following relevant behaviour.
project CSCommon in C#
project CS1 in C#, using CSCommon
project CPP1 in C++, using CSCommon
project CPPMain, using CPP1
If each project has its own output path, I recieve C4945.
If all projects have common outputh path, warning disappears.
I had the same problem as you. And I solved it exactly as you described it: remove the reference to 'Project B' (in your specific case).
That is the only way I know how to fix this error, short of disabling it.
No, removing the reference is probably not the correct way to handle it.
See https://stackoverflow.com/a/12423588/321013
Set Use Dependencies in Build=false for your references.
The point is, that you should have all references that the code in the project itself uses as direct references, but the setting Use Dependencies in Build=TRUE interferes with that, as it pulls in the transitive references also, generating conflicts if you also have direct references. (At least on my VS2005)

VS2008 Unit Test Project bugs

I'm using VS 2008 Developer Edition and am finding some bugs with the Test Projects.
I am getting one error that doesn't make sense - I have a class called 'Foo' which I need to test and created the blank test class automatically.
Foo takes 3 paremeters in its constructor - IBar, IBaz, IBang.
When I write a test case, I will Dim foo as New Foo(bar,baz,bang), and I will sometimes get an error that says = 'Type IBang could not be implicitly converted to IBang'. This error does not make any sense.
Even more odd - if I switch to an instance of Foo_Accessor() instead, the error goes away. I've played with the references and then I can eventually fix the above error - but then I get the same error for my Foo_Accessor() class!
I clean, rebuild, and sometimes the error will go away - but then I get the error 'Foo_Accessor' is not defined. Now I go to the Foo class and do 'create accessor' again - again, it still gives the same error. So at this point I'm stuck and my solution won't compile, and the only thing I did was add a new test case through visual studio!
Has anyone seen these issues and could please help?
Also - I have tried everything, including instructions from MS such as - renaming the type, re-referencing the project / in different ways, unloading the projects, etc, etc.. still I wind up with either the 'ifoo cannot convert to ifoo' bug or Foo_Accessor is not defined bug... I'm about to just break down and give the damned property I have to check a ReadOnly accessor... !
It's hard to say for certain but it sounds like you have a problem with your references being setup incorrectly. What's likely happening here is that one of the references between your projects is setup as a DLL reference vs. a project reference. This can confuse the type system into thinking that Bang from the project and Bang from the DLL are actually different types.
I would delete all references between my projects. Then go add all of them back again being careful to select the project from the project tab of the add reference dialog vs. the Browse one. This should fix your problem.
Is this a multi-language project or just a single language project? I've found this type of problem is more likely to occur in a multi-language project but it's certainly happened in a single language one.

Resources