简体   繁体   中英

“The type or namespace 'name' is missing” when it is included in references and using directives

I have a very weird problem. I am developing a Sharepoint 2013 Project which consists of a WebPart and a couple of Lists. I am using a DateTimeControl in the WebPart. I moved the WebPart into another project yesterday. After I moved it, I got an error that stated "The type or namespace DateTimeControl cannot be found in the namespace 'Microsoft.Sharepoint.WebControls'...". So I checked my using directives and my references. The supposedly missing namespace is definitely there. I even inspected it to check if DateTimeControl was inside it, which it was. The architecture of both projects is also the same.

Am I missing something here?

ADD: I tried adding a new WebPart with an DateTimeControl on it. I still get the same error. When I add another control from the same namespace, I get no errors. Only with DateTimeControl.

Make sure both projects are compiled against the same .Net Framework. If you WebPart project that is referencing your DateTimeControl is compiled at a lower .Net Framework than your DateTimeControl then you will get this error.

In esseense make sure they are compiled at the same .Net Framework, or referenced libraries are compiled at a lower .Net Framework

Ok I found the problem. This is a more Sharepoint-specific error.

It seems that you cannot use the control in the namespace "Microsoft.Sharepoint.WebControls" if you are working on a sandbox solution. I don't really understand Microsoft's reasons behind this, but it has to do with farm solutions being run under the farm administrator account, sandbox solutions don't do this.

So when I set the project's "Sandboxed Solution" property to false, the error was gone. My colleague could confirm this behavior on his machine too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM