I'm converting a (working) .netstandard library project into a multi-targetted project that will target:
<targetframeworks>netstandard2.1;xamarinios10;monoandroid10.0;monoandroid12.0;</targetframeworks>
I'm having issues with the System.ComponentModel.DataAnnotations reference. Sepcifically I get this error (for eveything except the .netstandard target):
The type 'DataType' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.ComponentModel.DataAnnotations, Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
After a bit of searching I tried adding the System.ComponentModel.Annotations (4.7.0) nuget package. This gave the same error.
In the nuget directory for this I noticed that where the .dll would normally live it had a file '.' - I didn't know if that was important (.nuget\packages\system.componentmodel.annotations\4.7.0\ref\MonoAndroid10) - the .netstandard dll was there as expected.
I've also noticed that (a separate) Xamarin.Android project seems to use the System.ComponentModel.DataAnnotations.dll which lives in C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\Xamarin.iOS\v1.0
I'm not sure if the right version of Mono.Android (or ios equivalant) is being targetted or I have to specify a specific assembly version, or whether I'm down the wrong track completely?
Thanks in advance,
Paul.
As the comment above mentions, to workaround this issue, I moved the bit of offending code (that used the System.ComponentModel.DataAnnotations) into a seperate project that targetted .netstandard2.1 and then referenced this project from my multi-targetted project.
Related
A project I am working on depends on a NuGet package. The dll file inside package is compiled in Release mode, therefore using debugger to inspect code (which is my goal) is impossible.
I'd like to replace the .dll file with the one I compiled in Debug mode. If I remove the package via NuGet and then add it via Add Reference, I get error:
Assembly 'AssemblyName' with identity 'AssemblyName, Version=4.2.5.0, Culture=neutral, PublicKeyToken=null' uses 'System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cf7b13ffcb2dde54'
which has a higher version than referenced assembly 'System.Memory' with identity 'System.Memory, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cf7b13ffcb2dde54'
What is the correct way to replace a NuGet package .dll with another .dll file? Where can the version number be changed I am using Rider, but learning how to do it in other IDEs is also useful.
This happens because the nuget is using a specific version of "System.Memory, Version=4.0.1.1", and you have System.Memory, Version=4.0.1.0 referenced in your project. You should update that reference and it should be good. So the problem is with your DLL not the NuGet. Probably when you removed the nuget you downgraded System.Memory, you should update that explicitly to the version that the error says it requires through NuGet.
Pro Tip if you want to mess around with nugets:
It is essentially a ZIP file
Download Nuget
Change extension to .zip
Decompress
Voila, you have some dll-s
You could ask the author of the nuget package to publish source and debug symbols of the package to a public symbolsource server and reference it. After that you would keep using the release version of the dll but be able to debug into it.
I installed the Nuget packages X.PagedList and X.PagedList.Mvc and now when I call the Html Helper 'PagedListPager' I get this error message and the helper method has a red underline under it that says. The application builds with no errors and I can run the page no problem, but this red line in annoying!
The type 'IEnumerable<>' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. 2_Views_Home_Events.cshtml
Question - does system.runtime version 4.0.0 have anything to do with the .net version the project is using? because I also upgraded .Net to 4.62 from 4.5.2 to get X.PagedList.Mvc to work correctly.
I followed the error message and tried adding the namespace to the view like this below but it didn't do anything. I also went to the references and right clicked to add a reference and looked through the list for System.Runtime, but I don't see any. I only see System, System.Runtime.* I don't see System.Runtime
Also I looked under the nuget package manager and see I can download the nuget package System.Runtime v4.3.0! Why isn't this included in the project to begin with? And will v4.3.0 work if it needs v4.0.0?
Win 10 with Visual Studio 2017 RC
OK this seems really stupid. System.Runtime doesn't come installed when you run VS and create a ASP.Net MVC project!! So I installed the nuget package System.Runtime to get it. Solved! Why wasn't it there to begin with? Looking at some quick details it looks like it contains types that are fundamental to programming like char, byte, string, etc, etc
I would like to sign all projects in my C# solution. But when I try to do so, there is the problem, that several third party assemblies don't have a strong name. These assemblies are:
Microsoft.Practices.Composite.dll
Microsoft.Practices.Composite.Presentation.dll
After doing some research I found a way to give third party DLLs a strong name (source):
1) ildasm /all /out=ThirdParty.il ThirdParty.dll
2) ilasm /dll /key=YourKey.snk ThirdParty.il
These operations both complete successful. But when I remove the NuGet packages with the unsigned assemblies from my projects and add the signed ones as references, I get the following compiler error:
The type 'Microsoft.Practices.Composite.Events.EventBase' is defined in an assembly that is not referenced. You must add a reference to assembly 'Microsoft.Practices.Composite, Version=2.0.1.0, Culture=neutral, PublicKeyToken=null'
But of course I already added Microsoft.Practices.Composite.Presentation.dll
To confine the problem, I tried to add the reference to a new project. But since I got the same error there, I can exclude some weird configuration in my main solution.
You can download my test-project here: https://www.dropbox.com/s/g7sqb4vtbnasfjz/ConsoleApplication1.zip?dl=0
I really hope that you can help me in any way.
Today I found out that the Composite Library is part of Prism since version 4. So instead of adding references to the dlls signed by me, I added the NuGet Package for Prism, which is already signed.
Error: http://pbrd.co/1vTqOTb
I am getting an error in my XAML in my WPF project:
"Error 11 Could not load file or assembly 'NLog, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=5120e14c03d0593c' or one of its dependencies.
The system cannot find the file specified. MainWindow.xaml 73 9 TestApp"
I have searched the entire solution and cant find any 'NLog'
I have tried to add the NLog dll to each of my projects in the solution but it makes no difference.
Any idea?
Turned out to be the NLog was .Net 4.0 and the project was .Net 4.5
I changed the project to 4.0 and the other dependent project to 4.0 and its working.
Thanks!
Whenever you reference another library, there's the chance they will need some other library. When you reference WPF, there are a lot of underlying libraries that get pulled up.
First, make sure that the DLLs you've referenced are set to "Copy Local = True" under their Properties. Also make sure they have the same PublicKeyToken as your error - if they're referenced by strong name (and most of .NET is) a slightly different version won't be read as the correct file.
The other thing you should consider is checking whether the DLL exists in your GAC, and manually installing it if it doesn't. This can often be the cause of such frustrating errors due to a misinstalled sdk (I once has the same issue with the Blend libraries)
I've been struggling with this for days now. googling and trying diff things but with no headway.
I'm doing an MVC project but i need to use services from another project(web project). I did build the web project and referenced its dll in the mvc project. I can access members from the referenced project and everything compiles just fine.
However, the trouble is at runtime at the point where my code is calling a class of the refereced project and its throwing this "could not load type" whatever!
This is the line of code that is problematic
CurrentAgency = new AgencySystem().RetrieveByApiCode(agencyCode);
AgencySystem is in the referenced assembly.
but it keeps saying
"Could not load type 'EPaymentInvoicing.BusinessFacade.AgencySystem' from assembly 'EPaymentInvoicing, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. "
Any idea why?
NB: The referenced project was build with vs2008 and the MVC project is in vs2010
Thanks(if u need more info pls i'd be glad)
The problem was with the assembly names.
Thanks to Saibal i was able to see that both projects had the same assembly name and the runtime was probably refering to the referencing assembly and looking for the AgencySystem tyoe there.
Changing the name of one of the assembly fixed my issue.
Check the platform type. It may be that the dll was compiled for x64 and your project is set for x86 or vice versa.
I don't think it's a platform problem as it should throw a BadImageFormatException in that case.
Does intellisense recognize the AgencySystem class? if that's true then probably you have referenced a newer assembly than the one that is copied in the compilation folder, so cleaning up the solution (and maybe deleting bin and obj folders) should fix it.
If intellisense is not recognizing the class then it probably doesn't exist.
I would recommend to add a version code and a strong name to the EPaymentInvoicing assembly specially if you are referencing it as a compiled assembly instead of a project.