0

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.

LeonidasFett
  • 3,052
  • 4
  • 46
  • 76
  • Do you mean the "AssemblyInfo.cs" file? If yes, there is no setting that says "specific version". I see AssemblyVersion in there. But I suppose that it's the version of the assembly that's being generated by my project. Other than that, I have tried restarting, cleaning and rebuilding with numerous combinations without success. – LeonidasFett Jan 15 '15 at 10:02
  • Ok sorry for the mix-up. The "Specific Version" property of the reference assembly is set to True. – LeonidasFett Jan 15 '15 at 10:10
  • I've removed my comments since they don't add much value. What you found is important. Since it's set to `true`, we may be quite sure that the `Microsoft.SharePoint.dll` is present (VS would tell you if it were missing) and is (almost*) exactly the same (the specificversion checks that). Sorry.. no more ideas on my side:/ [~almost - not necessarily perfectly the same, but Microsoft would ensure that from out perspective it'd contain the same things] – quetzalcoatl Jan 15 '15 at 10:57

2 Answers2

0

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

JKennedy
  • 18,150
  • 17
  • 114
  • 198
  • Target frameworks are the same. Even assembly versions are both 15.0, which is used by Sharepoint 2013. Very weird problem. – LeonidasFett Jan 15 '15 at 10:27
0

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.

LeonidasFett
  • 3,052
  • 4
  • 46
  • 76