开发者

Problem with assembly references in Visual Studio

I created a new project in visual studio proj2 and I want it to have the same assembly references as proj1, so I opened proj1.csproj and copied:

<ItemGroup>
<Reference Include="mscorlib" />
<Reference Include="system" />
<Reference Include="System.Windows" />
<Reference Include="System.Core" />
<Reference Include="System.Xml" />
<Reference Include="System.Net" />
<Reference Include="System.Windows.Browser" />
</ItemGroup>

and pasted it into proj1.csproj. The pr开发者_JAVA百科oblem is that my System.Windows assembly reference has an exclamation mark beside it, and when I try to click it, it says:

This project cannot be viewed in the object browser because it is unavailable or not yet built. Please ensure that the project is available and built.

And of course in my .cs file, it says that

The type or namespace 'Windows' does not exist in the namespace 'System' (are you missing an assembly reference?)

How do I get my assembly references to work?


Go to project properties and ensure you're targeting at least Framework 3.0.


System.Windows is WPF and it requires at least .NET 3.0 to be targeted by the project.


Given your update comment, here is the list of assemblies in the Client Profile. You will likely need to reference the full .NET 4 Framework to use System.Windows...

Also note that System.Windows.dll does not encapsulate the System.Windows namespace; much of that namespace is spread across the Presentation*.dll assemblies. Double-check that the actual references being used by your first project appear in the second, for starters.

Also please consider posting the code from your .cs file that results in this error; it's possible a type you're using therein is actually held in a different assembly that you aren't referencing.


Yeah, it sounds like there is a problem with the Framework version your project is targeting. Try setting proj2 to have the same target framework as proj1.

You can do this by right-clicking the project in the Solution Explorer in Visual Studio, selecting Properties, and viewing the Target Framework dropdown in the Application tab.

Alternatively, you can open up the .csproj files and ensure that they have matching TargetFrameworkVersion tags. This tag is typically located within a ProperyGroup near the top of the file.


Right click on the project and go to "Add References".

Add the latest version of System.Windows assembly.

Then it should work

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜