Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
697 views
in Technique[技术] by (71.8m points)

asp.net - Adding assembly reference within web.config

I have some general questions about web.config and how it works regarding assembly reference. I've been playing around with the new Razor view engine and had some trouble getting it up and running.

My problem started with a general

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

Now I figured this was just a simple Add Reference to the project and I'd be on my way. But even after I added a reference to the missing assembly, my project kept breaking.

I found the solution, and I had to add an assembly reference within the web.config. Once I did this everything worked fine.

First, I want to understand why it took adding a reference to web.config to fix this problem. Why wasn't a project reference just good enough?

Second, when it comes to adding references in web.config, I would like to understand the syntax. When I see markup like this

<add assembly="System.Web.WebPages" />

it seems very clear to me that I'm adding an assembly named System.Web.WebPages. But the full syntax in my web.config is

<add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

Version seems self explanatory, but what is culture and PublicKeyToken used for? Are they required? What happens if I don't know either of them, can I just put anything in?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Answering your first question:

There's another SO question here with a useful answer:

What is difference between web.config assemblies element and project file Reference element

Essentially it is to do with differences between Web Projects and non-web projects in Visual Studio (as I understand it).

Answering your second question:

This took quite a bit of digging around but here you go:

Culture - most assemblies should be culture neutral (assuming this is set in the application). However if you do have culture sensitive assemblies then this is where you specify the culture of the assembly.

PublicKeyToken - this is the public key from the public/private key pair that was used to sign the assembly. Having this enables .NET to verify that the assembly it is loading is the correct one.

More useful information here:

http://en.wikipedia.org/wiki/.NET_assembly


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...